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

42 lines
1.5 KiB
Python
Raw Permalink 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:
2020-08-23 22:13:38 +00:00
async with data.session_acm() as session:
author = await data.find_author(session=session, required=True)
if "banker" not in author.roles:
raise rc.UserError("Non hai permessi sufficienti per eseguire questo comando.")
2020-01-31 00:47:44 +00:00
2020-08-23 22:13:38 +00:00
user_arg = args[0]
qty_arg = args[1]
reason_arg = " ".join(args[2:])
2020-01-31 00:47:44 +00:00
2020-08-23 22:13:38 +00:00
if user_arg is None:
raise rc.InvalidInputError("Non hai specificato un destinatario!")
2020-08-20 01:20:53 +00:00
user = await rbt.User.find(self.alchemy, session, user_arg)
2020-08-23 22:13:38 +00:00
if user is None:
raise rc.InvalidInputError("L'utente specificato non esiste!")
2020-01-31 00:47:44 +00:00
2020-08-23 22:13:38 +00:00
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!")
2020-01-31 00:47:44 +00:00
2020-08-23 22:13:38 +00:00
if reason_arg == "":
raise rc.InvalidInputError("Non hai specificato un motivo!")
2020-01-31 00:47:44 +00:00
2020-08-23 22:13:38 +00:00
await FiorygiTransaction.spawn_fiorygi(user, qty, reason_arg, data=data, session=session)