Skip to content

Commit 4fdd9a8

Browse files
authored
Merge pull request #23 from HeDeAnTheonlyone/main
add mod sub command "role"
2 parents 77d93b4 + 837e1e5 commit 4fdd9a8

File tree

5 files changed

+51
-4
lines changed

5 files changed

+51
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ member_data.json
99
mute_lengths.json
1010
modlogs.json
1111
data/
12+
member_names.txt
1213

1314
*.vscode/
1415
*.vscode/*

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ comm_helper_B = 12345
5858
# report_ping: the id of the role to ping when a report is created
5959
report_ping = 12345
6060

61+
# roles that moderators can grant and remove
62+
mod_edit_roles = [1234567890, 9876543210]
63+
6164
#! Misc
6265

6366
# guild: the id of the active guild

modules/moderation/commands/mod.py

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from datetime import datetime, timedelta
55
import variables
66
import io
7-
import re
87
from utils.uwufier import Uwuifier
98
import utils.modlogs as modlogs
109
import matplotlib.pyplot as plt
@@ -33,7 +32,6 @@
3332
},
3433
]
3534

36-
3735
def generate_discord_relative_timestamp(seconds):
3836
# Calculate the future Unix timestamp
3937
future_timestamp = int((datetime.now() + timedelta(seconds=seconds)).timestamp())
@@ -280,3 +278,46 @@ async def banall(self, inter: disnake.ApplicationCommandInteraction):
280278
colour=disnake.Colour.dark_red()
281279
)
282280
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)

modules/utilities/commands/members.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ def __init__(self, bot):
99
@commands.slash_command(name="members", description="View member list and count")
1010
async def members(self, inter: disnake.ApplicationCommandInteraction):
1111

12-
with open("Member Names.txt","w+") as file:
12+
with open("member_names.txt","w+") as file:
1313
file.writelines([member.name + "\n" for member in inter.guild.members])
14-
await inter.response.send_message(f"`{inter.guild.member_count}` members",file=disnake.File(file),ephemeral=True)
14+
15+
dc_file = disnake.File("member_names.txt")
16+
await inter.response.send_message(f"`{inter.guild.member_count}` members",file=dc_file,ephemeral=True)

static/icons/Easter.gif

4.52 MB
Loading

0 commit comments

Comments
 (0)