diff --git a/payphone/bot.py b/payphone/bot.py index 104abe0..74c704f 100644 --- a/payphone/bot.py +++ b/payphone/bot.py @@ -316,7 +316,9 @@ class Payphone(commands.AutoShardedBot): return ban - async def unban(self, user_id: int, expired_by: int | None, send_notification: bool = True) -> None: + async def unban( + self, user_id: int, expired_by: int | None, send_notification: bool = True + ) -> None: """Unbans a user. Args: diff --git a/payphone/cogs/admin/cog.py b/payphone/cogs/admin/cog.py index 7b1af1b..ec2bf66 100644 --- a/payphone/cogs/admin/cog.py +++ b/payphone/cogs/admin/cog.py @@ -459,6 +459,26 @@ class Admin(base.Cog): except discord.DiscordException: pass + @commands.command() + @checks.is_in_server(constants.PAYPHONE_HUB_ID) + @checks.is_moderator() + async def lock(self, ctx: commands.Context) -> None: + """Closes and locks a thread. + + Permissions: + - Bot Moderator + - In Payphone Hub + """ + + if isinstance(ctx.channel, discord.Thread): + await ctx.channel.edit( + archived=True, + locked=True, + ) + return await ctx.send("🎫 This ticket was closed.") + + await ctx.send("❌ This is not a ticket!") + def setup(bot: Payphone) -> None: """Loads the Admin cog into the bot. diff --git a/payphone/core/calls.py b/payphone/core/calls.py index ea5b462..71e18c2 100644 --- a/payphone/core/calls.py +++ b/payphone/core/calls.py @@ -303,7 +303,7 @@ class Call: mask=data["mask"], is_masked=data["is_masked"], channel_id=data["channel_id"], - call_id=self.id + call_id=self.id, ) ) diff --git a/payphone/core/checks.py b/payphone/core/checks.py index ce1bf21..9a6e437 100644 --- a/payphone/core/checks.py +++ b/payphone/core/checks.py @@ -56,3 +56,10 @@ def is_on_call(): return True return commands.check(predicate) + + +def is_in_server(server_id: int): + async def predicate(ctx): + return ctx.guild and ctx.guild.id == server_id + + return commands.check(predicate) diff --git a/payphone/core/constants.py b/payphone/core/constants.py index ef1a4d6..deee502 100644 --- a/payphone/core/constants.py +++ b/payphone/core/constants.py @@ -42,6 +42,8 @@ SENTRY_DSN = os.getenv( VERSION = None +PAYPHONE_HUB_ID = 1248511160286842992 + with open("pyproject.toml", "r", encoding="UTF-8") as f: data = toml.load(f) VERSION = "v" + data["project"]["version"].split(".")[1] diff --git a/payphone/core/formatting.py b/payphone/core/formatting.py index cd34d26..e394960 100644 --- a/payphone/core/formatting.py +++ b/payphone/core/formatting.py @@ -15,7 +15,7 @@ def trim(text: str, length: int = 100) -> str: """ if len(text) > length: - return text[:length - 3] + "..." + return text[: length - 3] + "..." return text @@ -157,7 +157,7 @@ def time_to_text(time_diff: timedelta) -> str: str: The string representation. """ - years = time_diff.days // 365 + years = time_diff.days // 365 days = time_diff.days % 365 hours, remainder = divmod(time_diff.seconds, 3600) minutes, seconds = divmod(remainder, 60) diff --git a/payphone/tasks/__init__.py b/payphone/tasks/__init__.py index a5fec44..a5e05ab 100644 --- a/payphone/tasks/__init__.py +++ b/payphone/tasks/__init__.py @@ -1 +1 @@ -from payphone.tasks import connect, expire \ No newline at end of file +from payphone.tasks import connect, expire diff --git a/pyproject.toml b/pyproject.toml index da6ee20..d0a8c7c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,11 @@ requires-python = ">=3.12" dependencies = [ "aerich>=0.8.2", "aiohttp>=3.10.10", "orjson>=3.10.11", "py-cord>=2.6.1", "redis[hiredis]>=5.2.0", "rich>=13.9.4", "sentry-sdk>=2.22.0", "toml>=0.10.2", "tortoise-orm[accel,asyncpg]>=0.21.7", "typer>=0.13.0",] [dependency-groups] -dev = [ "python-dotenv>=1.0.1", "pyyaml>=6.0.2",] +dev = [ + "black>=25.1.0", + "python-dotenv>=1.0.1", + "pyyaml>=6.0.2", +] [tool.aerich] tortoise_orm = "payphone.db.setup.CONFIG" diff --git a/uv.lock b/uv.lock index 406cb1c..39931c1 100644 --- a/uv.lock +++ b/uv.lock @@ -169,6 +169,30 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/77/06/bb80f5f86020c4551da315d78b3ab75e8228f89f0162f2c3a819e407941a/attrs-25.3.0-py3-none-any.whl", hash = "sha256:427318ce031701fea540783410126f03899a97ffc6f61596ad581ac2e40e3bc3", size = 63815 }, ] +[[package]] +name = "black" +version = "25.1.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "click" }, + { name = "mypy-extensions" }, + { name = "packaging" }, + { name = "pathspec" }, + { name = "platformdirs" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/94/49/26a7b0f3f35da4b5a65f081943b7bcd22d7002f5f0fb8098ec1ff21cb6ef/black-25.1.0.tar.gz", hash = "sha256:33496d5cd1222ad73391352b4ae8da15253c5de89b93a80b3e2c8d9a19ec2666", size = 649449 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/83/71/3fe4741df7adf015ad8dfa082dd36c94ca86bb21f25608eb247b4afb15b2/black-25.1.0-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:4b60580e829091e6f9238c848ea6750efed72140b91b048770b64e74fe04908b", size = 1650988 }, + { url = "https://files.pythonhosted.org/packages/13/f3/89aac8a83d73937ccd39bbe8fc6ac8860c11cfa0af5b1c96d081facac844/black-25.1.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:1e2978f6df243b155ef5fa7e558a43037c3079093ed5d10fd84c43900f2d8ecc", size = 1453985 }, + { url = "https://files.pythonhosted.org/packages/6f/22/b99efca33f1f3a1d2552c714b1e1b5ae92efac6c43e790ad539a163d1754/black-25.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:3b48735872ec535027d979e8dcb20bf4f70b5ac75a8ea99f127c106a7d7aba9f", size = 1783816 }, + { url = "https://files.pythonhosted.org/packages/18/7e/a27c3ad3822b6f2e0e00d63d58ff6299a99a5b3aee69fa77cd4b0076b261/black-25.1.0-cp312-cp312-win_amd64.whl", hash = "sha256:ea0213189960bda9cf99be5b8c8ce66bb054af5e9e861249cd23471bd7b0b3ba", size = 1440860 }, + { url = "https://files.pythonhosted.org/packages/98/87/0edf98916640efa5d0696e1abb0a8357b52e69e82322628f25bf14d263d1/black-25.1.0-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:8f0b18a02996a836cc9c9c78e5babec10930862827b1b724ddfe98ccf2f2fe4f", size = 1650673 }, + { url = "https://files.pythonhosted.org/packages/52/e5/f7bf17207cf87fa6e9b676576749c6b6ed0d70f179a3d812c997870291c3/black-25.1.0-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:afebb7098bfbc70037a053b91ae8437c3857482d3a690fefc03e9ff7aa9a5fd3", size = 1453190 }, + { url = "https://files.pythonhosted.org/packages/e3/ee/adda3d46d4a9120772fae6de454c8495603c37c4c3b9c60f25b1ab6401fe/black-25.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:030b9759066a4ee5e5aca28c3c77f9c64789cdd4de8ac1df642c40b708be6171", size = 1782926 }, + { url = "https://files.pythonhosted.org/packages/cc/64/94eb5f45dcb997d2082f097a3944cfc7fe87e071907f677e80788a2d7b7a/black-25.1.0-cp313-cp313-win_amd64.whl", hash = "sha256:a22f402b410566e2d1c950708c77ebf5ebd5d0d88a6a2e87c86d9fb48afa0d18", size = 1442613 }, + { url = "https://files.pythonhosted.org/packages/09/71/54e999902aed72baf26bca0d50781b01838251a462612966e9fc4891eadd/black-25.1.0-py3-none-any.whl", hash = "sha256:95e8176dae143ba9097f351d174fdaf0ccd29efb414b362ae3fd72bf0f710717", size = 207646 }, +] + [[package]] name = "certifi" version = "2025.1.31" @@ -378,6 +402,15 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/99/b7/b9e70fde2c0f0c9af4cc5277782a89b66d35948ea3369ec9f598358c3ac5/multidict-6.1.0-py3-none-any.whl", hash = "sha256:48e171e52d1c4d33888e529b999e5900356b9ae588c2f09a52dcefb158b27506", size = 10051 }, ] +[[package]] +name = "mypy-extensions" +version = "1.0.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/98/a4/1ab47638b92648243faf97a5aeb6ea83059cc3624972ab6b8d2316078d3f/mypy_extensions-1.0.0.tar.gz", hash = "sha256:75dbf8955dc00442a438fc4d0666508a9a97b6bd41aa2f0ffe9d2f2725af0782", size = 4433 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/2a/e2/5d3f6ada4297caebe1a2add3b126fe800c96f56dbe5d1988a2cbe0b267aa/mypy_extensions-1.0.0-py3-none-any.whl", hash = "sha256:4392f6c0eb8a5668a69e23d168ffa70f0be9ccfd32b5cc2d26a34ae5b844552d", size = 4695 }, +] + [[package]] name = "orjson" version = "3.10.15" @@ -412,9 +445,27 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/27/f1/1d7ec15b20f8ce9300bc850de1e059132b88990e46cd0ccac29cbf11e4f9/orjson-3.10.15-cp313-cp313-win_amd64.whl", hash = "sha256:fd56a26a04f6ba5fb2045b0acc487a63162a958ed837648c5781e1fe3316cfbf", size = 133444 }, ] +[[package]] +name = "packaging" +version = "24.2" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/d0/63/68dbb6eb2de9cb10ee4c9c14a0148804425e13c4fb20d61cce69f53106da/packaging-24.2.tar.gz", hash = "sha256:c228a6dc5e932d346bc5739379109d49e8853dd8223571c7c5b55260edc0b97f", size = 163950 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/88/ef/eb23f262cca3c0c4eb7ab1933c3b1f03d021f2c48f54763065b6f0e321be/packaging-24.2-py3-none-any.whl", hash = "sha256:09abb1bccd265c01f4a3aa3f7a7db064b36514d2cba19a2f694fe6150451a759", size = 65451 }, +] + +[[package]] +name = "pathspec" +version = "0.12.1" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/ca/bc/f35b8446f4531a7cb215605d100cd88b7ac6f44ab3fc94870c120ab3adbf/pathspec-0.12.1.tar.gz", hash = "sha256:a482d51503a1ab33b1c67a6c3813a26953dbdc71c31dacaef9a838c4e29f5712", size = 51043 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/cc/20/ff623b09d963f88bfde16306a54e12ee5ea43e9b597108672ff3a408aad6/pathspec-0.12.1-py3-none-any.whl", hash = "sha256:a0d503e138a4c123b27490a4f7beda6a01c6f288df0e4a8b79c7eb0dc7b4cc08", size = 31191 }, +] + [[package]] name = "payphone" -version = "0.82.0" +version = "0.83.0" source = { virtual = "." } dependencies = [ { name = "aerich" }, @@ -431,6 +482,7 @@ dependencies = [ [package.dev-dependencies] dev = [ + { name = "black" }, { name = "python-dotenv" }, { name = "pyyaml" }, ] @@ -451,10 +503,20 @@ requires-dist = [ [package.metadata.requires-dev] dev = [ + { name = "black", specifier = ">=25.1.0" }, { name = "python-dotenv", specifier = ">=1.0.1" }, { name = "pyyaml", specifier = ">=6.0.2" }, ] +[[package]] +name = "platformdirs" +version = "4.3.7" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/b6/2d/7d512a3913d60623e7eb945c6d1b4f0bddf1d0b7ada5225274c87e5b53d1/platformdirs-4.3.7.tar.gz", hash = "sha256:eb437d586b6a0986388f0d6f74aa0cde27b48d0e3d66843640bfb6bdcdb6e351", size = 21291 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/6d/45/59578566b3275b8fd9157885918fcd0c4d74162928a5310926887b856a51/platformdirs-4.3.7-py3-none-any.whl", hash = "sha256:a03875334331946f13c549dbd8f4bac7a13a50a895a0eb1e8c6a8ace80d40a94", size = 18499 }, +] + [[package]] name = "propcache" version = "0.3.0"