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

Improve fiorygi (5.3.6)

This commit is contained in:
Steffo 2020-01-31 01:47:44 +01:00
parent c450d5e283
commit ea847631ac
7 changed files with 103 additions and 3 deletions

View file

@ -2,7 +2,7 @@
[tool.poetry] [tool.poetry]
name = "royalpack" name = "royalpack"
version = "5.3.5" version = "5.3.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

@ -34,6 +34,7 @@ from .trivia import TriviaCommand
from .steampowered import SteampoweredCommand from .steampowered import SteampoweredCommand
from .steammatch import SteammatchCommand from .steammatch import SteammatchCommand
from .dota import DotaCommand from .dota import DotaCommand
from .magickfiorygi import MagickfiorygiCommand
# Enter the commands of your Pack here! # Enter the commands of your Pack here!
available_commands = [ available_commands = [
@ -72,6 +73,7 @@ available_commands = [
SteampoweredCommand, SteampoweredCommand,
SteammatchCommand, SteammatchCommand,
DotaCommand, DotaCommand,
MagickfiorygiCommand,
] ]
# Don't change this, it should automatically generate __all__ # Don't change this, it should automatically generate __all__

View file

@ -0,0 +1,66 @@
from typing import *
import royalnet
import royalnet.commands as rc
import royalnet.serf.telegram as rt
from ..tables import Alias, Fiorygi, FiorygiTransaction
class MagickfiorygiCommand(rc.Command):
name: str = "magickfiorygi"
description: str = "Crea fiorygi dal nulla."
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)
if author.role != "Admin":
raise rc.UserError("Non hai permessi sufficienti per eseguire questo comando.")
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 = Alias.find_by_alias(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à non può essere 0!")
if reason_arg == "":
raise rc.InvalidInputError("Non hai specificato un motivo!")
transaction = self.alchemy.get(FiorygiTransaction)(
user_id=user.uid,
change=qty,
reason=reason_arg
)
data.session.add(transaction)
user.fiorygi.fiorygi += qty
await data.session_commit()
if len(user.telegram) > 0:
user_str = user.telegram[0].mention()
else:
user_str = user.username
if qty > 0:
msg = f"💰 [b]{user_str}[/b] ha ottenuto [b]{qty}[/b] fioryg{'i' if qty != 1 else ''} per [i]{reason_arg}[/i]!"
else:
msg = f"💸 [b]{user_str}[/b] ha perso [b]{-qty}[/b] fioryg{'i' if qty != -1 else ''} per [i]{reason_arg}[/i]."
client = self.serf.client
await self.serf.api_call(client.send_message,
chat_id=self.config["Telegram"]["main_group_id"],
text=rt.escape(msg),
parse_mode="HTML",
disable_webpage_preview=True)

View file

@ -12,6 +12,7 @@ from .leagueoflegends import LeagueOfLegends
from .fiorygi import Fiorygi from .fiorygi import Fiorygi
from .steam import Steam from .steam import Steam
from .dota import Dota from .dota import Dota
from .fiorygitransactions import FiorygiTransaction
# Enter the tables of your Pack here! # Enter the tables of your Pack here!
available_tables = [ available_tables = [
@ -28,6 +29,7 @@ available_tables = [
Fiorygi, Fiorygi,
Steam, Steam,
Dota, Dota,
FiorygiTransaction,
] ]
# Don't change this, it should automatically generate __all__ # Don't change this, it should automatically generate __all__

View file

@ -19,7 +19,7 @@ class Fiorygi:
return Column(Integer, nullable=False, default=0) return Column(Integer, nullable=False, default=0)
def __repr__(self): def __repr__(self):
return f"<Fiorygi di {self.royal}: {self.fiorygi}>" return f"<{self.__class__.__name__} di {self.user}: {self.fiorygi}>"
def __str__(self): def __str__(self):
return f"{self.fiorygi} fioryg" + ("i" if self.fiorygi != 1 else "") return f"{self.fiorygi} fioryg" + ("i" if self.fiorygi != 1 else "")

View file

@ -0,0 +1,30 @@
from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declared_attr
class FiorygiTransaction:
__tablename__ = "fiorygitransactions"
@declared_attr
def id(self):
return Column(Integer, primary_key=True)
@declared_attr
def change(self):
return Column(Integer, nullable=False)
@declared_attr
def user_id(self):
return Column(Integer, ForeignKey("fiorygi.user_id"), nullable=False)
@declared_attr
def user(self):
return relationship("Fiorygi", backref=backref("transactions"))
@declared_attr
def reason(self):
return Column(String, nullable=False, default="")
def __repr__(self):
return f"<{self.__class__.__name__}: {self.change:+} to {self.user.username} for {self.reason}>"

View file

@ -1 +1 @@
semantic = "5.3.5" semantic = "5.3.6"