feat(bot):

This commit is contained in:
Nyeki.py
2024-10-17 01:11:37 -03:00
parent 5011ab5f90
commit c745df0a9d
19 changed files with 1273 additions and 439 deletions
+26 -10
View File
@@ -17,7 +17,7 @@ from payphone.core import config, constants, exceptions, formatting, help_comman
# TODO: Make it an AutoShardedBot on production.
class Payphone(commands.AutoShardedBot):
redis: aredis.Redis
redis = aredis.Redis(host="localhost" if config.IS_DEBUG else "redis")
def __init__(self) -> None:
intents = discord.Intents.default()
@@ -41,7 +41,6 @@ class Payphone(commands.AutoShardedBot):
await setup.init()
self.redis = aredis.Redis(host="localhost" if config.IS_DEBUG else "redis")
await self.redis.ping()
await self.redis.delete(
@@ -130,12 +129,12 @@ class Payphone(commands.AutoShardedBot):
return bool(int(is_banned))
is_banned = await models.Ban.filter(
expressions.Q(user_id=user_id)
& expressions.Q(
expressions.Q(user_id=user_id),
expressions.Q(
expires_at=None,
expires_at__lt=datetime.now(timezone.utc),
expires_at__gt=datetime.now(timezone.utc),
join_type="OR",
)
),
).exists()
await self.redis.set(key, int(is_banned), ex=300)
@@ -208,24 +207,41 @@ class Payphone(commands.AutoShardedBot):
await self.redis.set(key, "0", ex=300)
async def get_prefix(self, message: discord.Message) -> str | list[str]:
async def get_prefix(
self, message: discord.Message | None = None, server_id: int | None = None
) -> str | list[str]:
"""Returns the prefix for the message.
The prefix is case-insensitive, meaning that it'll adapt to the message to be valid not
depending of the case. In case that the prefix is invalid, the default or set prefix in its
original case will be returned.
This method can also be used on a server's raw ID. Either `message` or `server_id` must be
set, but not both.
Args:
message (discord.Message): The message to check the prefix for.
message (discord.Message | None): The message to check the prefix for, or None.
server_id (int | None): The server's ID to get the prefix from.
Returns:
str: The prefix for the message.
Raises:
ValueError: Either `message` or `server_id` must be set, but not both.
"""
if message.guild is None:
if message is not None and server_id is not None:
raise ValueError(
"Either `message` or `server_id` must be set, but not both."
)
if message is None and server_id is None:
raise ValueError("Either `message` or `server_id` must be set.")
if message is not None and message.guild is None:
return ["p.", "P."]
server_id = message.guild.id
server_id = server_id if server_id is not None else message.guild.id
key = constants.PREFIX_TEMPLATE % server_id