mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 19:44:20 +00:00
Implement aliases
This commit is contained in:
parent
5fcf2652c6
commit
9bc92d7087
20 changed files with 61 additions and 15 deletions
|
@ -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:
|
||||
|
|
|
@ -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"]``."""
|
||||
|
||||
|
|
|
@ -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)"
|
||||
|
|
|
@ -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)"
|
||||
|
|
|
@ -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]"
|
||||
|
|
|
@ -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)"
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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)"
|
||||
|
|
|
@ -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)"
|
||||
|
|
|
@ -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] ]"
|
||||
|
|
|
@ -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."
|
||||
|
||||
|
|
|
@ -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)"
|
||||
|
|
|
@ -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)"
|
||||
|
|
|
@ -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] ]"
|
||||
|
|
|
@ -9,6 +9,8 @@ from ...utils import safeformat
|
|||
class SmecdsCommand(Command):
|
||||
name: str = "smecds"
|
||||
|
||||
aliases = ["secondomeecolpadellostagista"]
|
||||
|
||||
description: str = "Secondo me, è colpa dello stagista..."
|
||||
|
||||
syntax = ""
|
||||
|
|
|
@ -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]"
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -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]"
|
||||
|
|
|
@ -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]"
|
||||
|
|
|
@ -1 +1 @@
|
|||
semantic = "5.0a62"
|
||||
semantic = "5.0a63"
|
||||
|
|
Loading…
Reference in a new issue