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

42 lines
1.4 KiB
Python
Raw Normal View History

2020-01-31 00:47:44 +00:00
from typing import *
import royalnet
import royalnet.commands as rc
import royalnet.serf.telegram as rt
2020-02-03 23:54:39 +00:00
from royalnet.backpack.tables import Alias
from ..tables import Fiorygi, 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)
if author.role != "Admin":
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-02-26 18:19:01 +00:00
user = await Alias.find_user(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)