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

Aggiungi nuovi comandi

This commit is contained in:
Steffo 2020-05-14 00:11:48 +02:00
parent 2378cbb662
commit d05c2cd988
Signed by: steffo
GPG key ID: 896A80F55F7C97F0
6 changed files with 80 additions and 5 deletions

View file

@ -54,6 +54,8 @@ from .matchmaking import MatchmakingCommand
from .cvstats import CvstatsCommand from .cvstats import CvstatsCommand
from .elevatormusic import ElevatormusicCommand from .elevatormusic import ElevatormusicCommand
from .royalpack import RoyalpackCommand from .royalpack import RoyalpackCommand
from .givefiorygi import GivefiorygiCommand
from .help import HelpCommand
# Enter the commands of your Pack here! # Enter the commands of your Pack here!
available_commands = [ available_commands = [
@ -112,6 +114,8 @@ available_commands = [
CvstatsCommand, CvstatsCommand,
ElevatormusicCommand, ElevatormusicCommand,
RoyalpackCommand, RoyalpackCommand,
GivefiorygiCommand,
HelpCommand,
] ]
# Don't change this, it should automatically generate __all__ # Don't change this, it should automatically generate __all__

View file

@ -6,7 +6,7 @@ from royalnet.commands import *
class CiaoruoziCommand(Command): class CiaoruoziCommand(Command):
name: str = "ciaoruozi" name: str = "ciaoruozi"
description: str = "Saluta Ruozi, un leggendario essere che una volta era in User Games." description: str = "Saluta Ruozi, un leggendario essere che è tornato in Royal Games."
async def run(self, args: CommandArgs, data: CommandData) -> None: async def run(self, args: CommandArgs, data: CommandData) -> None:
if self.interface.name == "telegram": if self.interface.name == "telegram":

View file

@ -0,0 +1,44 @@
from typing import *
import royalnet.commands as rc
import royalnet.backpack.tables as rbt
from ..tables import FiorygiTransaction
class GivefiorygiCommand(rc.Command):
name: str = "givefiorygi"
description: str = "Cedi fiorygi a un altro utente."
syntax: str = "{destinatario} {quantità} {motivo}"
async def run(self, args: rc.CommandArgs, data: rc.CommandData) -> None:
author = await data.get_author(error_if_none=True)
user_arg = args[0]
qty_arg = args[1]
reason_arg = " ".join(args[2:])
if user_arg is None:
raise rc.InvalidInputError("Non hai specificato un destinatario!")
user = await rbt.User.find(self.alchemy, data.session, user_arg)
if user is None:
raise rc.InvalidInputError("L'utente specificato non esiste!")
if qty_arg is None:
raise rc.InvalidInputError("Non hai specificato una quantità!")
try:
qty = int(qty_arg)
except ValueError:
raise rc.InvalidInputError("La quantità specificata non è un numero!")
if qty <= 0:
raise rc.InvalidInputError("La quantità specificata deve essere almeno 1!")
if reason_arg == "":
raise rc.InvalidInputError("Non hai specificato un motivo!")
if author.fiorygi.fiorygi < qty:
raise rc.InvalidInputError("Non hai abbastanza fiorygi per effettuare la transazione!")
await FiorygiTransaction.spawn_fiorygi(data, author, -qty, reason_arg)
await FiorygiTransaction.spawn_fiorygi(data, user, qty, reason_arg)

View file

@ -0,0 +1,27 @@
from typing import *
import royalnet
import royalnet.commands as rc
class HelpCommand(rc.Command):
name: str = "help"
description: str = "Visualizza informazioni su un comando."
syntax: str = "{comando}"
async def run(self, args: rc.CommandArgs, data: rc.CommandData) -> None:
name: str = args[0].lstrip(self.interface.prefix)
try:
command: rc.Command = self.serf.commands[f"{self.interface.prefix}{name}"]
except KeyError:
raise rc.InvalidInputError("Il comando richiesto non esiste.")
message = [
f"[c]{self.interface.prefix}{command.name} {command.syntax}[/c]",
"",
f"{command.description}"
]
await data.reply("\n".join(message))

View file

@ -14,7 +14,7 @@ class MagickfiorygiCommand(rc.Command):
async def run(self, args: rc.CommandArgs, data: rc.CommandData) -> None: async def run(self, args: rc.CommandArgs, data: rc.CommandData) -> None:
author = await data.get_author(error_if_none=True) author = await data.get_author(error_if_none=True)
if author.role != "Admin": 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.")
user_arg = args[0] user_arg = args[0]
@ -23,7 +23,7 @@ class MagickfiorygiCommand(rc.Command):
if user_arg is None: if user_arg is None:
raise rc.InvalidInputError("Non hai specificato un destinatario!") raise rc.InvalidInputError("Non hai specificato un destinatario!")
user = await rbt.Alias.find_user(self.alchemy, data.session, user_arg) user = await rbt.User.find(self.alchemy, data.session, user_arg)
if user is None: if user is None:
raise rc.InvalidInputError("L'utente specificato non esiste!") raise rc.InvalidInputError("L'utente specificato non esiste!")

View file

@ -110,10 +110,10 @@ class MatchmakingCommand(rc.Command):
if response.choice == MMChoice.LATE_SHORT: if response.choice == MMChoice.LATE_SHORT:
td = mmevent.datetime + datetime.timedelta(minutes=10) td = mmevent.datetime + datetime.timedelta(minutes=10)
time_text = f" [{td.strftime('%H:%M')}]" time_text = f" [{td.strftime('%H:%M')}]"
elif response.choice == MMChoice.LATE_SHORT: elif response.choice == MMChoice.LATE_MEDIUM:
td = mmevent.datetime + datetime.timedelta(minutes=30) td = mmevent.datetime + datetime.timedelta(minutes=30)
time_text = f" [{td.strftime('%H:%M')}]" time_text = f" [{td.strftime('%H:%M')}]"
elif response.choice == MMChoice.LATE_SHORT: elif response.choice == MMChoice.LATE_LONG:
td = mmevent.datetime + datetime.timedelta(minutes=60) td = mmevent.datetime + datetime.timedelta(minutes=60)
time_text = f" [{td.strftime('%H:%M')}+]" time_text = f" [{td.strftime('%H:%M')}+]"
else: else: