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

36 lines
1.1 KiB
Python
Raw Permalink Normal View History

2020-05-21 16:56:20 +00:00
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}"
2020-08-20 01:20:53 +00:00
async def _permission_check(self, author, code, value, data, session):
2020-05-21 16:56:20 +00:00
if author.fiorygi.fiorygi < value:
raise rc.UserError("Non hai abbastanza fiorygi per creare questo Treasure.")
2020-08-20 01:20:53 +00:00
async def _create_treasure(self, author, code, value, data, session):
2020-05-21 16:56:20 +00:00
TreasureT = self.alchemy.get(Treasure)
2020-08-20 01:20:53 +00:00
treasure = await ru.asyncify(session.query(TreasureT).get, code)
2020-05-21 16:56:20 +00:00
if treasure is not None:
raise rc.UserError("Esiste già un Treasure con quel codice.")
treasure = TreasureT(
code=code,
value=value,
redeemed_by=None
)
2020-08-23 22:13:38 +00:00
await FiorygiTransaction.spawn_fiorygi(author, -value, "aver creato un tesoro", data=data, session=session)
2020-05-21 16:56:20 +00:00
return treasure