Experimental Discord bot written in Python
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

configcog.py 3.6KB

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