72 lines
3.0 KiB
Python
72 lines
3.0 KiB
Python
import discord
|
|
from discord import app_commands
|
|
from discord.ext import commands
|
|
|
|
import config
|
|
import guildconf
|
|
|
|
|
|
class Settings(commands.Cog):
|
|
def __init__(self, bot):
|
|
self.bot = bot
|
|
|
|
group = app_commands.Group(
|
|
name="config",
|
|
description="Configure the bot",
|
|
guild_ids=[config.GUILD.id],
|
|
guild_only=True,
|
|
default_permissions=discord.Permissions(manage_guild=True),
|
|
)
|
|
|
|
@group.command(name="modlog", description="Set the mod-log channel")
|
|
@app_commands.describe(channel="Channel where moderation actions are logged")
|
|
@app_commands.checks.has_permissions(manage_guild=True)
|
|
async def modlog(self, interaction: discord.Interaction,
|
|
channel: discord.TextChannel):
|
|
perms = channel.permissions_for(interaction.guild.me)
|
|
if not (perms.view_channel and perms.send_messages and perms.embed_links):
|
|
await interaction.response.send_message(
|
|
f"I need View Channel, Send Messages and Embed Links in {channel.mention}.",
|
|
ephemeral=True)
|
|
return
|
|
await self.bot.db.set_setting(guildconf.MOD_LOG, channel.id)
|
|
await interaction.response.send_message(
|
|
f"Mod log set to {channel.mention}.", ephemeral=True)
|
|
|
|
@group.command(name="modrole", description="Set the moderator role")
|
|
@app_commands.checks.has_permissions(manage_guild=True)
|
|
async def modrole(self, interaction: discord.Interaction, role: discord.Role):
|
|
await self._set_role(interaction, guildconf.MOD_ROLE, role, "Moderator")
|
|
|
|
@group.command(name="adminrole", description="Set the admin role")
|
|
@app_commands.checks.has_permissions(manage_guild=True)
|
|
async def adminrole(self, interaction: discord.Interaction, role: discord.Role):
|
|
await self._set_role(interaction, guildconf.ADMIN_ROLE, role, "Admin")
|
|
|
|
@group.command(name="show", description="Show the current configuration")
|
|
@app_commands.checks.has_permissions(manage_guild=True)
|
|
async def show(self, interaction: discord.Interaction):
|
|
def fmt(value, prefix):
|
|
return f"<{prefix}{value}>" if value else "not set"
|
|
|
|
modlog = await guildconf.get_id(self.bot, guildconf.MOD_LOG)
|
|
modrole = await guildconf.get_id(self.bot, guildconf.MOD_ROLE)
|
|
adminrole = await guildconf.get_id(self.bot, guildconf.ADMIN_ROLE)
|
|
await interaction.response.send_message(
|
|
f"Mod log: {fmt(modlog, '#')}\n"
|
|
f"Moderator role: {fmt(modrole, '@&')}\n"
|
|
f"Admin role: {fmt(adminrole, '@&')}",
|
|
ephemeral=True)
|
|
|
|
async def _set_role(self, interaction, key, role, label):
|
|
if role.is_default():
|
|
await interaction.response.send_message(
|
|
"@everyone can't be used here.", ephemeral=True)
|
|
return
|
|
await self.bot.db.set_setting(key, role.id)
|
|
await interaction.response.send_message(
|
|
f"{label} role set to {role.mention}.", ephemeral=True)
|
|
|
|
|
|
async def setup(bot):
|
|
await bot.add_cog(Settings(bot)) |