|
4 | 4 | from datetime import datetime, timedelta |
5 | 5 | import variables |
6 | 6 | import io |
7 | | -import re |
8 | 7 | from utils.uwufier import Uwuifier |
9 | 8 | import utils.modlogs as modlogs |
10 | 9 | import matplotlib.pyplot as plt |
|
33 | 32 | }, |
34 | 33 | ] |
35 | 34 |
|
36 | | - |
37 | 35 | def generate_discord_relative_timestamp(seconds): |
38 | 36 | # Calculate the future Unix timestamp |
39 | 37 | future_timestamp = int((datetime.now() + timedelta(seconds=seconds)).timestamp()) |
@@ -280,3 +278,46 @@ async def banall(self, inter: disnake.ApplicationCommandInteraction): |
280 | 278 | colour=disnake.Colour.dark_red() |
281 | 279 | ) |
282 | 280 | await inter.response.send_message(embed=emb,components=[disnake.ui.Button(style=disnake.ButtonStyle.red,label="CONFIRM")]) |
| 281 | + |
| 282 | + async def role_autocomplete(self, inter: disnake.ApplicationCommandInteraction, string: str): |
| 283 | + # Filter the roles to only those whose ID is in the whitelist |
| 284 | + filtered_roles = [ |
| 285 | + role for role in inter.guild.roles |
| 286 | + if role.id in variables.mod_edit_roles and string.lower() in role.name.lower() |
| 287 | + ] |
| 288 | + |
| 289 | + # Return the filtered roles as options for autocomplete |
| 290 | + return [disnake.OptionChoice(name=role.name, value=role.id) for role in filtered_roles] |
| 291 | + |
| 292 | + def role_list(self): |
| 293 | + return [disnake.OptionChoice(name=role.name,value=role.id) for role in self.bot.guild.roles if role.id in variables.mod_edit_roles] |
| 294 | + |
| 295 | + @mod.sub_command("role","grants or removes a (non-vital) role") |
| 296 | + async def role( |
| 297 | + self, |
| 298 | + inter: disnake.ApplicationCommandInteraction, |
| 299 | + user: disnake.Member, |
| 300 | + modification: str = commands.Param( |
| 301 | + default = "add", |
| 302 | + choices = ["add", "remove"] |
| 303 | + ), |
| 304 | + role: disnake.Role = commands.Param() |
| 305 | + ): |
| 306 | + if (not role.id in variables.mod_edit_roles): |
| 307 | + await inter.response.send_message(f"Role {role.name} is not allowed in this command", ephemeral=True) |
| 308 | + return |
| 309 | + |
| 310 | + try: |
| 311 | + if (modification == "add"): |
| 312 | + if (role in user.roles): |
| 313 | + await inter.response.send_message(f"User {user.name} already has the role {role}.", ephemeral=True) |
| 314 | + else: |
| 315 | + await user.add_roles(role) |
| 316 | + else: |
| 317 | + if (role in user.roles): |
| 318 | + await user.remove_roles(role) |
| 319 | + else: |
| 320 | + await inter.response.send_message(f"User {user.name} doesn't have the role {role}.", ephemeral=True) |
| 321 | + except: |
| 322 | + await inter.response.send_message(f"Failed to {modification} role {role.name}, to user {user.name}", ephemeral=True) |
| 323 | + await inter.response.send_message(f"Role {modification + ('ed' if modification == 'add' else 'd')}", ephemeral=True) |
0 commit comments