Skip to content

Commit

Permalink
🛠️Fix exc_manager
Browse files Browse the repository at this point in the history
  • Loading branch information
Aluerie committed Feb 14, 2025
1 parent d50233e commit acd406d
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 31 deletions.
12 changes: 6 additions & 6 deletions bot/exc_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
from pathlib import Path
from typing import TYPE_CHECKING

import discord

if TYPE_CHECKING:
from collections.abc import Generator

import discord

from .bot import AluBot


Expand All @@ -30,13 +30,13 @@ class ExceptionManager:
Attributes
----------
bot : AluBot
bot: AluBot
The bot instance.
cooldown : datetime.timedelta
cooldown: datetime.timedelta
The cooldown between sending errors. This defaults to 5 seconds.
errors_cache : dict[str, list[ErrorInfoPacket]]
errors_cache: dict[str, list[ErrorInfoPacket]]
A mapping of tracebacks to their error information.
error_webhook : discord.Webhook
error_webhook: discord.Webhook
The error webhook used to send errors.
"""
Expand Down
5 changes: 4 additions & 1 deletion utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
# from .const import *
from discord.utils import MISSING

# I just want to be able to do `from utils import MISSING`
__all__ = ("MISSING",)
2 changes: 1 addition & 1 deletion utils/const/other.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def url(self) -> str:
class Slash(StrEnum):
"""Slash mentions strings.
These are to be used when we can't easily access `bot.tree` for its `find_mention_for` method.
These are to be used when we can't easily access `bot.tree` for its `find_mention` method.
"""

feedback = "</feedback:1060350834367549541>"
Expand Down
2 changes: 1 addition & 1 deletion utils/dota/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .steamio_client import *
from .schemas import *
from .steamio_client import *
from .storage import *
57 changes: 35 additions & 22 deletions utils/pages.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
"""Pagination Menus View Classes.
These classes do not use `discord.ext.menus` and instead mirror some of their methods
under `Paginator` class' namespace instead. The principle is the same though:
We need to subclass `Paginator` and implement `format_page` that
uses slice of entries passed to the class and should return kwargs to be send
with `.send` methods, i.e. Embed or dict.
Sources
-------
* Gist by Soheab
Expand All @@ -20,7 +26,7 @@

from bot import AluView

from . import const
from . import MISSING, const

if TYPE_CHECKING:
from collections.abc import Sequence
Expand All @@ -32,10 +38,15 @@ class SendKwargs(TypedDict):
embed: NotRequired[discord.Embed]


__all__ = ("EmbedDescriptionPaginator", "Paginator")
__all__ = (
"EmbedDescriptionPaginator",
"Paginator",
)


class IndexModal(discord.ui.Modal, title="Go to page"):
"""Modal for the default button "index" which allows to navigate to a custom page in the Paginator."""

goto = discord.ui.TextInput(label="Page Number", min_length=1, required=True)

def __init__(self, paginator: Paginator) -> None:
Expand All @@ -55,7 +66,7 @@ async def on_submit(self, interaction: AluInteraction) -> None:
if not value.isdigit():
embed = discord.Embed(
color=const.Color.error,
description=f"Expected a page number between 1 and {self.paginator.max_pages}, not {value!r}",
description=f"Expected a page number between 1 and {self.paginator.max_pages}, not `{value!r}`",
)
await interaction.response.send_message(embed=embed, ephemeral=True)
return
Expand Down Expand Up @@ -192,9 +203,9 @@ async def _get_page_send_kwargs(self, page_entries: Any | Sequence[Any]) -> Send
if isinstance(send_kwargs, dict):
return send_kwargs
if isinstance(send_kwargs, str):
return {"content": send_kwargs, "embed": discord.utils.MISSING}
return {"content": send_kwargs, "embed": MISSING}
if isinstance(send_kwargs, discord.Embed):
return {"embed": send_kwargs, "content": discord.utils.MISSING}
return {"embed": send_kwargs, "content": MISSING}
return {}

def format_page(self, entries: Any | Sequence[Any]) -> str | discord.Embed | SendKwargs:
Expand Down Expand Up @@ -311,29 +322,31 @@ async def stop_pages(self, interaction: AluInteraction, _: discord.ui.Button[Sel
self.stop()


class EmbedAuthorTemplate(TypedDict):
name: str
icon_url: NotRequired[str]

if TYPE_CHECKING:

class EmbedFooterTemplate(TypedDict):
text: str
icon_url: NotRequired[str]
class EmbedAuthorTemplate(TypedDict):
name: str
url: NotRequired[str]
icon_url: NotRequired[str]

class EmbedFooterTemplate(TypedDict):
text: str
icon_url: NotRequired[str]

class EmbedTemplate(TypedDict):
"""Embed template with keys that I use the most in paginators (so it's quite incomplete).
class EmbedTemplate(TypedDict):
"""Embed template with keys that I use the most in paginators (so it's quite incomplete).
I mainly use this class for IDE-autocomplete purposes.
I mainly use this class for IDE-autocomplete purposes.
You can find out about this format in the discord API docs:
https://discord.com/developers/docs/resources/message#embed-object
"""
You can find out about this format in the discord API docs:
https://discord.com/developers/docs/resources/message#embed-object
"""

title: NotRequired[str]
color: NotRequired[int]
author: NotRequired[EmbedAuthorTemplate]
footer: NotRequired[EmbedFooterTemplate]
title: NotRequired[str]
url: NotRequired[str]
color: NotRequired[int]
author: NotRequired[EmbedAuthorTemplate]
footer: NotRequired[EmbedFooterTemplate]


class EmbedDescriptionPaginator(Paginator):
Expand Down

0 comments on commit acd406d

Please sign in to comment.