1
Fork 0
mirror of https://github.com/allthingslinux/tux.git synced 2024-10-02 16:43:12 +00:00

Make Pyright a bit happier about my code

This commit is contained in:
rm-rf-omega 2024-09-22 00:33:15 +02:00
parent 68b7f4de7f
commit 19f51c2685
3 changed files with 18 additions and 4 deletions

View file

@ -1,6 +1,14 @@
import asyncio import asyncio
<<<<<<< HEAD
from collections import defaultdict from collections import defaultdict
from time import time from time import time
=======
from typing import DefaultDict
from tux.utils.constants import Constants as CONST
from tux.bot import Tux
>>>>>>> 28393dc (Make Pyright a bit happier about my code)
import discord import discord
from discord.ext import commands, tasks from discord.ext import commands, tasks
@ -52,7 +60,7 @@ class GifLimiter(commands.Cog):
# Deletes the message passed as an argument, and creates a self-deleting message explaining the reason # Deletes the message passed as an argument, and creates a self-deleting message explaining the reason
async def delete_message(self, message: discord.Message, epilogue: str) -> None: async def delete_message(self, message: discord.Message, epilogue: str) -> None:
channel: discord.TextChannel = message.channel channel: discord.MessageableChannel = message.channel
await message.delete() await message.delete()
sent_message = await channel.send("-# GIF ratelimit exceeded " + epilogue) sent_message = await channel.send("-# GIF ratelimit exceeded " + epilogue)
await asyncio.sleep(3) await asyncio.sleep(3)
@ -89,14 +97,14 @@ class GifLimiter(commands.Cog):
return return
# If it doesn't, add it to recent GIFs # If it doesn't, add it to recent GIFs
current_time: float = time() current_time: int = int(time())
self.recent_gifs_by_channel[channel].append(current_time) self.recent_gifs_by_channel[channel].append(current_time)
self.recent_gifs_by_user[user].append(current_time) self.recent_gifs_by_user[user].append(current_time)
# Function regularly cleans GIF lists and only keeps the most recent ones # Function regularly cleans GIF lists and only keeps the most recent ones
@tasks.loop(seconds=20) @tasks.loop(seconds=20)
async def old_gif_remover(self) -> None: async def old_gif_remover(self) -> None:
current_time: float = time() current_time: int = int(time())
for channel_id, timestamps in self.recent_gifs_by_channel.items(): for channel_id, timestamps in 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] self.recent_gifs_by_channel[channel_id] = [t for t in timestamps if current_time - t < self.recent_gif_age]

View file

@ -6,7 +6,6 @@ from tux.database.controllers import DatabaseController
from tux.ui.embeds import EmbedCreator, EmbedType from tux.ui.embeds import EmbedCreator, EmbedType
from tux.utils.functions import is_harmful, strip_formatting from tux.utils.functions import is_harmful, strip_formatting
class EventHandler(commands.Cog): class EventHandler(commands.Cog):
def __init__(self, bot: Tux) -> None: def __init__(self, bot: Tux) -> None:
self.bot = bot self.bot = bot

View file

@ -77,6 +77,13 @@ class Constants:
# Icon constants # Icon constants
EMBED_ICONS: Final[dict[str, str]] = config["EMBED_ICONS"] EMBED_ICONS: Final[dict[str, str]] = config["EMBED_ICONS"]
# GIF ratelimit constants
RECENT_GIF_AGE: Final[int] = config["RECENT_GIF_AGE"]
GIF_LIMIT_EXCLUDE: Final[list[int]] = config["GIF_LIMIT_EXCLUDE"]
# Ideally would be int, int but YAML doesn't support integer keys
GIF_LIMITS: Final[dict[str, int]] = config["GIF_LIMITS_USER"]
GIF_LIMITS_CHANNEL: Final[dict[str, int]] = config["GIF_LIMITS_CHANNEL"]
# Embed limit constants # Embed limit constants
EMBED_MAX_NAME_LENGTH = 256 EMBED_MAX_NAME_LENGTH = 256
EMBED_MAX_DESC_LENGTH = 4096 EMBED_MAX_DESC_LENGTH = 4096