start on moderation stuff
This commit is contained in:
1 parent
b538da6033
commit
53e0daac1e
6 files changed
+271
-15
No files matched your search
@@ -0,0 +1,57 @@
|
||||
import discord
|
||||
from discord import app_commands
|
||||
|
||||
MOD_LOG = "mod_log_channel"
|
||||
MOD_ROLE = "mod_role"
|
||||
ADMIN_ROLE = "admin_role"
|
||||
|
||||
|
||||
async def get_id(bot, key):
|
||||
value = await bot.db.get_setting(key)
|
||||
return int(value) if value else None
|
||||
|
||||
|
||||
async def mod_log_channel(bot, guild):
|
||||
channel_id = await get_id(bot, MOD_LOG)
|
||||
return guild.get_channel(channel_id) if channel_id else None
|
||||
|
||||
|
||||
async def send_mod_log(bot, guild, **kwargs):
|
||||
"""Send to the mod-log channel. Returns the message, or None if unavailable."""
|
||||
channel = await mod_log_channel(bot, guild)
|
||||
if channel is None:
|
||||
return None
|
||||
try:
|
||||
return await channel.send(**kwargs)
|
||||
except discord.HTTPException:
|
||||
return None
|
||||
|
||||
|
||||
async def is_admin(bot, member):
|
||||
if member.guild_permissions.administrator:
|
||||
return True
|
||||
admin_role = await get_id(bot, ADMIN_ROLE)
|
||||
return admin_role is not None and any(r.id == admin_role for r in member.roles)
|
||||
|
||||
|
||||
async def is_mod(bot, member):
|
||||
if await is_admin(bot, member):
|
||||
return True
|
||||
mod_role = await get_id(bot, MOD_ROLE)
|
||||
return mod_role is not None and any(r.id == mod_role for r in member.roles)
|
||||
|
||||
|
||||
def mod_only():
|
||||
async def predicate(interaction):
|
||||
if await is_mod(interaction.client, interaction.user):
|
||||
return True
|
||||
raise app_commands.CheckFailure("You need to be a moderator to use this.")
|
||||
return app_commands.check(predicate)
|
||||
|
||||
|
||||
def admin_only():
|
||||
async def predicate(interaction):
|
||||
if await is_admin(interaction.client, interaction.user):
|
||||
return True
|
||||
raise app_commands.CheckFailure("You need to be an admin to use this.")
|
||||
return app_commands.check(predicate)
|
||||
Reference in new issue
Block a user