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

publish: 5.8.6

This commit is contained in:
Steffo 2020-05-21 18:56:20 +02:00
parent 0c5ab3c1d8
commit 78b435ccb1
Signed by: steffo
GPG key ID: 896A80F55F7C97F0
5 changed files with 65 additions and 18 deletions

View file

@ -2,7 +2,7 @@
[tool.poetry] [tool.poetry]
name = "royalpack" name = "royalpack"
version = "5.8.5" version = "5.8.6"
description = "A Royalnet command pack for the Royal Games community" description = "A Royalnet command pack for the Royal Games community"
authors = ["Stefano Pigozzi <ste.pigozzi@gmail.com>"] authors = ["Stefano Pigozzi <ste.pigozzi@gmail.com>"]
license = "AGPL-3.0+" license = "AGPL-3.0+"

View file

@ -57,7 +57,7 @@ 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 .magicktreasure import CreatetreasureCommand
from .treasure import TreasureCommand from .treasure import TreasureCommand
# Enter the commands of your Pack here! # Enter the commands of your Pack here!

View file

@ -0,0 +1,37 @@
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}"
async def _permission_check(self, author, code, value, data):
if "banker" not in author.roles:
raise rc.UserError("Non hai permessi sufficienti per eseguire questo comando.")
if author.fiorygi.fiorygi < value:
raise rc.UserError("Non hai abbastanza fiorygi per creare questo Treasure.")
async def _create_treasure(self, author, code, value, data):
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
)
await FiorygiTransaction.spawn_fiorygi(data, author, -value, "aver creato un tesoro")
return treasure

View file

@ -5,26 +5,19 @@ import royalnet.utils as ru
from ..tables import Treasure from ..tables import Treasure
class CreatetreasureCommand(rc.Command): class MagicktreasureCommand(rc.Command):
name: str = "createtreasure" name: str = "magicktreasure"
description: str = "Crea un nuovo tesoro di Fiorygi." description: str = "Crea un nuovo Treasure di Fiorygi (senza spendere i tuoi)."
syntax: str = "{codice} {valore}" syntax: str = "{codice} {valore}"
async def run(self, args: rc.CommandArgs, data: rc.CommandData) -> None: async def _permission_check(self, author, code, value, data):
author = await data.get_author(error_if_none=True)
if "banker" not in author.roles: if "banker" not in author.roles:
raise rc.UserError("Non hai permessi sufficienti per eseguire questo comando.") raise rc.UserError("Non hai permessi sufficienti per eseguire questo comando.")
return author
code = args[0] async def _create_treasure(self, author, code, value, data):
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) TreasureT = self.alchemy.get(Treasure)
treasure = await ru.asyncify(data.session.query(TreasureT).get, code) treasure = await ru.asyncify(data.session.query(TreasureT).get, code)
@ -36,8 +29,25 @@ class CreatetreasureCommand(rc.Command):
value=value, value=value,
redeemed_by=None redeemed_by=None
) )
return treasure
async def run(self, args: rc.CommandArgs, data: rc.CommandData) -> None:
await data.delete_invoking()
author = await data.get_author(error_if_none=True)
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.")
await self._permission_check(author, code, value, data)
treasure = await self._create_treasure(author, code, value, data)
data.session.add(treasure) data.session.add(treasure)
await data.session_commit() await data.session_commit()
await data.delete_invoking() await data.reply("✅ Treasure creato!")
await data.reply("✅ Tesoro creato!")

View file

@ -1 +1 @@
semantic = "5.8.5" semantic = "5.8.6"