Browse Source

Change: changed over slowmode to edit discord's own slowmode feature.

tags/v2.0.0
Roxie Gibson 5 years ago
parent
commit
efe0c0d6db
2 changed files with 14 additions and 40 deletions
  1. +1
    -0
      CHANGELOG.md
  2. +13
    -40
      roxbot/cogs/admin.py

+ 1
- 0
CHANGELOG.md View File

@@ -19,6 +19,7 @@
- Added `;me_irl` subreddit command that outputs images from the me_irl network of subreddits.
- Added more subreddits to the `;aww` command.
- Changed the main name of the `;gss` command to `;traa` while adding ;gss as a alias. Also added `;trans_irl` as a alias.
- Slowmode now uses Discord's own slowmode rather than its own system.

#### Minor Changes
- Roxbot will remove all redundant settings (removed roles from self assign, etc.).

+ 13
- 40
roxbot/cogs/admin.py View File

@@ -52,6 +52,7 @@ class Admin:
OK_SLOWMODE_ON = "Slowmode on :snail: ({} seconds)"
OK_SLOWMODE_OFF = "Slowmode off"
OK_SLOWMODE_CHANGED = "Slowmode set to :snail: ({} seconds)"
ERROR_SLOWMODE_SECONDS = "Rate limit has to be between 0-120."

OK_PURGE_CONFIRMATION = "{} message(s) purged from chat."

@@ -90,59 +91,31 @@ class Admin:
"warnings": {},
}
}
self.slow_mode = False
self.slow_mode_channels = {}
self.users = {}

async def on_message(self, message):
# Slow Mode Code
channel = message.channel
author = message.author

if not author == self.bot.user:
if (self.slow_mode and channel.id in self.slow_mode_channels) and not _is_admin_or_mod(message):
if author.id not in self.users[channel.id]:
# If user hasn't sent a message in this channel after slow mode was turned on
self.users[channel.id][author.id] = message.created_at
else:
# Else, check when their last message was and if time is smaller than the timer, delete the message.
timer = datetime.timedelta(seconds=self.slow_mode_channels[channel.id])
if message.created_at - self.users[channel.id][author.id] < timer:
await message.delete()
else:
self.users[message.channel.id][author.id] = message.created_at
else:
pass

@commands.guild_only()
@commands.has_permissions(manage_messages=True)
@commands.bot_has_permissions(manage_messages=True)
@commands.command()
async def slowmode(self, ctx, seconds):
async def slowmode(self, ctx, seconds: int):
"""Puts the current channel in slowmode. Requires the Manage Messages permission.
Users with manage_channel or manage_messages permissions will not be effected.
Usage:
;slowmode [time/"off"]
;slowmode [time]
seconds = number of seconds for the cooldown between messages a user has.
off = turns off slowmode for this channel"""
# TODO: Edit this when api is avalible for discord's new slowmode feature.
if seconds == "off" and self.slow_mode: # Turn Slow Mode off
self.slow_mode = False
self.slow_mode_channels.pop(ctx.channel.id)
self.users.pop(ctx.channel.id)
0 turns off slowmode for this channel"""
if seconds == 0: # Turn Slow Mode off
await ctx.channel.edit(slowmode_delay=seconds, reason="{} requested to turn off slowmode.".format(ctx.author))
return await ctx.send(self.OK_SLOWMODE_OFF)

elif seconds.isdigit() and not self.slow_mode: # Turn Slow Mode On
self.users[ctx.channel.id] = {}
self.slow_mode_channels[ctx.channel.id] = int(seconds)
self.slow_mode = True
elif 0 < seconds <= 120 and ctx.channel.slowmode_delay == 0: # Turn Slow Mode On
await ctx.channel.edit(slowmode_delay=seconds, reason="{} requested slowmode with a timer of {}".format(ctx.author, seconds))
return await ctx.send(self.OK_SLOWMODE_ON.format(seconds))

elif seconds.isdigit and self.slow_mode: # Change value of Slow Mode timer
self.slow_mode_channels[ctx.channel.id] = int(seconds)
elif 0 < seconds <= 120 and ctx.channel.slowmode_delay > 0: # Change value of Slow Mode timer
await ctx.channel.edit(slowmode_delay=seconds, reason="{} requested slowmode timer be changed to {}".format(ctx.author, seconds))
return await ctx.send(self.OK_SLOWMODE_CHANGED.format(seconds))

else:
pass
elif seconds < 0 or seconds > 120:
raise commands.BadArgument(self.ERROR_SLOWMODE_SECONDS)

@commands.guild_only()
@commands.has_permissions(manage_messages=True)

Loading…
Cancel
Save