From 9ddda1652311d1468e491d9a4614faaa9ec07349 Mon Sep 17 00:00:00 2001 From: Ryan Foster Date: Wed, 8 Sep 2021 10:38:00 -0400 Subject: [PATCH] cogs.admin: Add slowmode command Add the ability to edit a channel's slowmode delay. --- obsbot/cogs/public/admin.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/obsbot/cogs/public/admin.py b/obsbot/cogs/public/admin.py index 5fb7263..580934d 100644 --- a/obsbot/cogs/public/admin.py +++ b/obsbot/cogs/public/admin.py @@ -18,6 +18,7 @@ def __init__(self, bot): ('.status', 'prints the bot\'s current status'), ('.setgame', 'Set the bot\'s "Playing ..." status'), ('.setsong', 'Set the bot\'s "Listening to ..." status'), + ('.slow', 'Set the current channel\'s Slowmode setting (0-21600 seconds)'), ] } self.restricted = set() @@ -102,6 +103,26 @@ def add_help_section(self, section_name, command_list, restricted=False): if restricted: self.restricted.add(section_name) + @command() + async def slow(self, ctx: Context, seconds: int = 0): + if not self.bot.is_admin(ctx.author): + return + + # Clamp to the min value of 0 seconds (disabled, no delay) + if seconds < 0: + seconds = 0 + + # Clamp to the max value of 21600 seconds (6 hours) + if seconds > 21600: + seconds = 21600 + + if seconds == 0: + await ctx.send("Slowmode has been disabled in this channel.") + elif seconds > 0: + await ctx.send(f"Slowmode has been enabled in this channel with a {seconds} second delay.") + + await ctx.channel.edit(slowmode_delay=seconds) + def setup(bot): bot.add_cog(Admin(bot))