feat(shard): ✨ A few changes.

This commit is contained in:
2025-04-02 00:57:30 -03:00
parent f1f71b61e4
commit e59c649195
4 changed files with 58 additions and 20 deletions
+12 -2
View File
@@ -297,7 +297,7 @@ class Payphone(commands.AutoShardedBot):
expires_at (datetime | None): When the ban expires. expires_at (datetime | None): When the ban expires.
created_by_id (int | None): The ID of the user who created the ban. created_by_id (int | None): The ID of the user who created the ban.
reason (str | None): The reason for the ban. reason (str | None): The reason for the ban.
Returns: Returns:
(Ban): The ban. (Ban): The ban.
""" """
@@ -316,12 +316,13 @@ class Payphone(commands.AutoShardedBot):
return ban return ban
async def unban(self, user_id: int, expired_by: int | None) -> None: async def unban(self, user_id: int, expired_by: int | None, send_notification: bool = True) -> None:
"""Unbans a user. """Unbans a user.
Args: Args:
user_id (int): The user to unban's ID. user_id (int): The user to unban's ID.
expired_by (int | None): The user who expired the ban. expired_by (int | None): The user who expired the ban.
send_notification (bool): Whether to send a notification to the user or not.
""" """
await models.Ban.filter( await models.Ban.filter(
@@ -334,6 +335,15 @@ class Payphone(commands.AutoShardedBot):
await self.redis.delete(f"banned:{user_id}") await self.redis.delete(f"banned:{user_id}")
if send_notification:
try:
await (await self.get_or_fetch_user(user_id)).send(
f"🔔 You have been unbanned from Payphone{f" by <@{expired_by}>" if expired_by else ""}."
)
except discord.DiscordException:
pass
async def on_command_error( async def on_command_error(
self, context: commands.Context, exception: commands.CommandError self, context: commands.Context, exception: commands.CommandError
) -> None: ) -> None:
+38 -17
View File
@@ -3,6 +3,8 @@ from datetime import datetime, timedelta, timezone
import discord import discord
from discord.ext import commands, pages from discord.ext import commands, pages
from tortoise import expressions
from payphone.db import models from payphone.db import models
from payphone.bot import Payphone from payphone.bot import Payphone
from payphone.cogs import base from payphone.cogs import base
@@ -109,12 +111,6 @@ class Admin(base.Cog):
await ctx.send(f"{user.mention} was unbanned from Payphone.") await ctx.send(f"{user.mention} was unbanned from Payphone.")
try:
await user.send("🔔 You were unbanned from Payphone!")
except discord.Forbidden:
pass
user: models.User = await models.User.get(id=user.id) user: models.User = await models.User.get(id=user.id)
await user.set_cache(self.bot.redis) await user.set_cache(self.bot.redis)
@@ -210,12 +206,13 @@ class Admin(base.Cog):
if not bans and not warns: if not bans and not warns:
if user.bans_count or user.warns_count: if user.bans_count or user.warns_count:
await ctx.send( await ctx.send(
"<@!{user_id}> has no bans nor warns registered in the database, but they" f"❓ <@{user_id}> has no bans nor warns recorded, but they have been banned"
f" have been banned `{user.bans_count}` times and warned `{user.warns_count}`." f" `{user.bans_count}` times and warned `{user.warns_count}` times.",
allowed_mentions=discord.AllowedMentions(users=False),
) )
return return
await ctx.send(f"<@!{user_id}> has no bans nor warns.") await ctx.send(f"<@!{user_id}> hasn't been banned nor warned.")
return return
ban_embeds = [ ban_embeds = [
@@ -357,13 +354,13 @@ class Admin(base.Cog):
return await ctx.send("❌ Warning not found.") return await ctx.send("❌ Warning not found.")
await models.User.filter(id=warn.user_id).update( await models.User.filter(id=warn.user_id).update(
warns_count=models.User.warns_count - 1 warns_count=expressions.F("warns_count") - 1
) )
await warn.delete() await warn.delete()
await ctx.send( await ctx.send(
f"✅ Deleted warning #{warn.id} for user <@{warn.user_id}>.", f"✅ Deleted warning `#{warn.id}` for user <@{warn.user_id}>.",
allowed_mentions=discord.AllowedMentions(users=False), allowed_mentions=discord.AllowedMentions(users=False),
) )
@@ -385,13 +382,25 @@ class Admin(base.Cog):
return await ctx.send("❌ Ban not found.") return await ctx.send("❌ Ban not found.")
await models.User.filter(id=ban.user_id).update( await models.User.filter(id=ban.user_id).update(
bans_count=models.User.bans_count - 1 bans_count=expressions.F("bans_count") - 1
) )
await ban.delete() await ban.delete()
if (
not await models.Ban.filter(
expressions.Q(
expires_at__gt=datetime.now(timezone.utc),
expires_at=None,
join_type="OR",
),
expressions.Q(user_id=ban.user_id),
).exists()
) and (ban.expires_at is None or ban.expires_at > datetime.now(timezone.utc)):
await self.bot.unban(ban.user_id, ctx.author.id)
await ctx.send( await ctx.send(
f"✅ Deleted ban #{ban.id} for user <@{ban.user_id}>.", f"✅ Deleted ban `#{ban.id}` for user <@{ban.user_id}>.",
allowed_mentions=discord.AllowedMentions(users=False), allowed_mentions=discord.AllowedMentions(users=False),
) )
@@ -409,15 +418,27 @@ class Admin(base.Cog):
- Bot Moderator - Bot Moderator
""" """
await models.User.filter(id=user.id).update(bans_count=0, warns_count=0) user_id = user if isinstance(user, int) else user.id if user else ctx.author.id
await models.Ban.filter(user_id=user.id).delete()
await models.Warn.filter(user_id=user.id).delete() await models.User.filter(id=user_id).update(bans_count=0, warns_count=0)
await models.Ban.filter(user_id=user_id).delete()
await models.Warn.filter(user_id=user_id).delete()
await self.bot.unban(user_id, ctx.author.id, False)
await ctx.send( await ctx.send(
f"✅ Cleared the record of <@{user.id}>.", f"✅ Cleared the record of <@{user_id}>.",
allowed_mentions=discord.AllowedMentions(users=False), allowed_mentions=discord.AllowedMentions(users=False),
) )
try:
await (await self.bot.get_or_fetch_user(user_id)).send(
f"✅ Your record has been cleared by {ctx.author.mention}. You are free to use the bot again."
)
except discord.DiscordException:
pass
def setup(bot: Payphone) -> None: def setup(bot: Payphone) -> None:
"""Loads the Admin cog into the bot. """Loads the Admin cog into the bot.
+7
View File
@@ -53,6 +53,13 @@ class ReportView(discord.ui.View):
self, select: discord.SelectMenu, interaction: discord.Interaction self, select: discord.SelectMenu, interaction: discord.Interaction
) -> None: ) -> None:
"""Handles the action select.""" """Handles the action select."""
interacter = await models.User.get_or_none(id=interaction.user.id)
if interacter is None or not interacter.is_moderator:
return await interaction.response.send_message(
"❌ You are not allowed to do this. Only moderators can perform moderative actions.",
ephemeral=True,
)
self.report.resolved = True self.report.resolved = True
await self.report.save() await self.report.save()
Generated
+1 -1
View File
@@ -414,7 +414,7 @@ wheels = [
[[package]] [[package]]
name = "payphone" name = "payphone"
version = "0.68.0" version = "0.69.0"
source = { virtual = "." } source = { virtual = "." }
dependencies = [ dependencies = [
{ name = "aerich" }, { name = "aerich" },