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:
parent
68b7f4de7f
commit
19f51c2685
3 changed files with 18 additions and 4 deletions
|
@ -1,6 +1,14 @@
|
|||
import asyncio
|
||||
<<<<<<< HEAD
|
||||
from collections import defaultdict
|
||||
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
|
||||
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
|
||||
async def delete_message(self, message: discord.Message, epilogue: str) -> None:
|
||||
channel: discord.TextChannel = message.channel
|
||||
channel: discord.MessageableChannel = message.channel
|
||||
await message.delete()
|
||||
sent_message = await channel.send("-# GIF ratelimit exceeded " + epilogue)
|
||||
await asyncio.sleep(3)
|
||||
|
@ -89,14 +97,14 @@ class GifLimiter(commands.Cog):
|
|||
return
|
||||
|
||||
# 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_user[user].append(current_time)
|
||||
|
||||
# Function regularly cleans GIF lists and only keeps the most recent ones
|
||||
@tasks.loop(seconds=20)
|
||||
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():
|
||||
self.recent_gifs_by_channel[channel_id] = [t for t in timestamps if current_time - t < self.recent_gif_age]
|
||||
|
|
|
@ -6,7 +6,6 @@ from tux.database.controllers import DatabaseController
|
|||
from tux.ui.embeds import EmbedCreator, EmbedType
|
||||
from tux.utils.functions import is_harmful, strip_formatting
|
||||
|
||||
|
||||
class EventHandler(commands.Cog):
|
||||
def __init__(self, bot: Tux) -> None:
|
||||
self.bot = bot
|
||||
|
|
|
@ -77,6 +77,13 @@ class Constants:
|
|||
# Icon constants
|
||||
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_MAX_NAME_LENGTH = 256
|
||||
EMBED_MAX_DESC_LENGTH = 4096
|
||||
|
|
Loading…
Reference in a new issue