diff --git a/royalnet/commands/royalgames/old/author.py b/royalnet/commands/royalgames/old/author.py deleted file mode 100644 index f4e8fd07..00000000 --- a/royalnet/commands/royalgames/old/author.py +++ /dev/null @@ -1,19 +0,0 @@ -from ..utils import Command, Call -from ..database.tables import Royal, Telegram, Discord - - -class AuthorCommand(Command): - - command_name = "author" - command_description = "Ottieni informazioni sull'autore di questa chiamata." - command_syntax = "" - - require_alchemy_tables = {Royal, Telegram, Discord} - - @classmethod - async def common(cls, call: Call): - author = await call.get_author() - if author is None: - await call.reply(f"☁️ L'autore di questa chiamata è sconosciuto.") - return - await call.reply(f"🌞 {str(author)} è l'autore di questa chiamata.") diff --git a/royalnet/commands/royalgames/old/dateparser.py b/royalnet/commands/royalgames/old/dateparser.py deleted file mode 100644 index 22a94aa8..00000000 --- a/royalnet/commands/royalgames/old/dateparser.py +++ /dev/null @@ -1,19 +0,0 @@ -import datetime -import dateparser -from ..utils import Command, Call - - -class DateparserCommand(Command): - - command_name = "dateparser" - command_description = "Legge e comprende la data inserita." - command_syntax = "(data)" - - @classmethod - async def common(cls, call: Call): - text = call.args.joined(require_at_least=1) - date: datetime.datetime = dateparser.parse(text) - if date is None: - await call.reply("🕕 La data inserita non è valida.") - return - await call.reply(f"🕐 La data inserita è {date.strftime('%Y-%m-%d %H:%M:%S')}") diff --git a/royalnet/commands/royalgames/old/debug_create.py b/royalnet/commands/royalgames/old/debug_create.py deleted file mode 100644 index 3b06e7c1..00000000 --- a/royalnet/commands/royalgames/old/debug_create.py +++ /dev/null @@ -1,20 +0,0 @@ -from ..utils import Command, Call, asyncify -from ..database.tables import Royal, Alias - - -class DebugCreateCommand(Command): - - command_name = "debug_create" - command_description = "Crea un nuovo account Royalnet" - command_syntax = "(newusername)" - - require_alchemy_tables = {Royal, Alias} - - @classmethod - async def common(cls, call: Call): - royal = call.alchemy.Royal(username=call.args[0], role="Member") - call.session.add(royal) - alias = call.alchemy.Alias(royal=royal, alias=royal.username.lower()) - call.session.add(alias) - await asyncify(call.session.commit) - await call.reply(f"✅ Utente {royal} creato!") diff --git a/royalnet/commands/royalgames/old/error_handler.py b/royalnet/commands/royalgames/old/error_handler.py deleted file mode 100644 index 0fbe2b1c..00000000 --- a/royalnet/commands/royalgames/old/error_handler.py +++ /dev/null @@ -1,55 +0,0 @@ -import logging as _logging -from ..utils import Command, Call -from ..error import * - -log = _logging.getLogger(__name__) - - -class ErrorHandlerCommand(Command): - - command_name = "error_handler" - command_description = "Gestisce gli errori causati dagli altri comandi." - command_syntax = "" - - @classmethod - async def common(cls, call: Call): - exception: Exception = call.kwargs["exception"] - if isinstance(exception, NoneFoundError): - await call.reply(f"⚠️ L'elemento richiesto non è stato trovato.\n[p]{exception}[/p]") - return - elif isinstance(exception, TooManyFoundError): - await call.reply(f"⚠️ La richiesta effettuata è ambigua, pertanto è stata annullata.\n[p]{exception}[/p]") - return - elif isinstance(exception, UnregisteredError): - await call.reply("⚠️ Devi essere registrato a Royalnet per usare questo comando.\nUsa il comando [c]sync[/c] per registrarti!") - return - elif isinstance(exception, UnsupportedError): - await call.reply(f"⚠️ Il comando richiesto non è disponibile tramite l'interfaccia [c]{call.interface_name}[/c].") - return - elif isinstance(exception, InvalidInputError): - command = call.kwargs["previous_command"] - await call.reply(f"⚠️ Sintassi non valida.\nSintassi corretta: [c]{call.interface_prefix}{command.command_name} {command.command_syntax}[/c]") - return - elif isinstance(exception, InvalidConfigError): - await call.reply(f"⚠️ Il bot non è stato configurato correttamente, quindi questo comando non può essere eseguito.\n[p]{exception}[/p]") - return - elif isinstance(exception, RoyalnetRequestError): - await call.reply(f"⚠️ La richiesta a Royalnet ha restituito un errore:\n" - f"[p]{exception.error.extra_info['type']}\n" - f"{exception.error.extra_info['str']}[/p]") - return - elif isinstance(exception, ExternalError): - await call.reply(f"⚠️ Una risorsa esterna necessaria per l'esecuzione del comando non ha funzionato correttamente, quindi il comando è stato annullato.\n[p]{exception}[/p]") - return - elif isinstance(exception, RoyalnetResponseError): - log.warning(f"Invalid response from Royalnet - {exception.__class__.__name__}: {exception}") - await call.reply(f"❌ La risposta ricevuta da Royalnet non è valida: [p]{exception}[/p]") - return - elif isinstance(exception, CurrentlyDisabledError): - await call.reply(f"⚠️ Il comando richiesto è temporaneamente disabilitato.\n[p]{exception}[/p]") - return - elif __debug__: - raise - else: - log.error(f"Unhandled exception - {exception.__class__.__name__}: {exception}") - await call.reply(f"❌ Eccezione non gestita durante l'esecuzione del comando:\n[b]{exception.__class__.__name__}[/b]\n[p]{exception}[/p]") diff --git a/royalnet/commands/royalgames/old/id.py b/royalnet/commands/royalgames/old/id.py deleted file mode 100644 index c41fb331..00000000 --- a/royalnet/commands/royalgames/old/id.py +++ /dev/null @@ -1,26 +0,0 @@ -import telegram -import discord -import typing -from ..utils import Command, Call - - -class IdCommand(Command): - - command_name = "id" - command_description = "Visualizza l'id della chat attuale." - command_syntax = "" - - @classmethod - async def telegram(cls, call: Call): - chat: telegram.Chat = call.channel - await call.reply(f"🔢 L'id di questa chat è [b]{chat.id}[/b].") - - @classmethod - async def discord(cls, call: Call): - channel = call.channel - if isinstance(channel, discord.TextChannel): - await call.reply(f"🔢 L'id di questa chat è [b]{channel.id}[/b].") - elif isinstance(channel, discord.DMChannel): - await call.reply(f"🔢 L'id di questa chat è [b]{channel.id}[/b].") - else: - await call.reply(f"⚠️ Questo tipo di chat non è supportato.") diff --git a/royalnet/commands/royalgames/old/kv.py b/royalnet/commands/royalgames/old/kv.py deleted file mode 100644 index a006b876..00000000 --- a/royalnet/commands/royalgames/old/kv.py +++ /dev/null @@ -1,37 +0,0 @@ -from ..database.tables import ActiveKvGroup, Royal, Keyvalue, Keygroup -from ..utils import Command, Call, asyncify - - -class KvCommand(Command): - - command_name = "kv" - command_description = "Visualizza o modifica un valore kv." - command_syntax = "(chiave) [valore]" - - require_alchemy_tables = {ActiveKvGroup, Royal, Keyvalue, Keygroup} - - @classmethod - async def common(cls, call: Call): - key = call.args[0].lower() - value = call.args.optional(1) - author = await call.get_author(error_if_none=True) - active = await asyncify(call.session.query(call.alchemy.ActiveKvGroup).filter_by(royal=author).one_or_none) - if active is None: - await call.reply("⚠️ Devi prima attivare un gruppo con il comando [c]kvactive[/c]!") - return - keyvalue = await asyncify(call.session.query(call.alchemy.Keyvalue).filter_by(group=active.group, key=key).one_or_none) - if value is None: - # Get - if keyvalue is None: - await call.reply("⚠️ La chiave specificata non esiste.") - return - await call.reply(f"ℹ️ Valore della chiave:\n{keyvalue}") - else: - # Set/kv asdf 1000 - if keyvalue is None: - keyvalue = call.alchemy.Keyvalue(group=active.group, key=key, value=value) - call.session.add(keyvalue) - else: - keyvalue.value = value - await asyncify(call.session.commit) - await call.reply(f"✅ Chiave aggiornata:\n{keyvalue}") diff --git a/royalnet/commands/royalgames/old/kvactive.py b/royalnet/commands/royalgames/old/kvactive.py deleted file mode 100644 index a9f7227b..00000000 --- a/royalnet/commands/royalgames/old/kvactive.py +++ /dev/null @@ -1,32 +0,0 @@ -from ..database.tables import ActiveKvGroup, Royal, Keygroup -from ..utils import Command, Call, asyncify - - -class KvactiveCommand(Command): - - command_name = "kvactive" - command_description = "Seleziona un gruppo di valori kv." - command_syntax = "(nomegruppo)" - - require_alchemy_tables = {ActiveKvGroup, Royal, Keygroup} - - @classmethod - async def common(cls, call: Call): - group_name = call.args[0].lower() - author = await call.get_author(error_if_none=True) - active = await asyncify(call.session.query(call.alchemy.ActiveKvGroup).filter_by(royal=author).one_or_none) - if active is None: - group = await asyncify(call.session.query(call.alchemy.Keygroup).filter_by(group_name=group_name).one_or_none) - if group is None: - group = call.alchemy.Keygroup(group_name=group_name) - call.session.add(group) - active = call.alchemy.ActiveKvGroup(royal=author, group=group) - call.session.add(active) - else: - group = await asyncify(call.session.query(call.alchemy.Keygroup).filter_by(group_name=group_name).one_or_none) - if group is None: - group = call.alchemy.Keygroup(group_name=group_name) - call.session.add(group) - active.group = group - await asyncify(call.session.commit) - await call.reply(f"✅ Hai attivato il gruppo [b]{group_name}[/b].") diff --git a/royalnet/commands/royalgames/old/kvroll.py b/royalnet/commands/royalgames/old/kvroll.py deleted file mode 100644 index 9b95a31b..00000000 --- a/royalnet/commands/royalgames/old/kvroll.py +++ /dev/null @@ -1,39 +0,0 @@ -import random -from ..database.tables import ActiveKvGroup, Royal, Keygroup, Keyvalue -from ..utils import Command, Call, asyncify, plusformat - - -class KvrollCommand(Command): - - command_name = "kvroll" - command_description = "Lancia 1d20, poi aggiungici il valore della kv selezionata." - command_syntax = "(chiave) [modifier]" - - require_alchemy_tables = {ActiveKvGroup, Royal, Keyvalue, Keygroup} - - @classmethod - async def common(cls, call: Call): - key = call.args[0].lower() - normal_mod_str = call.args.optional(1, 0) - try: - normal_modifier = int(normal_mod_str) - except ValueError: - await call.reply("⚠️ Il modificatore specificato non è un numero.") - return - author = await call.get_author(error_if_none=True) - active = await asyncify(call.session.query(call.alchemy.ActiveKvGroup).filter_by(royal=author).one_or_none) - if active is None: - await call.reply("⚠️ Devi prima attivare un gruppo con il comando [c]kvactive[/c]!") - return - keyvalue = await asyncify(call.session.query(call.alchemy.Keyvalue).filter_by(group=active.group, key=key).one_or_none) - if keyvalue is None: - await call.reply("⚠️ La chiave specificata non esiste.") - return - try: - kv_modifier = int(keyvalue.value) - except ValueError: - await call.reply("⚠️ Il valore della chiave specificata non è un numero.") - return - roll = random.randrange(1, 21) - result = roll + kv_modifier + normal_modifier - await call.reply(f"🎲 {roll}{plusformat(kv_modifier)}{plusformat(normal_modifier)} = [b]{result}[/b]") diff --git a/royalnet/commands/royalgames/old/missing.py b/royalnet/commands/royalgames/old/missing.py deleted file mode 100644 index 6a5670fd..00000000 --- a/royalnet/commands/royalgames/old/missing.py +++ /dev/null @@ -1,17 +0,0 @@ -import asyncio -import logging as _logging -from ..utils import Command, Call - - -log = _logging.getLogger(__name__) - - -class MissingCommand(Command): - - command_name = "missing" - command_description = "Informa che il comando non esiste." - command_syntax = "" - - @classmethod - async def common(cls, call: Call): - await call.reply(f"⚠️ Il comando richiesto non esiste.") diff --git a/royalnet/commands/royalgames/old/null.py b/royalnet/commands/royalgames/old/null.py deleted file mode 100644 index f30db9fb..00000000 --- a/royalnet/commands/royalgames/old/null.py +++ /dev/null @@ -1,12 +0,0 @@ -from ..utils import Command, Call - - -class NullCommand(Command): - - command_name = "null" - command_description = "Non fa nulla." - command_syntax = "" - - @classmethod - async def common(cls, call: Call): - pass diff --git a/royalnet/commands/royalgames/old/reminder.py b/royalnet/commands/royalgames/old/reminder.py deleted file mode 100644 index cd2a7232..00000000 --- a/royalnet/commands/royalgames/old/reminder.py +++ /dev/null @@ -1,25 +0,0 @@ -import datetime -import dateparser -import typing -from ..utils import Command, Call, sleep_until - - -class ReminderCommand(Command): - - command_name = "reminder" - command_description = "Ripete quello che gli avevi chiesto dopo un po' di tempo." - command_syntax = "[ (data) ] (testo)" - - @classmethod - async def common(cls, call: Call): - date_str, reminder_text = call.args.match(r"\[ *(.+?) *] *(.+?) *$") - try: - date: typing.Optional[datetime.datetime] = dateparser.parse(date_str) - except OverflowError: - date = None - if date is None: - await call.reply("⚠️ La data che hai inserito non è valida.") - return - await call.reply(f"✅ Promemoria impostato per [b]{date.strftime('%Y-%m-%d %H:%M:%S')}[/b]") - await sleep_until(date) - await call.reply(f"❗️ Promemoria: [b]{reminder_text}[/b]") diff --git a/royalnet/commands/royalgames/old/royalnetprofile.py b/royalnet/commands/royalgames/old/royalnetprofile.py deleted file mode 100644 index 8e2f59d9..00000000 --- a/royalnet/commands/royalgames/old/royalnetprofile.py +++ /dev/null @@ -1,20 +0,0 @@ -import asyncio -from ..utils import Command, Call -from ..database.tables import Royal, Telegram, Discord - - -class RoyalnetprofileCommand(Command): - - command_name = "royalnetprofile" - command_description = "Invia in chat il link al tuo profilo Royalnet!" - command_syntax = "" - - require_alchemy_tables = {Royal, Telegram, Discord} - - @classmethod - async def common(cls, call: Call): - author = await call.get_author(error_if_none=True) - if author is None: - await call.reply("⚠️ Devi essere registrato a Royalnet per usare questo comando!") - return - await call.reply(f"🔗 https://ryg.steffo.eu/profile/{author.username}") diff --git a/royalnet/commands/royalgames/old/sync.py b/royalnet/commands/royalgames/old/sync.py deleted file mode 100644 index 8e19a4dd..00000000 --- a/royalnet/commands/royalgames/old/sync.py +++ /dev/null @@ -1,81 +0,0 @@ -import typing -from telegram import Update, User -from discord import Message, Member -from ..utils import Command, Call, asyncify -from ..error import UnsupportedError -from ..database.tables import Royal, Telegram, Discord - - -class SyncCommand(Command): - - command_name = "sync" - command_description = "Connetti il tuo account attuale a Royalnet!" - command_syntax = "(royalnetusername)" - - require_alchemy_tables = {Royal, Telegram, Discord} - - @classmethod - async def common(cls, call: Call): - raise UnsupportedError() - - @classmethod - async def telegram(cls, call: Call): - update: Update = call.kwargs["update"] - # Find the user - user: typing.Optional[User] = update.effective_user - if user is None: - raise ValueError("Trying to sync a None user.") - # Find the Royal - royal = await asyncify(call.session.query(call.alchemy.Royal).filter_by(username=call.args[0]).one_or_none) - if royal is None: - await call.reply("⚠️ Non esiste alcun account Royalnet con quel nome. Ricorda, gli username sono [b]case-sensitive[/b]!") - return - # Find if the user is already synced - telegram = await asyncify(call.session.query(call.alchemy.Telegram).filter_by(tg_id=user.id).one_or_none) - if telegram is None: - # Create a Telegram to connect to the Royal - # Avatar is WIP - telegram = call.alchemy.Telegram(royal=royal, - tg_id=user.id, - first_name=user.first_name, - last_name=user.last_name, - username=user.username) - call.session.add(telegram) - await call.reply(f"✅ Connessione completata: {str(royal)} ⬌ {str(telegram)}") - else: - # Update the Telegram data - telegram.first_name = user.first_name - telegram.last_name = user.last_name - telegram.username = user.username - await call.reply(f"✅ Connessione aggiornata: {str(royal)} ⬌ {str(telegram)}") - # Commit the session - await asyncify(call.session.commit) - - @classmethod - async def discord(cls, call: Call): - message: Message = call.kwargs["message"] - user: typing.Optional[Member] = message.author - # Find the Royal - royal = await asyncify(call.session.query(call.alchemy.Royal).filter_by(username=call.args[0]).one_or_none) - if royal is None: - await call.reply("⚠️ Non esiste alcun account Royalnet con quel nome. Ricorda, gli username sono [b]case-sensitive[/b]!") - return - # Find if the user is already synced - discord = await asyncify(call.session.query(call.alchemy.Discord).filter_by(discord_id=user.id).one_or_none) - if discord is None: - # Create a Discord to connect to the Royal - discord = call.alchemy.Discord(royal=royal, - discord_id=user.id, - username=user.name, - discriminator=user.discriminator, - avatar_hash=user.avatar) - call.session.add(discord) - await call.reply(f"✅ Connessione completata: {str(royal)} ⬌ {str(discord)}") - else: - # Update the Discord data - discord.username = user.name - discord.discriminator = user.discriminator - discord.avatar_hash = user.avatar - await call.reply(f"✅ Connessione aggiornata: {str(royal)} ⬌ {str(discord)}") - # Commit the session - await asyncify(call.session.commit) diff --git a/royalnet/commands/royalgames/old/videoinfo.py b/royalnet/commands/royalgames/old/videoinfo.py deleted file mode 100644 index 37929d7d..00000000 --- a/royalnet/commands/royalgames/old/videoinfo.py +++ /dev/null @@ -1,36 +0,0 @@ -import asyncio -from ..utils import Command, Call, asyncify -from ..audio import YtdlInfo - - -class VideoinfoCommand(Command): - - command_name = "videoinfo" - command_description = "Visualizza le informazioni di un video." - command_syntax = "(url)" - - @classmethod - async def common(cls, call: Call): - url = call.args[0] - info_list = await asyncify(YtdlInfo.retrieve_for_url, url) - for info in info_list: - info_dict = info.__dict__ - message = f"🔍 Dati di [b]{info}[/b]:\n" - for key in info_dict: - # Skip description - if key == "description": - continue - # Skip formats - if key == "formats": - continue - if key == "requested_formats": - continue - # Skip subtitles - if key == "subtitles": - continue - # Skip empty keys - if info_dict[key] is None: - continue - message += f"[c]{key}[/c]: {info_dict[key]}\n" - await call.reply(message) - await asyncio.sleep(0.2)