Skip to content

Commit

Permalink
Revert "[patch] Improve autoslowmode/bugfix"
Browse files Browse the repository at this point in the history
This reverts commit 11cda60.
  • Loading branch information
Exenifix committed Feb 19, 2023
1 parent 11cda60 commit 95d9b75
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
17 changes: 10 additions & 7 deletions ext/autoslowmode.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from datetime import datetime, timedelta

import disnake
from disnake.ext import commands

from utils.bot import Bot
from utils.checks import is_automod_manager
from utils.constants import AUTOSLOWMODE_EDIT_DELAY
from utils.embeds import BaseEmbed, ErrorEmbed, SuccessEmbed
from utils.utils import Queue

Expand All @@ -12,6 +15,7 @@ def __init__(self, bot: Bot):
self.bot = bot
self.cached_autoslowmode_channels: set[int] = set()
self._cache_loaded = False
self._slowmode_cooldowns: dict[int, datetime] = {}

self.asm_data: dict[int, Queue[disnake.Message]] = {}

Expand Down Expand Up @@ -41,19 +45,19 @@ async def autoslowmode_controller(self, message: disnake.Message):
return

queue = self.add_to_data(message)
if len(queue) < 10:
if len(queue) < 10 or (
message.channel.id in self._slowmode_cooldowns and datetime.now() < self._slowmode_cooldowns[message.channel.id]
):
return

try:
new_slowmode = round(30.0 / ((queue.getright().created_at - queue.getleft().created_at).seconds - 2) + 1)
if new_slowmode < 3:
new_slowmode = 0
queue.clear()
if abs(new_slowmode - message.channel.slowmode_delay) > 3:
new_slowmode = int(30 / (queue.getright().created_at - queue.getleft().created_at).seconds)
if abs(new_slowmode - message.channel.slowmode_delay) >= 5:
await message.channel.edit(
slowmode_delay=new_slowmode,
reason="Autoslowmode",
)
self._slowmode_cooldowns[message.channel.id] = datetime.now() + timedelta(seconds=AUTOSLOWMODE_EDIT_DELAY)
await message.channel.send(
embed=BaseEmbed(
message.guild.me,
Expand All @@ -62,7 +66,6 @@ async def autoslowmode_controller(self, message: disnake.Message):
),
delete_after=3,
)
queue.clear()

except disnake.HTTPException:
self.bot.log.warning("Failed to update slowmode in %s", message.channel.id)
Expand Down
1 change: 1 addition & 0 deletions utils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
MAX_SPAM_QUEUE_SIZE = 10
MAX_BLACKLIST_QUEUE_SIZE = 10
MAX_AUTOSLOWMODE_CHANNELS_AMOUNT = 10
AUTOSLOWMODE_EDIT_DELAY = 10
SPAM_VERIFICATION_THRESHOLD = 3
WARNINGS_RESET_INTERVAL = 15
EMOJIS = {
Expand Down

0 comments on commit 95d9b75

Please sign in to comment.