1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-30 15:04:18 +00:00
royalnet/royalpack/commands/treasure.py

34 lines
1.2 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:
author = await data.get_author(error_if_none=True)
2020-05-24 09:36:10 +00:00
code = args[0].lower()
2020-05-21 13:16:03 +00:00
TreasureT = self.alchemy.get(Treasure)
treasure = await ru.asyncify(data.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}.")
treasure.redeemed_by = author
await data.session_commit()
await FiorygiTransaction.spawn_fiorygi(data,
author,
treasure.value,
f'aver trovato il tesoro "{treasure.code}"')
await data.reply("🤑 Tesoro riscattato!")