diff --git a/pyproject.toml b/pyproject.toml index 205eeefa..9506e992 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,7 +2,7 @@ [tool.poetry] name = "royalpack" - version = "5.8.5" + version = "5.8.6" description = "A Royalnet command pack for the Royal Games community" authors = ["Stefano Pigozzi "] license = "AGPL-3.0+" diff --git a/royalpack/commands/__init__.py b/royalpack/commands/__init__.py index fca178ba..e6d40c58 100644 --- a/royalpack/commands/__init__.py +++ b/royalpack/commands/__init__.py @@ -57,7 +57,7 @@ from .royalpack import RoyalpackCommand from .givefiorygi import GivefiorygiCommand from .help import HelpCommand from .pug import PugCommand -from .createtreasure import CreatetreasureCommand +from .magicktreasure import CreatetreasureCommand from .treasure import TreasureCommand # Enter the commands of your Pack here! diff --git a/royalpack/commands/givetreasure.py b/royalpack/commands/givetreasure.py new file mode 100644 index 00000000..40a8b10d --- /dev/null +++ b/royalpack/commands/givetreasure.py @@ -0,0 +1,37 @@ +from typing import * +import royalnet +import royalnet.commands as rc +import royalnet.utils as ru +from ..tables import Treasure, FiorygiTransaction +from .magicktreasure import MagicktreasureCommand + + +class GivetreasureCommand(MagicktreasureCommand): + name: str = "givetreasure" + + description: str = "Crea un nuovo Treasure di Fiorygi (usando il tuo credito)" + + syntax: str = "{codice} {valore}" + + async def _permission_check(self, author, code, value, data): + if "banker" not in author.roles: + raise rc.UserError("Non hai permessi sufficienti per eseguire questo comando.") + if author.fiorygi.fiorygi < value: + raise rc.UserError("Non hai abbastanza fiorygi per creare questo Treasure.") + + async def _create_treasure(self, author, code, value, data): + TreasureT = self.alchemy.get(Treasure) + + treasure = await ru.asyncify(data.session.query(TreasureT).get, code) + if treasure is not None: + raise rc.UserError("Esiste già un Treasure con quel codice.") + + treasure = TreasureT( + code=code, + value=value, + redeemed_by=None + ) + + await FiorygiTransaction.spawn_fiorygi(data, author, -value, "aver creato un tesoro") + + return treasure diff --git a/royalpack/commands/createtreasure.py b/royalpack/commands/magicktreasure.py similarity index 69% rename from royalpack/commands/createtreasure.py rename to royalpack/commands/magicktreasure.py index d49a75f8..2b16b16f 100644 --- a/royalpack/commands/createtreasure.py +++ b/royalpack/commands/magicktreasure.py @@ -5,26 +5,19 @@ import royalnet.utils as ru from ..tables import Treasure -class CreatetreasureCommand(rc.Command): - name: str = "createtreasure" +class MagicktreasureCommand(rc.Command): + name: str = "magicktreasure" - description: str = "Crea un nuovo tesoro di Fiorygi." + description: str = "Crea un nuovo Treasure di Fiorygi (senza spendere i tuoi)." syntax: str = "{codice} {valore}" - async def run(self, args: rc.CommandArgs, data: rc.CommandData) -> None: - author = await data.get_author(error_if_none=True) + async def _permission_check(self, author, code, value, data): if "banker" not in author.roles: raise rc.UserError("Non hai permessi sufficienti per eseguire questo comando.") + return author - code = args[0] - try: - value = int(args[1]) - except ValueError: - raise rc.InvalidInputError("Il valore deve essere maggiore o uguale a 0.") - if value < 0: - raise rc.InvalidInputError("Il valore deve essere maggiore o uguale a 0.") - + async def _create_treasure(self, author, code, value, data): TreasureT = self.alchemy.get(Treasure) treasure = await ru.asyncify(data.session.query(TreasureT).get, code) @@ -36,8 +29,25 @@ class CreatetreasureCommand(rc.Command): value=value, redeemed_by=None ) + + return treasure + + async def run(self, args: rc.CommandArgs, data: rc.CommandData) -> None: + await data.delete_invoking() + author = await data.get_author(error_if_none=True) + + code = args[0] + try: + value = int(args[1]) + except ValueError: + raise rc.InvalidInputError("Il valore deve essere maggiore o uguale a 0.") + if value < 0: + raise rc.InvalidInputError("Il valore deve essere maggiore o uguale a 0.") + + await self._permission_check(author, code, value, data) + treasure = await self._create_treasure(author, code, value, data) + data.session.add(treasure) await data.session_commit() - await data.delete_invoking() - await data.reply("✅ Tesoro creato!") + await data.reply("✅ Treasure creato!") diff --git a/royalpack/version.py b/royalpack/version.py index 8454abc1..206beda3 100644 --- a/royalpack/version.py +++ b/royalpack/version.py @@ -1 +1 @@ -semantic = "5.8.5" +semantic = "5.8.6"