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

35 lines
1.3 KiB
Python
Raw Normal View History

2020-05-21 13:16:03 +00:00
from typing import *
import royalnet
import royalnet.commands as rc
import royalnet.utils as ru
from ..tables import Treasure, FiorygiTransaction
class TreasureCommand(rc.Command):
name: str = "treasure"
description: str = "Riscatta un Treasure che hai trovato da qualche parte."
syntax: str = "{code}"
async def run(self, args: rc.CommandArgs, data: rc.CommandData) -> None:
2020-08-23 22:13:38 +00:00
TreasureT = self.alchemy.get(Treasure)
2020-05-21 13:16:03 +00:00
2020-08-20 01:20:53 +00:00
async with data.session_acm() as session:
2020-08-23 22:13:38 +00:00
author = await data.find_author(session=session, required=True)
code = args[0].lower()
2020-05-21 13:16:03 +00:00
2020-08-20 01:20:53 +00:00
treasure = await ru.asyncify(session.query(TreasureT).get, code)
if treasure is None:
raise rc.UserError("Non esiste nessun Treasure con quel codice.")
if treasure.redeemed_by is not None:
raise rc.UserError(f"Quel tesoro è già stato riscattato da {treasure.redeemed_by}.")
2020-05-21 13:16:03 +00:00
2020-08-20 01:20:53 +00:00
treasure.redeemed_by = author
await ru.asyncify(session.commit)
2020-05-21 13:16:03 +00:00
await FiorygiTransaction.spawn_fiorygi(data,
author,
treasure.value,
f'aver trovato il tesoro "{treasure.code}"')
await data.reply("🤑 Tesoro riscattato!")