diff --git a/royalpack/commands/__init__.py b/royalpack/commands/__init__.py index 215e19e9..7c743bfc 100644 --- a/royalpack/commands/__init__.py +++ b/royalpack/commands/__init__.py @@ -54,6 +54,8 @@ from .matchmaking import MatchmakingCommand from .cvstats import CvstatsCommand from .elevatormusic import ElevatormusicCommand from .royalpack import RoyalpackCommand +from .givefiorygi import GivefiorygiCommand +from .help import HelpCommand # Enter the commands of your Pack here! available_commands = [ @@ -112,6 +114,8 @@ available_commands = [ CvstatsCommand, ElevatormusicCommand, RoyalpackCommand, + GivefiorygiCommand, + HelpCommand, ] # Don't change this, it should automatically generate __all__ diff --git a/royalpack/commands/ciaoruozi.py b/royalpack/commands/ciaoruozi.py index 727b7cca..be932f5b 100644 --- a/royalpack/commands/ciaoruozi.py +++ b/royalpack/commands/ciaoruozi.py @@ -6,7 +6,7 @@ from royalnet.commands import * class CiaoruoziCommand(Command): name: str = "ciaoruozi" - description: str = "Saluta Ruozi, un leggendario essere che una volta era in User Games." + description: str = "Saluta Ruozi, un leggendario essere che è tornato in Royal Games." async def run(self, args: CommandArgs, data: CommandData) -> None: if self.interface.name == "telegram": diff --git a/royalpack/commands/givefiorygi.py b/royalpack/commands/givefiorygi.py new file mode 100644 index 00000000..3511381f --- /dev/null +++ b/royalpack/commands/givefiorygi.py @@ -0,0 +1,44 @@ +from typing import * +import royalnet.commands as rc +import royalnet.backpack.tables as rbt + +from ..tables import FiorygiTransaction + + +class GivefiorygiCommand(rc.Command): + name: str = "givefiorygi" + + description: str = "Cedi fiorygi a un altro utente." + + syntax: str = "{destinatario} {quantità} {motivo}" + + async def run(self, args: rc.CommandArgs, data: rc.CommandData) -> None: + author = await data.get_author(error_if_none=True) + + user_arg = args[0] + qty_arg = args[1] + reason_arg = " ".join(args[2:]) + + if user_arg is None: + raise rc.InvalidInputError("Non hai specificato un destinatario!") + user = await rbt.User.find(self.alchemy, data.session, user_arg) + if user is None: + raise rc.InvalidInputError("L'utente specificato non esiste!") + + if qty_arg is None: + raise rc.InvalidInputError("Non hai specificato una quantità!") + try: + qty = int(qty_arg) + except ValueError: + raise rc.InvalidInputError("La quantità specificata non è un numero!") + if qty <= 0: + raise rc.InvalidInputError("La quantità specificata deve essere almeno 1!") + + if reason_arg == "": + raise rc.InvalidInputError("Non hai specificato un motivo!") + + if author.fiorygi.fiorygi < qty: + raise rc.InvalidInputError("Non hai abbastanza fiorygi per effettuare la transazione!") + + await FiorygiTransaction.spawn_fiorygi(data, author, -qty, reason_arg) + await FiorygiTransaction.spawn_fiorygi(data, user, qty, reason_arg) diff --git a/royalpack/commands/help.py b/royalpack/commands/help.py new file mode 100644 index 00000000..0b5a3675 --- /dev/null +++ b/royalpack/commands/help.py @@ -0,0 +1,27 @@ +from typing import * +import royalnet +import royalnet.commands as rc + + +class HelpCommand(rc.Command): + name: str = "help" + + description: str = "Visualizza informazioni su un comando." + + syntax: str = "{comando}" + + async def run(self, args: rc.CommandArgs, data: rc.CommandData) -> None: + name: str = args[0].lstrip(self.interface.prefix) + + try: + command: rc.Command = self.serf.commands[f"{self.interface.prefix}{name}"] + except KeyError: + raise rc.InvalidInputError("Il comando richiesto non esiste.") + + message = [ + f"[c]{self.interface.prefix}{command.name} {command.syntax}[/c]", + "", + f"{command.description}" + ] + + await data.reply("\n".join(message)) diff --git a/royalpack/commands/magickfiorygi.py b/royalpack/commands/magickfiorygi.py index 03e3e494..3f98f64e 100644 --- a/royalpack/commands/magickfiorygi.py +++ b/royalpack/commands/magickfiorygi.py @@ -14,7 +14,7 @@ class MagickfiorygiCommand(rc.Command): async def run(self, args: rc.CommandArgs, data: rc.CommandData) -> None: author = await data.get_author(error_if_none=True) - if author.role != "Admin": + if "banker" not in author.roles: raise rc.UserError("Non hai permessi sufficienti per eseguire questo comando.") user_arg = args[0] @@ -23,7 +23,7 @@ class MagickfiorygiCommand(rc.Command): if user_arg is None: raise rc.InvalidInputError("Non hai specificato un destinatario!") - user = await rbt.Alias.find_user(self.alchemy, data.session, user_arg) + user = await rbt.User.find(self.alchemy, data.session, user_arg) if user is None: raise rc.InvalidInputError("L'utente specificato non esiste!") diff --git a/royalpack/commands/matchmaking.py b/royalpack/commands/matchmaking.py index 3fb7c6ec..410adb2a 100644 --- a/royalpack/commands/matchmaking.py +++ b/royalpack/commands/matchmaking.py @@ -110,10 +110,10 @@ class MatchmakingCommand(rc.Command): if response.choice == MMChoice.LATE_SHORT: td = mmevent.datetime + datetime.timedelta(minutes=10) time_text = f" [{td.strftime('%H:%M')}]" - elif response.choice == MMChoice.LATE_SHORT: + elif response.choice == MMChoice.LATE_MEDIUM: td = mmevent.datetime + datetime.timedelta(minutes=30) time_text = f" [{td.strftime('%H:%M')}]" - elif response.choice == MMChoice.LATE_SHORT: + elif response.choice == MMChoice.LATE_LONG: td = mmevent.datetime + datetime.timedelta(minutes=60) time_text = f" [{td.strftime('%H:%M')}+]" else: