1
Fork 0
mirror of https://github.com/allthingslinux/tux.git synced 2024-10-02 08:39:09 +00:00

Merge pull request #581 from allthingslinux/gif_limiter

Fixed a critical bug in the GIF ratelimiter cog caused by the double …
This commit is contained in:
electron271 2024-09-28 23:39:59 -05:00 committed by GitHub
commit 6f1524de75
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -58,17 +58,12 @@ class GifLimiter(commands.Cog):
if (
channel in self.channelwide_gif_limits
and channel in self.recent_gifs_by_channel
and len(self.recent_gifs_by_channel[channel]) >= self.channelwide_gif_limits[channel]
):
await self._delete_message(message, "for channel")
return
if (
user in self.recent_gifs_by_user
and channel in self.user_gif_limits
and len(self.recent_gifs_by_user[user]) >= self.user_gif_limits[channel]
):
if channel in self.user_gif_limits and len(self.recent_gifs_by_user[user]) >= self.user_gif_limits[channel]:
await self._delete_message(message, "for user")
return
@ -97,16 +92,15 @@ class GifLimiter(commands.Cog):
current_time: int = int(time())
async with self.gif_lock:
for channel_id, timestamps in self.recent_gifs_by_channel.items():
for channel_id, timestamps in list(self.recent_gifs_by_channel.items()):
self.recent_gifs_by_channel[channel_id] = [
t for t in timestamps if current_time - t < self.recent_gif_age
]
for user_id, timestamps in self.recent_gifs_by_user.items():
self.recent_gifs_by_user[user_id] = [t for t in timestamps if current_time - t < self.recent_gif_age]
# Delete user key if no GIF has recently been sent by them
if len(self.recent_gifs_by_user[user_id]) == 0:
for user_id, timestamps in list(self.recent_gifs_by_user.items()):
filtered_timestamps = [t for t in timestamps if current_time - t < self.recent_gif_age]
if filtered_timestamps:
self.recent_gifs_by_user[user_id] = filtered_timestamps
else:
del self.recent_gifs_by_user[user_id]