Skip to content

Commit

Permalink
🛠️More renaming around
Browse files Browse the repository at this point in the history
  • Loading branch information
Aluerie committed Feb 11, 2025
1 parent 6e9e6b9 commit 1cffa7a
Show file tree
Hide file tree
Showing 35 changed files with 279 additions and 283 deletions.
6 changes: 3 additions & 3 deletions bot/bases/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import discord
from discord.ext import commands

from utils import formats
from utils import fmt

if TYPE_CHECKING:
import datetime
Expand Down Expand Up @@ -42,7 +42,7 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:

@override
def __repr__(self) -> str:
return f"<AluContext cmd={self.command} ntr={formats.tick(bool(self.interaction))} author={self.author}>"
return f"<AluContext cmd={self.command} ntr={fmt.tick(bool(self.interaction))} author={self.author}>"

# The following attributes are here just to match discord.Interaction properties
# Just so we don't need to do `if isinstance(discord.Interaction):` checks every time
Expand Down Expand Up @@ -83,7 +83,7 @@ def session(self) -> ClientSession:
async def tick_reaction(self, semi_bool: bool | None) -> None:
"""Add tick reaction to `ctx.message`."""
with contextlib.suppress(discord.HTTPException):
await self.message.add_reaction(formats.tick(semi_bool))
await self.message.add_reaction(fmt.tick(semi_bool))

# the next two functions mean the following in a context of discord chat:
# /--> replying to @Bob: wow, 2+2=5
Expand Down
4 changes: 2 additions & 2 deletions bot/bases/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from discord.ext import tasks
from discord.utils import MISSING

from utils import formats
from utils import fmt

if TYPE_CHECKING:
import datetime
Expand Down Expand Up @@ -78,7 +78,7 @@ async def _error(self, cog: HasBotAttribute, exception: Exception) -> None:
meta = f"module = {self.coro.__module__}\nqualname = {self.coro.__qualname__}"
embed = (
discord.Embed(title=f"Task Error: `{self.coro.__name__}`", colour=0xEF7A85)
.add_field(name="Meta", value=formats.code(meta, "ebnf"), inline=False)
.add_field(name="Meta", value=fmt.code(meta, "ebnf"), inline=False)
.set_footer(text=f"{self.__class__.__name__}._error: {self.coro.__name__}")
)
await cog.bot.exc_manager.register_error(exception, embed)
Expand Down
6 changes: 3 additions & 3 deletions bot/bases/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import discord

from utils import const, errors, formats, helpers
from utils import const, errors, fmt, helpers

