Experimental Discord bot written in Python
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. from discord import Guild, TextChannel
  2. from discord.ext import commands
  3. from config import CONFIG
  4. from storage import ConfigKey, Storage
  5. from cogs.basecog import BaseCog
  6. class ConfigCog(BaseCog, name='Configuration'):
  7. """
  8. Cog for handling general bot configuration.
  9. """
  10. @commands.group(
  11. brief='Manages general bot configuration'
  12. )
  13. @commands.has_permissions(ban_members=True)
  14. @commands.guild_only()
  15. async def config(self, context: commands.Context):
  16. 'General guild configuration command group'
  17. if context.invoked_subcommand is None:
  18. await context.send_help()
  19. @config.command(
  20. brief='Sets the mod warning channel',
  21. description='Run this command in the channel where bot messages ' +
  22. 'intended for server moderators should be sent. Other bot ' +
  23. 'messages may still be posted in the channel a command was ' +
  24. 'invoked in. If no output channel is set, mod-related messages ' +
  25. 'will not be posted!',
  26. )
  27. async def setwarningchannel(self, context: commands.Context) -> None:
  28. 'Command handler'
  29. guild: Guild = context.guild
  30. channel: TextChannel = context.channel
  31. Storage.set_config_value(guild, ConfigKey.WARNING_CHANNEL_ID,
  32. context.channel.id)
  33. await context.message.reply(
  34. f'{CONFIG["success_emoji"]} Warning channel updated to {channel.mention}.',
  35. mention_author=False)
  36. @config.command(
  37. brief='Shows the mod warning channel',
  38. description='Shows the configured channel (if any) where mod ' + \
  39. 'warnings will be posted.',
  40. )
  41. async def getwarningchannel(self, context: commands.Context) -> None:
  42. 'Command handler'
  43. guild: Guild = context.guild
  44. channel_id = Storage.get_config_value(guild, ConfigKey.WARNING_CHANNEL_ID)
  45. if channel_id is None:
  46. await context.message.reply(
  47. f'{CONFIG["info_emoji"]} No warning channel is configured.',
  48. mention_author=False)
  49. else:
  50. channel = guild.get_channel(channel_id)
  51. await context.message.reply(
  52. f'{CONFIG["info_emoji"]} Warning channel is configured as {channel.mention}.',
  53. mention_author=False)
  54. @config.command(
  55. brief='Sets a user/role to mention in warning messages',
  56. usage='<@user|@role>',
  57. description='Configures an role or other prefix to include at the ' +
  58. 'beginning of warning messages. If the intent is to get the ' +
  59. 'attention of certain users, be sure to specify a properly ' +
  60. 'formed @ tag, not just the name of the user/role.'
  61. )
  62. async def setwarningmention(self,
  63. context: commands.Context,
  64. mention: str = None) -> None:
  65. 'Command handler'
  66. guild: Guild = context.guild
  67. Storage.set_config_value(guild, ConfigKey.WARNING_MENTION, mention)
  68. if mention is None:
  69. await context.message.reply(
  70. f'{CONFIG["success_emoji"]} Warning messages will not tag anyone.',
  71. mention_author=False)
  72. else:
  73. await context.message.reply(
  74. f'{CONFIG["success_emoji"]} Warning messages will now tag {mention}.',
  75. mention_author=False)
  76. @config.command(
  77. brief='Shows the user/role to mention in warning messages',
  78. description='Shows the text, if any, that will be prefixed on any ' +
  79. 'warning messages.'
  80. )
  81. async def getwarningmention(self, context: commands.Context) -> None:
  82. 'Command handler'
  83. guild: Guild = context.guild
  84. mention: str = Storage.get_config_value(guild, ConfigKey.WARNING_MENTION)
  85. if mention is None:
  86. await context.message.reply(
  87. f'{CONFIG["info_emoji"]} No warning mention configured.',
  88. mention_author=False)
  89. else:
  90. await context.message.reply(
  91. f'{CONFIG["info_emoji"]} Warning messages will tag {mention}',
  92. mention_author=False)