diff --git a/royalnet/bots/generic.py b/royalnet/bots/generic.py index 2c6163a2..10f2b77f 100644 --- a/royalnet/bots/generic.py +++ b/royalnet/bots/generic.py @@ -24,19 +24,30 @@ class GenericBot: def _init_commands(self) -> None: """Generate the ``commands`` dictionary required to handle incoming messages, and the ``network_handlers`` dictionary required to handle incoming requests. """ - log.debug(f"Now binding commands") + log.info(f"Registering commands...") self._Interface = self._interface_factory() self._Data = self._data_factory() self.commands = {} self.network_handlers: typing.Dict[str, typing.Type[NetworkHandler]] = {} for SelectedCommand in self.uninitialized_commands: - log.debug(f"Binding {SelectedCommand.name}...") interface = self._Interface() try: - self.commands[f"{interface.prefix}{SelectedCommand.name}"] = SelectedCommand(interface) + command = SelectedCommand(interface) except Exception as e: - log.error(f"{e.__class__.__name__} during the initialization of {SelectedCommand.name}, skipping...") - log.debug(f"Successfully bound commands") + log.error(f"{e.__class__.__qualname__} during the registration of {SelectedCommand.__qualname__}") + # Override the main command name, but warn if it's overriding something + if f"{interface.prefix}{SelectedCommand.name}" in self.commands: + log.warning(f"Overriding (already defined): {SelectedCommand.__qualname__} -> {interface.prefix}{SelectedCommand.name}") + else: + log.debug(f"Registering: {SelectedCommand.__qualname__} -> {interface.prefix}{SelectedCommand.name}") + self.commands[f"{interface.prefix}{SelectedCommand.name}"] = command + # Register aliases, but don't override anything + for alias in SelectedCommand.aliases: + if f"{interface.prefix}{alias}" not in self.commands: + log.debug(f"Aliasing: {SelectedCommand.__qualname__} -> {interface.prefix}{alias}") + self.commands[f"{interface.prefix}{alias}"] = self.commands[f"{interface.prefix}{SelectedCommand.name}"] + else: + log.info(f"Ignoring (already defined): {SelectedCommand.__qualname__} -> {interface.prefix}{alias}") def _interface_factory(self) -> typing.Type[CommandInterface]: # noinspection PyAbstractClass,PyMethodParameters @@ -121,20 +132,23 @@ class GenericBot: """Create an :py:class:`royalnet.database.Alchemy` with the tables required by the commands. Then, find the chain that links the ``master_table`` to the ``identity_table``. """ if self.uninitialized_database_config: - log.debug(f"Initializing database") + log.info(f"Database: enabled") required_tables = {self.uninitialized_database_config.master_table, self.uninitialized_database_config.identity_table} for command in self.uninitialized_commands: required_tables = required_tables.union(command.require_alchemy_tables) - log.debug(f"Found {len(required_tables)} required tables") + log.debug(f"Required tables: {', '.join([item.__qualname__ for item in required_tables])}") self.alchemy = Alchemy(self.uninitialized_database_config.database_uri, required_tables) self.master_table = self.alchemy.__getattribute__(self.uninitialized_database_config.master_table.__name__) + log.debug(f"Master table: {self.master_table.__qualname__}") self.identity_table = self.alchemy.__getattribute__(self.uninitialized_database_config.identity_table.__name__) + log.debug(f"Identity table: {self.identity_table.__qualname__}") self.identity_column = self.identity_table.__getattribute__(self.identity_table, self.uninitialized_database_config.identity_column_name) + log.debug(f"Identity column: {self.identity_column.__class__.__qualname__}") self.identity_chain = relationshiplinkchain(self.master_table, self.identity_table) - log.debug(f"Identity chain is {self.identity_chain}") + log.debug(f"Identity chain: {' -> '.join([str(item) for item in self.identity_chain])}") else: - log.debug(f"Database is not enabled, setting everything to None") + log.debug(f"Database: disabled") self.alchemy = None self.master_table = None self.identity_table = None @@ -142,13 +156,13 @@ class GenericBot: def _init_sentry(self): if self.uninitialized_sentry_dsn: - log.debug("Sentry integration enabled") + log.info("Sentry: enabled") self.sentry = sentry_sdk.init(self.uninitialized_sentry_dsn, integrations=[AioHttpIntegration(), SqlalchemyIntegration(), LoggingIntegration(event_level=None)]) else: - log.debug("Sentry integration disabled") + log.info("Sentry: disabled") def _init_loop(self): if self.uninitialized_loop is None: diff --git a/royalnet/commands/command.py b/royalnet/commands/command.py index 9b275787..23249109 100644 --- a/royalnet/commands/command.py +++ b/royalnet/commands/command.py @@ -10,7 +10,7 @@ class Command: """The main name of the command. To have ``/example`` on Telegram, the name should be ``example``.""" - aliases: typing.List[str] = NotImplemented + aliases: typing.List[str] = [] """A list of possible aliases for a command. To have ``/e`` as alias for ``/example``, one should set aliases to ``["e"]``.""" diff --git a/royalnet/commands/royalgames/dnditem.py b/royalnet/commands/royalgames/dnditem.py index 1ce43933..de3b7050 100644 --- a/royalnet/commands/royalgames/dnditem.py +++ b/royalnet/commands/royalgames/dnditem.py @@ -11,6 +11,8 @@ from ...utils import parse_5etools_entry class DnditemCommand(Command): name: str = "dnditem" + aliases = ["item"] + description: str = "Ottieni informazioni su un oggetto di D&D5e." syntax = "(nomeoggetto)" diff --git a/royalnet/commands/royalgames/dndspell.py b/royalnet/commands/royalgames/dndspell.py index cd5d9e73..63c7a992 100644 --- a/royalnet/commands/royalgames/dndspell.py +++ b/royalnet/commands/royalgames/dndspell.py @@ -11,6 +11,8 @@ from ...utils import parse_5etools_entry, ordinalformat, andformat class DndspellCommand(Command): name: str = "dndspell" + aliases = ["spell"] + description: str = "Ottieni informazioni su una magia di D&D5e." syntax = "(nomemagia)" diff --git a/royalnet/commands/royalgames/mm.py b/royalnet/commands/royalgames/mm.py index f3b130c2..379a2fb1 100644 --- a/royalnet/commands/royalgames/mm.py +++ b/royalnet/commands/royalgames/mm.py @@ -20,6 +20,8 @@ class MmCommand(Command): Requires the MM_CHANNEL_ID envvar to be set.""" name: str = "mm" + aliases = ["matchmaking", "matchmake"] + description: str = "Trova giocatori per una partita a qualcosa." syntax: str = "[ (data) ] (nomegioco)\n[descrizione]" diff --git a/royalnet/commands/royalgames/mp3.py b/royalnet/commands/royalgames/mp3.py index e3734e59..8532aa98 100644 --- a/royalnet/commands/royalgames/mp3.py +++ b/royalnet/commands/royalgames/mp3.py @@ -11,6 +11,8 @@ from ...audio import YtdlMp3 class Mp3Command(Command): name: str = "mp3" + aliases = ["dlmusic"] + description: str = "Scarica un video con youtube-dl e invialo in chat." syntax = "(ytdlstring)" diff --git a/royalnet/commands/royalgames/pause.py b/royalnet/commands/royalgames/pause.py index 00f42d29..55f5a5e4 100644 --- a/royalnet/commands/royalgames/pause.py +++ b/royalnet/commands/royalgames/pause.py @@ -6,7 +6,7 @@ from ..commandargs import CommandArgs from ..commanddata import CommandData from ...utils import NetworkHandler from ...network import Request, ResponseSuccess -from ...error import NoneFoundError +from ...error import NoneFoundError, TooManyFoundError if typing.TYPE_CHECKING: from ...bots import DiscordBot diff --git a/royalnet/commands/royalgames/play.py b/royalnet/commands/royalgames/play.py index a20d705a..f072e158 100644 --- a/royalnet/commands/royalgames/play.py +++ b/royalnet/commands/royalgames/play.py @@ -56,6 +56,8 @@ class PlayNH(NetworkHandler): class PlayCommand(Command): name: str = "play" + aliases = ["p"] + description: str = "Aggiunge una canzone alla coda della chat vocale." syntax = "[ [guild] ] (url)" diff --git a/royalnet/commands/royalgames/playmode.py b/royalnet/commands/royalgames/playmode.py index 989d7d95..18c84f09 100644 --- a/royalnet/commands/royalgames/playmode.py +++ b/royalnet/commands/royalgames/playmode.py @@ -45,6 +45,8 @@ class PlaymodeNH(NetworkHandler): class PlaymodeCommand(Command): name: str = "playmode" + aliases = ["pm", "mode"] + description: str = "Cambia modalità di riproduzione per la chat vocale." syntax = "[ [guild] ] (mode)" diff --git a/royalnet/commands/royalgames/queue.py b/royalnet/commands/royalgames/queue.py index 04865bad..052da55c 100644 --- a/royalnet/commands/royalgames/queue.py +++ b/royalnet/commands/royalgames/queue.py @@ -50,6 +50,8 @@ class QueueNH(NetworkHandler): class QueueCommand(Command): name: str = "queue" + aliases = ["q"] + description: str = "Visualizza la coda di riproduzione attuale." syntax = "[ [guild] ]" diff --git a/royalnet/commands/royalgames/rage.py b/royalnet/commands/royalgames/rage.py index 1112efa5..9a8c85cd 100644 --- a/royalnet/commands/royalgames/rage.py +++ b/royalnet/commands/royalgames/rage.py @@ -6,7 +6,9 @@ from ..commanddata import CommandData class RageCommand(Command): - name: str = "ship" + name: str = "rage" + + aliases = ["balurage", "madden"] description: str = "Arrabbiati per qualcosa, come una software house californiana." diff --git a/royalnet/commands/royalgames/reminder.py b/royalnet/commands/royalgames/reminder.py index c7148b13..04a87526 100644 --- a/royalnet/commands/royalgames/reminder.py +++ b/royalnet/commands/royalgames/reminder.py @@ -17,6 +17,8 @@ from ...error import * class ReminderCommand(Command): name: str = "reminder" + aliases = ["calendar"] + description: str = "Ti ricorda di fare qualcosa dopo un po' di tempo." syntax: str = "[ (data) ] (messaggio)" diff --git a/royalnet/commands/royalgames/ship.py b/royalnet/commands/royalgames/ship.py index 7fb354e1..5111ae5d 100644 --- a/royalnet/commands/royalgames/ship.py +++ b/royalnet/commands/royalgames/ship.py @@ -9,6 +9,8 @@ from ...utils import safeformat class ShipCommand(Command): name: str = "ship" + aliases = ["⛵️"] + description: str = "Crea una ship tra due nomi." syntax = "(nomeuno) (nomedue)" diff --git a/royalnet/commands/royalgames/skip.py b/royalnet/commands/royalgames/skip.py index 74201e42..c0edf252 100644 --- a/royalnet/commands/royalgames/skip.py +++ b/royalnet/commands/royalgames/skip.py @@ -39,6 +39,8 @@ class SkipNH(NetworkHandler): class SkipCommand(Command): name: str = "skip" + aliases = ["s", "next", "n"] + description: str = "Salta la canzone attualmente in riproduzione in chat vocale." syntax: str = "[ [guild] ]" diff --git a/royalnet/commands/royalgames/smecds.py b/royalnet/commands/royalgames/smecds.py index 16da1ff7..b52f6341 100644 --- a/royalnet/commands/royalgames/smecds.py +++ b/royalnet/commands/royalgames/smecds.py @@ -9,6 +9,8 @@ from ...utils import safeformat class SmecdsCommand(Command): name: str = "smecds" + aliases = ["secondomeecolpadellostagista"] + description: str = "Secondo me, è colpa dello stagista..." syntax = "" diff --git a/royalnet/commands/royalgames/summon.py b/royalnet/commands/royalgames/summon.py index 99ed8733..9d9cfe91 100644 --- a/royalnet/commands/royalgames/summon.py +++ b/royalnet/commands/royalgames/summon.py @@ -28,6 +28,8 @@ class SummonNH(NetworkHandler): class SummonCommand(Command): name: str = "summon" + aliases = ["cv"] + description: str = "Evoca il bot in un canale vocale." syntax: str = "[nomecanale]" diff --git a/royalnet/commands/royalgames/trivia.py b/royalnet/commands/royalgames/trivia.py index b6385af2..7b9ec640 100644 --- a/royalnet/commands/royalgames/trivia.py +++ b/royalnet/commands/royalgames/trivia.py @@ -16,6 +16,8 @@ from ...database.tables import TriviaScore class TriviaCommand(Command): name: str = "trivia" + aliases = ["t"] + description: str = "Manda una domanda dell'OpenTDB in chat." require_alchemy_tables = {TriviaScore} diff --git a/royalnet/commands/royalgames/videochannel.py b/royalnet/commands/royalgames/videochannel.py index 3d153675..8bce18fe 100644 --- a/royalnet/commands/royalgames/videochannel.py +++ b/royalnet/commands/royalgames/videochannel.py @@ -9,6 +9,8 @@ from ...error import * class VideochannelCommand(Command): name: str = "videochannel" + aliases = ["golive", "live", "video"] + description: str = "Converti il canale vocale in un canale video." syntax = "[channelname]" diff --git a/royalnet/commands/royalgames/zawarudo.py b/royalnet/commands/royalgames/zawarudo.py index 3918ab93..cd04eec9 100644 --- a/royalnet/commands/royalgames/zawarudo.py +++ b/royalnet/commands/royalgames/zawarudo.py @@ -76,6 +76,8 @@ class ZawarudoNH(NetworkHandler): class ZawarudoCommand(Command): name: str = "zawarudo" + aliases = ["theworld", "world"] + description: str = "Ferma il tempo!" syntax = "[ [guild] ] [1-9]" diff --git a/royalnet/version.py b/royalnet/version.py index 8d92dcaa..b5e155c5 100644 --- a/royalnet/version.py +++ b/royalnet/version.py @@ -1 +1 @@ -semantic = "5.0a62" +semantic = "5.0a63"