From aaae63c42044adfdd82f0e9eae7926ee347c83f4 Mon Sep 17 00:00:00 2001 From: "Nyeki.py" <84998222+Nekidev@users.noreply.github.com> Date: Thu, 17 Oct 2024 02:10:18 -0300 Subject: [PATCH] feat(bot): :sparkles: Make prefixes allow up to 5 characters. --- payphone/bot.py | 6 +++--- .../db/migrations/models/3_20241017020958_update.py | 11 +++++++++++ payphone/db/models.py | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 payphone/db/migrations/models/3_20241017020958_update.py diff --git a/payphone/bot.py b/payphone/bot.py index 5edb677..c407c53 100644 --- a/payphone/bot.py +++ b/payphone/bot.py @@ -271,16 +271,16 @@ class Payphone(commands.AutoShardedBot): Args: server (discord.Guild | models.Server | int): The server to update or it's ID. - prefix (str, optional): The new prefix. It cannot be longer than 3 characters. Defaults + prefix (str, optional): The new prefix. It cannot be longer than 5 characters. Defaults to "p.". Raises: ValueError: The prefix provided is invalid. """ - if len(prefix) > 3 or len(prefix) == 0: + if len(prefix) > 5 or len(prefix) == 0: raise ValueError( - "The prefix must not be longer than 3 characters and must not be an empty string." + "The prefix must not be longer than 5 characters and must not be an empty string." ) server_id = server if isinstance(server, int) else server.id diff --git a/payphone/db/migrations/models/3_20241017020958_update.py b/payphone/db/migrations/models/3_20241017020958_update.py new file mode 100644 index 0000000..7737e8f --- /dev/null +++ b/payphone/db/migrations/models/3_20241017020958_update.py @@ -0,0 +1,11 @@ +from tortoise import BaseDBAsyncClient + + +async def upgrade(db: BaseDBAsyncClient) -> str: + return """ + ALTER TABLE "server" ALTER COLUMN "prefix" TYPE VARCHAR(5) USING "prefix"::VARCHAR(5);""" + + +async def downgrade(db: BaseDBAsyncClient) -> str: + return """ + ALTER TABLE "server" ALTER COLUMN "prefix" TYPE VARCHAR(3) USING "prefix"::VARCHAR(3);""" diff --git a/payphone/db/models.py b/payphone/db/models.py index f1c8305..59e7b86 100644 --- a/payphone/db/models.py +++ b/payphone/db/models.py @@ -73,7 +73,7 @@ class Profile(models.Model): class Server(models.Model): id: int = fields.BigIntField(primary_key=True) - prefix: str = fields.CharField(max_length=3, default="p.") + prefix: str = fields.CharField(max_length=5, default="p.") channels: fields.BackwardFKRelation["Channel"] profiles: fields.BackwardFKRelation["Profile"]