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.7KB

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