Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add slowmode command #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions obsbot/cogs/public/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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))
2 changes: 2 additions & 0 deletions obsbot/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ async def on_command_error(self, context, exception):
return
elif isinstance(exception, commands.errors.MissingRequiredArgument):
return
elif isinstance(exception, commands.errors.BadArgument):
return
raise exception

async def close(self):
Expand Down