Experimental Discord bot written in Python
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

configcog.py 3.5KB

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