mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 19:44:20 +00:00
Merge branch 'master' into beeg-refactor
# Conflicts: # royalnet/bots/generic.py # royalnet/commands/royalmusic/pause.py # royalnet/commands/royalmusic/play.py
This commit is contained in:
commit
a69cb05bd1
36 changed files with 79 additions and 35 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
|
||||
|
@ -118,20 +129,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.__qualname__)
|
||||
self.identity_table = self.alchemy.__getattribute__(self.uninitialized_database_config.identity_table.__qualname__)
|
||||
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
|
||||
|
@ -139,13 +153,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:
|
||||
|
|
|
@ -9,7 +9,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)"
|
||||
|
|
|
@ -21,6 +21,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]"
|
||||
|
|
|
@ -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."
|
||||
|
||||
|
|
|
@ -16,6 +16,8 @@ from ..commanderrors import InvalidInputError, UnsupportedError
|
|||
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)"
|
||||
|
|
|
@ -9,6 +9,8 @@ from ...utils import safeformat
|
|||
class SmecdsCommand(Command):
|
||||
name: str = "smecds"
|
||||
|
||||
aliases = ["secondomeecolpadellostagista"]
|
||||
|
||||
description: str = "Secondo me, è colpa dello stagista..."
|
||||
|
||||
syntax = ""
|
||||
|
|
|
@ -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 ..commanderrors import CommandError, UnsupportedError
|
|||
class VideochannelCommand(Command):
|
||||
name: str = "videochannel"
|
||||
|
||||
aliases = ["golive", "live", "video"]
|
||||
|
||||
description: str = "Converti il canale vocale in un canale video."
|
||||
|
||||
syntax = "[channelname]"
|
||||
|
|
|
@ -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)"
|
||||
|
|
|
@ -47,6 +47,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)"
|
||||
|
|
|
@ -52,6 +52,8 @@ class QueueNH(NetworkHandler):
|
|||
class QueueCommand(Command):
|
||||
name: str = "queue"
|
||||
|
||||
aliases = ["q"]
|
||||
|
||||
description: str = "Visualizza la coda di riproduzione attuale."
|
||||
|
||||
syntax = "[ [guild] ]"
|
||||
|
|
|
@ -40,6 +40,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] ]"
|
||||
|
|
|
@ -29,6 +29,8 @@ class SummonNH(NetworkHandler):
|
|||
class SummonCommand(Command):
|
||||
name: str = "summon"
|
||||
|
||||
aliases = ["cv"]
|
||||
|
||||
description: str = "Evoca il bot in un canale vocale."
|
||||
|
||||
syntax: str = "[nomecanale]"
|
||||
|
|
|
@ -77,6 +77,8 @@ class ZawarudoNH(NetworkHandler):
|
|||
class ZawarudoCommand(Command):
|
||||
name: str = "zawarudo"
|
||||
|
||||
aliases = ["theworld", "world"]
|
||||
|
||||
description: str = "Ferma il tempo!"
|
||||
|
||||
syntax = "[ [guild] ] [1-9]"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from .royals import User
|
||||
from .users import User
|
||||
from .telegram import Telegram
|
||||
from .diario import Diario
|
||||
from .aliases import Alias
|
||||
|
|
|
@ -5,7 +5,7 @@ from sqlalchemy import Column, \
|
|||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.ext.declarative import declared_attr
|
||||
# noinspection PyUnresolvedReferences
|
||||
from .royals import User
|
||||
from .users import User
|
||||
# noinspection PyUnresolvedReferences
|
||||
from .keygroups import Keygroup
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ from sqlalchemy import Column, \
|
|||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.ext.declarative import declared_attr
|
||||
# noinspection PyUnresolvedReferences
|
||||
from .royals import User
|
||||
from .users import User
|
||||
|
||||
|
||||
class Alias:
|
||||
|
|
|
@ -4,7 +4,7 @@ from sqlalchemy import Column, \
|
|||
ForeignKey
|
||||
from sqlalchemy.orm import relationship, backref
|
||||
from sqlalchemy.ext.declarative import declared_attr
|
||||
from .royals import User
|
||||
from .users import User
|
||||
|
||||
|
||||
class Bio:
|
||||
|
|
|
@ -9,7 +9,7 @@ from sqlalchemy import Column, \
|
|||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.ext.declarative import declared_attr
|
||||
# noinspection PyUnresolvedReferences
|
||||
from .royals import User
|
||||
from .users import User
|
||||
|
||||
|
||||
class Diario:
|
||||
|
|
|
@ -6,7 +6,7 @@ from sqlalchemy import Column, \
|
|||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.ext.declarative import declared_attr
|
||||
# noinspection PyUnresolvedReferences
|
||||
from .royals import User
|
||||
from .users import User
|
||||
|
||||
|
||||
class Discord:
|
||||
|
|
|
@ -4,7 +4,7 @@ from sqlalchemy import Column, \
|
|||
ForeignKey
|
||||
from sqlalchemy.ext.declarative import declared_attr
|
||||
from sqlalchemy.orm import relationship
|
||||
from .royals import User
|
||||
from .users import User
|
||||
from .medals import Medal
|
||||
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ from sqlalchemy import Column, \
|
|||
ForeignKey
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.ext.declarative import declared_attr
|
||||
from .royals import User
|
||||
from .users import User
|
||||
from .mmevents import MMEvent
|
||||
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ from sqlalchemy import Column, \
|
|||
BigInteger
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.ext.declarative import declared_attr
|
||||
from .royals import User
|
||||
from .users import User
|
||||
if typing.TYPE_CHECKING:
|
||||
from .mmdecisions import MMDecision
|
||||
from .mmresponse import MMResponse
|
||||
|
|
|
@ -4,7 +4,7 @@ from sqlalchemy import Column, \
|
|||
ForeignKey
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.ext.declarative import declared_attr
|
||||
from .royals import User
|
||||
from .users import User
|
||||
from .mmevents import MMEvent
|
||||
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ from sqlalchemy import Column, \
|
|||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.ext.declarative import declared_attr
|
||||
# noinspection PyUnresolvedReferences
|
||||
from .royals import User
|
||||
from .users import User
|
||||
|
||||
|
||||
class Reminder:
|
||||
|
|
|
@ -6,7 +6,7 @@ from sqlalchemy import Column, \
|
|||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.ext.declarative import declared_attr
|
||||
# noinspection PyUnresolvedReferences
|
||||
from .royals import User
|
||||
from .users import User
|
||||
|
||||
|
||||
class Telegram:
|
||||
|
|
|
@ -3,7 +3,7 @@ from sqlalchemy import Column, \
|
|||
ForeignKey
|
||||
from sqlalchemy.orm import relationship, backref
|
||||
from sqlalchemy.ext.declarative import declared_attr
|
||||
from .royals import User
|
||||
from .users import User
|
||||
|
||||
|
||||
class TriviaScore:
|
||||
|
|
|
@ -9,7 +9,7 @@ from sqlalchemy.ext.declarative import declared_attr
|
|||
# noinspection PyUnresolvedReferences
|
||||
from .wikipages import WikiPage
|
||||
# noinspection PyUnresolvedReferences
|
||||
from .royals import User
|
||||
from .users import User
|
||||
|
||||
|
||||
class WikiRevision:
|
||||
|
|
|
@ -1 +1 @@
|
|||
semantic = "5.0a62"
|
||||
semantic = "5.0a63"
|
||||
|
|
|
@ -25,7 +25,7 @@ def login_done():
|
|||
fd = f.request.form
|
||||
if "username" not in fd:
|
||||
return error(400, "Nessun username inserito.")
|
||||
royal_user = alchemy_session.query(alchemy.Royal).filter_by(username=fd["username"]).one_or_none()
|
||||
royal_user = alchemy_session.query(alchemy.User).filter_by(username=fd["username"]).one_or_none()
|
||||
if royal_user is None:
|
||||
return error(404, "L'username inserito non corrisponde a nessun account registrato.")
|
||||
if "password" not in fd:
|
||||
|
|
|
@ -23,7 +23,7 @@ def login_index():
|
|||
return error(400, "Non è stato inserito nessun username.")
|
||||
if "password" not in fd:
|
||||
return error(400, "Non è stata inserita nessuna password.")
|
||||
royal = alchemy_session.query(alchemy.Royal).filter_by(username=fd["username"]).one_or_none()
|
||||
royal = alchemy_session.query(alchemy.User).filter_by(username=fd["username"]).one_or_none()
|
||||
if royal is not None:
|
||||
return error(403, "Esiste già un utente con quell'username.")
|
||||
alias = alchemy_session.query(alchemy.Alias).filter_by(alias=fd["username"]).one_or_none()
|
||||
|
|
|
@ -18,14 +18,14 @@ rp = Royalprint("profile", __name__, url_prefix="/profile", template_folder=tmpl
|
|||
@rp.route("/")
|
||||
def profile_index():
|
||||
alchemy, alchemy_session = f.current_app.config["ALCHEMY"], f.current_app.config["ALCHEMY_SESSION"]
|
||||
royals = alchemy_session.query(alchemy.Royal).order_by(alchemy.Royal.username).all()
|
||||
royals = alchemy_session.query(alchemy.User).order_by(alchemy.User.username).all()
|
||||
return f.render_template("profile_index.html", royals=royals)
|
||||
|
||||
|
||||
@rp.route("/<username>")
|
||||
def profile_page(username):
|
||||
alchemy, alchemy_session = f.current_app.config["ALCHEMY"], f.current_app.config["ALCHEMY_SESSION"]
|
||||
royal = alchemy_session.query(alchemy.Royal).filter_by(username=username).one_or_none()
|
||||
royal = alchemy_session.query(alchemy.User).filter_by(username=username).one_or_none()
|
||||
if royal is None:
|
||||
return error(404, "Non esiste nessun utente con l'username richiesto.")
|
||||
if royal.bio is not None and royal.bio.contents != "":
|
||||
|
@ -43,7 +43,7 @@ def profile_editbio(username):
|
|||
if "royal" not in f.session:
|
||||
return error(403, "Devi aver effettuato il login per modificare una bio.")
|
||||
alchemy, alchemy_session = f.current_app.config["ALCHEMY"], f.current_app.config["ALCHEMY_SESSION"]
|
||||
royal = alchemy_session.query(alchemy.Royal).filter_by(username=username).one_or_none()
|
||||
royal = alchemy_session.query(alchemy.User).filter_by(username=username).one_or_none()
|
||||
if not (f.session["royal"]["uid"] == royal.uid or f.session["royal"]["role"] == "Admin"):
|
||||
return error(403, "Non sei autorizzato a modificare questa pagina bio.")
|
||||
|
||||
|
|
Loading…
Reference in a new issue