| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- from discord import Guild, TextChannel
- from discord.ext import commands
-
- from config import CONFIG
- from storage import ConfigKey, Storage
- from cogs.basecog import BaseCog
-
- class ConfigCog(BaseCog, name='Configuration'):
- """
- Cog for handling general bot configuration.
- """
- @commands.group(
- brief='Manages general bot configuration'
- )
- @commands.has_permissions(ban_members=True)
- @commands.guild_only()
- async def config(self, context: commands.Context):
- 'General guild configuration command group'
- if context.invoked_subcommand is None:
- await context.send_help()
-
- @config.command(
- brief='Sets the mod warning channel',
- description='Run this command in the channel where bot messages ' +
- 'intended for server moderators should be sent. Other bot ' +
- 'messages may still be posted in the channel a command was ' +
- 'invoked in. If no output channel is set, mod-related messages ' +
- 'will not be posted!',
- )
- async def setwarningchannel(self, context: commands.Context) -> None:
- 'Command handler'
- guild: Guild = context.guild
- channel: TextChannel = context.channel
- Storage.set_config_value(guild, ConfigKey.WARNING_CHANNEL_ID,
- context.channel.id)
- await context.message.reply(
- f'{CONFIG["success_emoji"]} Warning channel updated to {channel.mention}.',
- mention_author=False)
-
- @config.command(
- brief='Shows the mod warning channel',
- description='Shows the configured channel (if any) where mod ' + \
- 'warnings will be posted.',
- )
- async def getwarningchannel(self, context: commands.Context) -> None:
- 'Command handler'
- guild: Guild = context.guild
- channel_id = Storage.get_config_value(guild, ConfigKey.WARNING_CHANNEL_ID)
- if channel_id is None:
- await context.message.reply(
- f'{CONFIG["info_emoji"]} No warning channel is configured.',
- mention_author=False)
- else:
- channel = guild.get_channel(channel_id)
- await context.message.reply(
- f'{CONFIG["info_emoji"]} Warning channel is configured as {channel.mention}.',
- mention_author=False)
-
- @config.command(
- brief='Sets a user/role to mention in warning messages',
- usage='<@user|@role>',
- description='Configures an role or other prefix to include at the ' +
- 'beginning of warning messages. If the intent is to get the ' +
- 'attention of certain users, be sure to specify a properly ' +
- 'formed @ tag, not just the name of the user/role.'
- )
- async def setwarningmention(self,
- context: commands.Context,
- mention: str = None) -> None:
- 'Command handler'
- guild: Guild = context.guild
- Storage.set_config_value(guild, ConfigKey.WARNING_MENTION, mention)
- if mention is None:
- await context.message.reply(
- f'{CONFIG["success_emoji"]} Warning messages will not tag anyone.',
- mention_author=False)
- else:
- await context.message.reply(
- f'{CONFIG["success_emoji"]} Warning messages will now tag {mention}.',
- mention_author=False)
-
- @config.command(
- brief='Shows the user/role to mention in warning messages',
- description='Shows the text, if any, that will be prefixed on any ' +
- 'warning messages.'
- )
- async def getwarningmention(self, context: commands.Context) -> None:
- 'Command handler'
- guild: Guild = context.guild
- mention: str = Storage.get_config_value(guild, ConfigKey.WARNING_MENTION)
- if mention is None:
- await context.message.reply(
- f'{CONFIG["info_emoji"]} No warning mention configured.',
- mention_author=False)
- else:
- await context.message.reply(
- f'{CONFIG["info_emoji"]} Warning messages will tag {mention}',
- mention_author=False)
|