Skip to content

Commit 7f5f5a5

Browse files
committed
cogs.admin: Add slowmode command
Add the ability to edit a channel's slowmode delay.
1 parent 6d6e3de commit 7f5f5a5

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

obsbot/cogs/public/admin.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def __init__(self, bot):
1818
('.status', 'prints the bot\'s current status'),
1919
('.setgame', 'Set the bot\'s "Playing ..." status'),
2020
('.setsong', 'Set the bot\'s "Listening to ..." status'),
21+
('.slow', 'Set the current channel\'s Slowmode setting (0-21600 seconds)'),
2122
]
2223
}
2324
self.restricted = set()
@@ -102,6 +103,26 @@ def add_help_section(self, section_name, command_list, restricted=False):
102103
if restricted:
103104
self.restricted.add(section_name)
104105

106+
@command()
107+
async def slow(self, ctx: Context, seconds: int = 0):
108+
if not self.bot.is_admin(ctx.author):
109+
return
110+
111+
# Clamp to the min value of 0 seconds (disabled, no delay)
112+
if seconds < 0:
113+
seconds = 0
114+
115+
# Clamp to the max value of 21600 seconds (6 hours)
116+
if seconds > 21600:
117+
seconds = 21600
118+
119+
if seconds == 0:
120+
await ctx.send('Slowmode has been disabled in this channel.')
121+
elif seconds > 0:
122+
await ctx.send(f'Slowmode has been enabled in this channel with a {seconds} second delay.')
123+
124+
await ctx.channel.edit(slowmode_delay=seconds)
125+
105126

106127
def setup(bot):
107128
bot.add_cog(Admin(bot))

obsbot/main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ async def on_command_error(self, context, exception):
9999
return
100100
elif isinstance(exception, commands.errors.MissingRequiredArgument):
101101
return
102+
elif isinstance(exception, commands.errors.BadArgument):
103+
return
102104
raise exception
103105

104106
async def close(self):

0 commit comments

Comments
 (0)