From d2f3355644942d5fdbb0c552b08dead702f3fa9a Mon Sep 17 00:00:00 2001 From: "Nyeki.py" <84998222+Nekidev@users.noreply.github.com> Date: Sat, 19 Oct 2024 21:42:18 -0300 Subject: [PATCH] feat(bot): :coffin: Remove appeals support. --- payphone/bot.py | 5 --- payphone/cogs/mods/cog.py | 1 - payphone/cogs/mods/modals.py | 43 +------------------ payphone/cogs/mods/views.py | 42 ------------------ .../models/12_20241019213937_update.py | 13 ++++++ payphone/db/models.py | 9 ---- 6 files changed, 14 insertions(+), 99 deletions(-) create mode 100644 payphone/db/migrations/models/12_20241019213937_update.py diff --git a/payphone/bot.py b/payphone/bot.py index c6c89d3..e65e1f9 100644 --- a/payphone/bot.py +++ b/payphone/bot.py @@ -39,9 +39,6 @@ class Payphone(commands.AutoShardedBot): console. """ - # Import from inside the function to prevent circular import errors. - from payphone.cogs.mods import views as mod_views - await setup.init() await redis.ping() @@ -50,8 +47,6 @@ class Payphone(commands.AutoShardedBot): constants.CHANNELS_ONCALL_SET, constants.CHANNELS_SEARCH_QUEUE ) - self.add_view(mod_views.BanNotificationView(self, models.Ban())) - print(f"Ready! Logged in as {self.user.display_name}.") async def on_shard_ready(self, shard_id: int) -> None: diff --git a/payphone/cogs/mods/cog.py b/payphone/cogs/mods/cog.py index 3f26e68..98cf14c 100644 --- a/payphone/cogs/mods/cog.py +++ b/payphone/cogs/mods/cog.py @@ -73,7 +73,6 @@ class Mods(base.Cog): await self.bot.get_or_fetch_user(user_id) ).send( embed=embeds.BanNotificationEmbed(self.bot, row), - view=views.BanNotificationView(self.bot, row), ) row.notification_message_id = notification_message.id diff --git a/payphone/cogs/mods/modals.py b/payphone/cogs/mods/modals.py index 056eb19..dc7c800 100644 --- a/payphone/cogs/mods/modals.py +++ b/payphone/cogs/mods/modals.py @@ -1,5 +1,3 @@ -from datetime import datetime, timezone - import discord from discord import errors @@ -11,44 +9,6 @@ from payphone.core import formatting from payphone.cogs.mods import embeds, views -class BanNotificationModal(discord.ui.Modal): - """Modal sent to users to appeal their ban.""" - - def __init__(self, bot: bot.Payphone) -> None: - """Initializes the modal.""" - - self.bot = bot - - super().__init__( - discord.ui.InputText( - custom_id="ban-notification-appeal:appeal", - label="Appeal", - placeholder="", - max_length=500, - required=True, - style=discord.InputTextStyle.long, - ), - title="Ban Appeal", - custom_id="ban-notification-appeal", - timeout=None, - ) - - @transactions.atomic() - async def callback(self, interaction: discord.Interaction): - ban = await models.Ban.get(notification_message_id=interaction.message.id) - - await interaction.response.defer() - - ban.appeal = self.children[0].value - ban.status = models.BanStatus.ON_REVIEW - await ban.save() - - await interaction.message.edit( - embed=embeds.BanNotificationEmbed(self.bot, ban), - view=views.BanNotificationView(self.bot, ban), - ) - - class BanUserModal(discord.ui.Modal): """Modal sent to ban a user.""" @@ -107,8 +67,7 @@ class BanUserModal(discord.ui.Modal): notification_message = await ( await self.bot.get_or_fetch_user(self.profile.user_id) ).send( - embed=embeds.BanNotificationEmbed(self.bot, ban), - view=views.BanNotificationView(self.bot, ban), + embed=embeds.BanNotificationEmbed(self.bot, ban) ) ban.notification_message_id = notification_message.id diff --git a/payphone/cogs/mods/views.py b/payphone/cogs/mods/views.py index b9dcfe9..9a75648 100644 --- a/payphone/cogs/mods/views.py +++ b/payphone/cogs/mods/views.py @@ -10,48 +10,6 @@ from payphone.core import constants from payphone.cogs.mods import modals, views, embeds -class BanNotificationView(discord.ui.View): - """View sent with the ban notification embed. - - This view contains a button that sends a modal to appeal the ban. - """ - - def __init__(self, bot: bot.Payphone, ban: models.Ban) -> None: - """Initializes the view. - - Args: - bot (bot.Payphone): The bot. - ban (models.Ban): The ban to appeal. - """ - - super().__init__(timeout=None) - - self.bot = bot - - if ban.status != models.BanStatus.VALID: - self.disable_all_items() - self.children[0].label = "Appealed" - - self.add_item( - discord.ui.Button( - label=f"Status: {ban.status.name.replace("_", " ").lower().title()}", - disabled=True, - ) - ) - - @discord.ui.button( - label="Appeal Ban", - custom_id="ban-notification:appeal-ban", - style=discord.ButtonStyle.blurple, - ) - async def callback( - self, _button: discord.ui.Button, interaction: discord.Interaction - ) -> None: - """Sends the ban appeal modal.""" - - await interaction.response.send_modal(modals.BanNotificationModal(self.bot)) - - class ReportView(discord.ui.View): """The view sent together with the report embed.""" diff --git a/payphone/db/migrations/models/12_20241019213937_update.py b/payphone/db/migrations/models/12_20241019213937_update.py new file mode 100644 index 0000000..c42ce82 --- /dev/null +++ b/payphone/db/migrations/models/12_20241019213937_update.py @@ -0,0 +1,13 @@ +from tortoise import BaseDBAsyncClient + + +async def upgrade(db: BaseDBAsyncClient) -> str: + return """ + ALTER TABLE "ban" DROP COLUMN "appeal"; + ALTER TABLE "ban" DROP COLUMN "status";""" + + +async def downgrade(db: BaseDBAsyncClient) -> str: + return """ + ALTER TABLE "ban" ADD "appeal" VARCHAR(500); + ALTER TABLE "ban" ADD "status" SMALLINT NOT NULL DEFAULT 0;""" diff --git a/payphone/db/models.py b/payphone/db/models.py index 05daf41..1041b0a 100644 --- a/payphone/db/models.py +++ b/payphone/db/models.py @@ -337,13 +337,6 @@ class Report(models.Model): created_at: datetime = fields.DatetimeField(auto_now_add=True) -class BanStatus(enum.IntEnum): - VALID = 0 - ON_REVIEW = 1 - APPEAL_ACCEPTED = 2 - APPEAL_DECLINED = 3 - - class Ban(models.Model): user_id: int = fields.BigIntField() report: fields.ForeignKeyNullableRelation["Report"] = fields.ForeignKeyField( @@ -354,8 +347,6 @@ class Ban(models.Model): ) notification_message_id: int = fields.BigIntField(null=True, db_index=True) reason: str = fields.CharField(max_length=500) - appeal: str | None = fields.CharField(max_length=500, null=True) - status: BanStatus = fields.IntEnumField(BanStatus, default=BanStatus.VALID) banned_by: fields.ForeignKeyRelation["User"] = fields.ForeignKeyField( "models.User", related_name="bans_created", null=True )