1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-12-17 23:24:20 +00:00
royalnet/royalpack/commands/magickfiorygi.py

41 lines
1.4 KiB
Python
Raw Normal View History

2020-01-31 00:47:44 +00:00
from typing import *
import royalnet.commands as rc
2020-05-10 22:46:12 +00:00
import royalnet.backpack.tables as rbt
from ..tables import FiorygiTransaction
2020-01-31 00:47:44 +00:00
class MagickfiorygiCommand(rc.Command):
name: str = "magickfiorygi"
description: str = "Crea fiorygi dal nulla."
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)
2020-05-13 22:11:48 +00:00
if "banker" not in author.roles:
2020-01-31 00:47:44 +00:00
raise rc.UserError("Non hai permessi sufficienti per eseguire questo comando.")
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!")
2020-05-13 22:11:48 +00:00
user = await rbt.User.find(self.alchemy, data.session, user_arg)
2020-01-31 00:47:44 +00:00
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 reason_arg == "":
raise rc.InvalidInputError("Non hai specificato un motivo!")
2020-04-26 21:13:13 +00:00
await FiorygiTransaction.spawn_fiorygi(data, user, qty, reason_arg)