mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 19:44:20 +00:00
Add treasures
This commit is contained in:
parent
8f4ec1d1b9
commit
cb37a65a81
5 changed files with 105 additions and 0 deletions
|
@ -57,6 +57,8 @@ from .royalpack import RoyalpackCommand
|
||||||
from .givefiorygi import GivefiorygiCommand
|
from .givefiorygi import GivefiorygiCommand
|
||||||
from .help import HelpCommand
|
from .help import HelpCommand
|
||||||
from .pug import PugCommand
|
from .pug import PugCommand
|
||||||
|
from .createtreasure import CreatetreasureCommand
|
||||||
|
from .treasure import TreasureCommand
|
||||||
|
|
||||||
# Enter the commands of your Pack here!
|
# Enter the commands of your Pack here!
|
||||||
available_commands = [
|
available_commands = [
|
||||||
|
@ -118,6 +120,8 @@ available_commands = [
|
||||||
GivefiorygiCommand,
|
GivefiorygiCommand,
|
||||||
HelpCommand,
|
HelpCommand,
|
||||||
PugCommand,
|
PugCommand,
|
||||||
|
CreatetreasureCommand,
|
||||||
|
TreasureCommand,
|
||||||
]
|
]
|
||||||
|
|
||||||
# Don't change this, it should automatically generate __all__
|
# Don't change this, it should automatically generate __all__
|
||||||
|
|
43
royalpack/commands/createtreasure.py
Normal file
43
royalpack/commands/createtreasure.py
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
from typing import *
|
||||||
|
import royalnet
|
||||||
|
import royalnet.commands as rc
|
||||||
|
import royalnet.utils as ru
|
||||||
|
from ..tables import Treasure
|
||||||
|
|
||||||
|
|
||||||
|
class CreatetreasureCommand(rc.Command):
|
||||||
|
name: str = "createtreasure"
|
||||||
|
|
||||||
|
description: str = "Crea un nuovo tesoro di Fiorygi."
|
||||||
|
|
||||||
|
syntax: str = "{codice} {valore}"
|
||||||
|
|
||||||
|
async def run(self, args: rc.CommandArgs, data: rc.CommandData) -> None:
|
||||||
|
author = await data.get_author(error_if_none=True)
|
||||||
|
if "banker" not in author.roles:
|
||||||
|
raise rc.UserError("Non hai permessi sufficienti per eseguire questo comando.")
|
||||||
|
|
||||||
|
code = args[0]
|
||||||
|
try:
|
||||||
|
value = int(args[1])
|
||||||
|
except ValueError:
|
||||||
|
raise rc.InvalidInputError("Il valore deve essere maggiore o uguale a 0.")
|
||||||
|
if value < 0:
|
||||||
|
raise rc.InvalidInputError("Il valore deve essere maggiore o uguale a 0.")
|
||||||
|
|
||||||
|
TreasureT = self.alchemy.get(Treasure)
|
||||||
|
|
||||||
|
treasure = await ru.asyncify(data.session.query(TreasureT).get, code)
|
||||||
|
if treasure is not None:
|
||||||
|
raise rc.UserError("Esiste già un Treasure con quel codice.")
|
||||||
|
|
||||||
|
treasure = TreasureT(
|
||||||
|
code=code,
|
||||||
|
value=value,
|
||||||
|
redeemed_by=None
|
||||||
|
)
|
||||||
|
data.session.add(treasure)
|
||||||
|
await data.session_commit()
|
||||||
|
|
||||||
|
await data.delete_invoking()
|
||||||
|
await data.reply("✅ Tesoro creato!")
|
33
royalpack/commands/treasure.py
Normal file
33
royalpack/commands/treasure.py
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
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)
|
||||||
|
code = args[0]
|
||||||
|
|
||||||
|
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!")
|
|
@ -17,6 +17,7 @@ from .brawlhalladuos import BrawlhallaDuo
|
||||||
from .mmevents import MMEvent
|
from .mmevents import MMEvent
|
||||||
from .mmresponse import MMResponse
|
from .mmresponse import MMResponse
|
||||||
from .cvstats import Cvstats
|
from .cvstats import Cvstats
|
||||||
|
from .treasure import Treasure
|
||||||
|
|
||||||
# Enter the tables of your Pack here!
|
# Enter the tables of your Pack here!
|
||||||
available_tables = [
|
available_tables = [
|
||||||
|
@ -38,6 +39,7 @@ available_tables = [
|
||||||
MMEvent,
|
MMEvent,
|
||||||
MMResponse,
|
MMResponse,
|
||||||
Cvstats,
|
Cvstats,
|
||||||
|
Treasure,
|
||||||
]
|
]
|
||||||
|
|
||||||
# Don't change this, it should automatically generate __all__
|
# Don't change this, it should automatically generate __all__
|
||||||
|
|
23
royalpack/tables/treasure.py
Normal file
23
royalpack/tables/treasure.py
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
from sqlalchemy import *
|
||||||
|
from sqlalchemy.orm import *
|
||||||
|
from sqlalchemy.ext.declarative import declared_attr
|
||||||
|
|
||||||
|
|
||||||
|
class Treasure:
|
||||||
|
__tablename__ = "treasures"
|
||||||
|
|
||||||
|
@declared_attr
|
||||||
|
def code(self):
|
||||||
|
return Column(String, primary_key=True)
|
||||||
|
|
||||||
|
@declared_attr
|
||||||
|
def redeemed_by_id(self):
|
||||||
|
return Column(Integer, ForeignKey("users.uid"))
|
||||||
|
|
||||||
|
@declared_attr
|
||||||
|
def redeemed_by(self):
|
||||||
|
return relationship("User")
|
||||||
|
|
||||||
|
@declared_attr
|
||||||
|
def value(self):
|
||||||
|
return Column(Integer, nullable=False)
|
Loading…
Reference in a new issue