if TYPE_CHECKING:
from .context import AluInteraction
Expand Down Expand Up @@ -59,8 +59,8 @@ async def on_views_modals_error(
),
icon_url=interaction.user.display_avatar,
)
.add_field(name="View Objects", value=formats.code(args_join, "ps"), inline=False)
.add_field(name="Snowflake IDs", value=formats.code(snowflake_ids, "ebnf"), inline=False)
.add_field(name="View Objects", value=fmt.code(args_join, "ps"), inline=False)
.add_field(name="Snowflake IDs", value=fmt.code(snowflake_ids, "ebnf"), inline=False)
.set_footer(
text=f"{view.__class__.__name__}.on_error",
icon_url=interaction.guild.icon if interaction.guild else interaction.user.display_avatar,
Expand Down
35 changes: 13 additions & 22 deletions bot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from bot import EXT_CATEGORY_NONE, AluContext, ExtCategory
from config import config
from ext import get_extensions
from utils import cache, const, disambiguator, errors, formats, helpers, transposer
from utils import cache, const, disambiguator, errors, fmt, helpers, transposer

from .exc_manager import ExceptionManager
from .intents_perms import INTENTS, PERMISSIONS
Expand All @@ -37,14 +37,7 @@
log = logging.getLogger(__name__)


class AluBotHelper(TimerManager):
"""Extra class to help with MRO."""

def __init__(self, *, bot: AluBot) -> None:
super().__init__(bot=bot)


class AluBot(commands.Bot, AluBotHelper):
class AluBot(commands.Bot):
"""Main class for AluBot.
Essentially extended subclass over discord.py's `commands.Bot`
Expand All @@ -71,15 +64,13 @@ def __init__(
Parameters
----------
session : ClientSession
aiohttp.ClientSession to use within the bot.
pool : asyncpg.Pool[DotRecord]
A connection pool to the database.
test : bool, default=False
test: bool = False
whether the bot is a testing version (YenBot) or main production bot (AluBot).
I just like to use different discord bot token to debug issues, test new code, etc.
kwargs : Any
kwargs for the purpose of MRO and what not.
session: ClientSession
aiohttp.ClientSession to use within the bot.
pool: asyncpg.Pool[asyncpg.Record]
A connection pool to the database.
"""
self.test: bool = test
Expand Down Expand Up @@ -134,7 +125,7 @@ async def setup_hook(self) -> None:
# we could go with attribute option like exceptions manager
# but let's keep its methods nearby in AluBot namespace
# needs to be done after cogs are loaded so all cog event listeners are ready
super(AluBotHelper, self).__init__(bot=self)
self.timers = TimerManager(bot=self)

if self.test:
if failed_to_load_some_ext:
Expand Down Expand Up @@ -393,7 +384,7 @@ async def on_error(self: AluBot, event: str, *args: Any, **kwargs: Any) -> None:
args_join = "\n".join(f"[{index}]: {arg!r}" for index, arg in enumerate(args)) if args else "No Args"
embed = (
discord.Embed(colour=0xA32952, title=f"Event Error: `{event}`")
.add_field(name="Args", value=formats.code(args_join, "ps"), inline=False)
.add_field(name="Args", value=fmt.code(args_join, "ps"), inline=False)
.set_footer(text=f"{self.__class__.__name__}.on_error: {event}")
)
await self.exc_manager.register_error(exception, embed)
Expand Down Expand Up @@ -430,7 +421,7 @@ async def on_command_error(self, ctx: AluContext, error: commands.CommandError |
desc = (
f"Sorry! Incorrect argument value: {error.argument!r}.\n Only these options are valid "
f"for a parameter `{error.param.displayed_name or error.param.name}`:\n"
f"{formats.human_join([repr(literal) for literal in error.literals])}."
f"{fmt.human_join([repr(literal) for literal in error.literals])}."
)

case commands.EmojiNotFound():
Expand All @@ -450,7 +441,7 @@ async def on_command_error(self, ctx: AluContext, error: commands.CommandError |
# TODO: make a fuzzy search in here to recommend the command that user wants
desc = f"Please, double-check, did you make a typo? Or use `{ctx.prefix}help`"
case commands.CommandOnCooldown():
desc = f"Please retry in `{formats.human_timedelta(error.retry_after, mode='brief')}`"
desc = f"Please retry in `{fmt.human_timedelta(error.retry_after, mode='brief')}`"
case commands.NotOwner():
desc = f"Sorry, only {ctx.bot.owner} as the bot developer is allowed to use this command."
case commands.MissingRole():
Expand Down Expand Up @@ -483,8 +474,8 @@ async def on_command_error(self, ctx: AluContext, error: commands.CommandError |
name=f"@{ctx.author} in #{ctx.channel} ({ctx.guild.name if ctx.guild else 'DM Channel'})",
icon_url=ctx.author.display_avatar,
)
.add_field(name="Command Args", value=formats.code(kwargs_join, "ps"), inline=False)
.add_field(name="Snowflake IDs", value=formats.code(snowflake_ids, "ebnf"), inline=False)
.add_field(name="Command Args", value=fmt.code(kwargs_join, "ps"), inline=False)
.add_field(name="Snowflake IDs", value=fmt.code(snowflake_ids, "ebnf"), inline=False)
.set_footer(
text=f"on_command_error: {cmd_name}",
icon_url=ctx.guild.icon if ctx.guild else ctx.author.display_avatar,
Expand Down
4 changes: 2 additions & 2 deletions bot/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import discord

from config import config
from utils import const, formats
from utils import const, fmt

if TYPE_CHECKING:
from collections.abc import Generator
Expand Down Expand Up @@ -60,7 +60,7 @@ def setup_logging(*, test: bool) -> Generator[Any, Any, Any]:
log.info(ASCII_STARTING_UP_ART)
# send a webhook message as well
webhook = discord.SyncWebhook.from_url(config["WEBHOOKS"]["LOGGER"])
now_str = formats.format_dt(datetime.datetime.now(datetime.UTC), style="T")
now_str = fmt.format_dt(datetime.datetime.now(datetime.UTC), style="T")
embed = discord.Embed(
colour=discord.Colour.og_blurple(),
description=f"{now_str} The bot is restarting",
Expand Down
Loading

0 comments on commit 1cffa7a

Please sign in to comment.