| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- """
- Cog handling general configuration for a guild.
- """
- from typing import Union, Optional
-
- from discord import Guild, Permissions, TextChannel, Interaction, Role, User
- from discord.app_commands import Group
- from discord.ext.commands import Bot
-
- from config import CONFIG
- from rocketbot.storage import ConfigKey, Storage
- from rocketbot.cogs.basecog import BaseCog
-
- class ConfigCog(BaseCog, name='Configuration'):
- """
- Cog for handling general bot configuration.
- """
-
- def __init__(self, bot: Bot) -> None:
- super().__init__(
- bot,
- config_prefix='config',
- name='configuration',
- short_description='Manages general bot configuration.',
- )
-
- config = Group(
- name='config',
- description='Manages general bot configuration',
- guild_only=True,
- default_permissions=Permissions(Permissions.manage_messages.flag)
- )
-
- @config.command(
- description='Sets the mod warning channel',
- extras={
- 'long_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, interaction: Interaction) -> None:
- """Command handler"""
- guild: Guild = interaction.guild
- channel: TextChannel = interaction.channel
- Storage.set_config_value(guild, ConfigKey.WARNING_CHANNEL_ID,
- interaction.channel.id)
- await interaction.response.send_message(
- f'{CONFIG["success_emoji"]} Warning channel updated to {channel.mention}.',
- ephemeral=True,
- )
-
- @config.command(
- description='Shows the mod warning channel',
- extras={
- 'long_description': 'Shows the configured channel (if any) where mod ' + \
- 'warnings will be posted.',
- },
- )
- async def getwarningchannel(self, interaction: Interaction) -> None:
- """Command handler"""
- guild: Guild = interaction.guild
- channel_id = Storage.get_config_value(guild, ConfigKey.WARNING_CHANNEL_ID)
- if channel_id is None:
- await interaction.response.send_message(
- f'{CONFIG["info_emoji"]} No warning channel is configured.',
- ephemeral=True,
- )
- else:
- channel = guild.get_channel(channel_id)
- await interaction.response.send_message(
- f'{CONFIG["info_emoji"]} Warning channel is configured as {channel.mention}.',
- ephemeral=True,
- )
-
- @config.command(
- description='Sets a user/role to mention in warning messages',
- extras={
- 'usage': '<@user|@role>',
- 'long_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,
- interaction: Interaction,
- mention: Optional[Union[User, Role]] = None) -> None:
- """Command handler"""
- guild: Guild = interaction.guild
- Storage.set_config_value(guild, ConfigKey.WARNING_MENTION, mention.mention if mention else None)
- if mention is None:
- await interaction.response.send_message(
- f'{CONFIG["success_emoji"]} Warning messages will not tag anyone.',
- ephemeral=True,
- )
- else:
- await interaction.response.send_message(
- f'{CONFIG["success_emoji"]} Warning messages will now tag {mention}.',
- ephemeral=True,
- )
-
- @config.command(
- description='Shows the user/role to mention in warning messages',
- extras={
- 'long_description': 'Shows the text, if any, that will be prefixed on any ' +
- 'warning messages.',
- },
- )
- async def getwarningmention(self, interaction: Interaction) -> None:
- """Command handler"""
- guild: Guild = interaction.guild
- mention: str = Storage.get_config_value(guild, ConfigKey.WARNING_MENTION)
- if mention is None:
- await interaction.response.send_message(
- f'{CONFIG["info_emoji"]} No warning mention configured.',
- ephemeral=True,
- )
- else:
- await interaction.response.send_message(
- f'{CONFIG["info_emoji"]} Warning messages will tag {mention}',
- ephemeral=True,
- )
|