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

Change an enormous amount of stuff

This commit is contained in:
Steffo 2019-10-17 15:33:23 +02:00
parent 1750522321
commit 4a07afe72b
72 changed files with 232 additions and 461 deletions

View file

@ -5170,7 +5170,7 @@ jQuery.event = {
} }
} }
// Remove generic event handler if we removed something and no more handlers exist // Remove common event handler if we removed something and no more handlers exist
// (avoids potential for endless recursion during removal of special event handlers) // (avoids potential for endless recursion during removal of special event handlers)
if ( origCount && !handlers.length ) { if ( origCount && !handlers.length ) {
if ( !special.teardown || if ( !special.teardown ||

View file

@ -5,66 +5,7 @@ These pages were automatically generated from docstrings in code.
They might be outdated, or incomplete. They might be outdated, or incomplete.
Audio .. automodule:: royalnet
------------------------------------
.. automodule:: royalnet.audio
:members:
:undoc-members:
:private-members:
Bots
------------------------------------
.. automodule:: royalnet.bots
:members:
:undoc-members:
:private-members:
Commands
------------------------------------
.. automodule:: royalnet.commands
:members:
:undoc-members:
:private-members:
Database
------------------------------------
.. automodule:: royalnet.database
:members:
:undoc-members:
:private-members:
Network
------------------------------------
.. automodule:: royalnet.network
:members:
:undoc-members:
:private-members:
Utils
------------------------------------
.. automodule:: royalnet.utils
:members:
:undoc-members:
:private-members:
Web
------------------------------------
.. automodule:: royalnet.web
:members:
:undoc-members:
:private-members:
Error
------------------------------------
.. automodule:: royalnet.error
:members: :members:
:undoc-members: :undoc-members:
:private-members: :private-members:

View file

@ -1,4 +1,3 @@
from . import audio, bots, database, utils, error, web, version from . import audio, bots, commands, packs, database, utils, error, web, version
from royalnet import commands
__all__ = ["audio", "bots", "commands", "database", "utils", "error", "web", "version"] __all__ = ["audio", "bots", "commands", "database", "utils", "error", "web", "version"]

View file

@ -2,6 +2,7 @@ import click
import typing import typing
import importlib import importlib
import royalnet as r import royalnet as r
import royalherald as rh
import multiprocessing import multiprocessing
import keyring import keyring
@ -13,8 +14,8 @@ import keyring
help="Enable/disable the Discord module.") help="Enable/disable the Discord module.")
@click.option("-d", "--database", type=str, default=None, @click.option("-d", "--database", type=str, default=None,
help="The PostgreSQL database path.") help="The PostgreSQL database path.")
@click.option("-c", "--command-packs", type=str, multiple=True, default=[], @click.option("-p", "--packs", type=str, multiple=True, default=[],
help="The names of the command pack modules that should be imported.") help="The names of the Packs that should be used.")
@click.option("-n", "--network-address", type=str, default=None, @click.option("-n", "--network-address", type=str, default=None,
help="The Network server URL to connect to.") help="The Network server URL to connect to.")
@click.option("-l", "--local-network-server", is_flag=True, default=False, @click.option("-l", "--local-network-server", is_flag=True, default=False,
@ -26,7 +27,7 @@ import keyring
def run(telegram: typing.Optional[bool], def run(telegram: typing.Optional[bool],
discord: typing.Optional[bool], discord: typing.Optional[bool],
database: typing.Optional[str], database: typing.Optional[str],
command_packs: typing.List[str], packs: typing.List[str],
network_address: typing.Optional[str], network_address: typing.Optional[str],
local_network_server: bool, local_network_server: bool,
secrets_name: str, secrets_name: str,
@ -63,41 +64,38 @@ def run(telegram: typing.Optional[bool],
# Start the network server # Start the network server
if local_network_server: if local_network_server:
server_process = multiprocessing.Process(name="Network Server", server_process = multiprocessing.Process(name="Network Server",
target=r.network.NetworkServer("0.0.0.0", target=rh.Server("0.0.0.0", 44444, network_password).run_blocking,
44444,
network_password).run_blocking,
daemon=True) daemon=True)
server_process.start() server_process.start()
network_address = "ws://127.0.0.1:44444/" network_address = "ws://127.0.0.1:44444/"
# Create a Royalnet configuration # Create a Royalnet configuration
network_config: typing.Optional[r.network.NetworkConfig] = None network_config: typing.Optional[rh.Config] = None
if network_address is not None: if network_address is not None:
network_config = r.network.NetworkConfig(network_address, network_password) network_config = rh.Config(network_address, network_password)
# Create a Alchemy configuration # Create a Alchemy configuration
telegram_db_config: typing.Optional[r.database.DatabaseConfig] = None telegram_db_config: typing.Optional[r.database.DatabaseConfig] = None
discord_db_config: typing.Optional[r.database.DatabaseConfig] = None discord_db_config: typing.Optional[r.database.DatabaseConfig] = None
if database is not None: if database is not None:
telegram_db_config = r.database.DatabaseConfig(database, telegram_db_config = r.database.DatabaseConfig(database,
r.database.tables.User, r.packs.common.tables.User,
r.database.tables.Telegram, r.packs.common.tables.Telegram,
"tg_id") "tg_id")
discord_db_config = r.database.DatabaseConfig(database, discord_db_config = r.database.DatabaseConfig(database,
r.database.tables.User, r.packs.common.tables.User,
r.database.tables.Discord, r.packs.common.tables.Discord,
"discord_id") "discord_id")
# Import command packs # Import command packs
if not command_packs: packs.append("royalnet.packs.common") # common pack is always imported
raise click.ClickException("No command packs were specified.")
enabled_commands = [] enabled_commands = []
for pack in command_packs: for pack in packs:
imported = importlib.import_module(pack) imported = importlib.import_module(pack)
try: try:
imported_commands = imported.commands imported_commands = imported.commands
except AttributeError: except AttributeError:
raise click.ClickException(f"{pack} isn't a Royalnet command pack.") raise click.ClickException(f"{pack} isn't a Royalnet Pack.")
enabled_commands = [*enabled_commands, *imported_commands] enabled_commands = [*enabled_commands, *imported_commands]
telegram_process: typing.Optional[multiprocessing.Process] = None telegram_process: typing.Optional[multiprocessing.Process] = None

View file

@ -52,7 +52,7 @@ class PlayMode:
def queue_preview(self) -> typing.List[YtdlDiscord]: def queue_preview(self) -> typing.List[YtdlDiscord]:
"""Display all the videos in the PlayMode as a list, if possible. """Display all the videos in the PlayMode as a list, if possible.
To be used with ``queue`` commands, for example. To be used with ``queue`` packs, for example.
Raises: Raises:
NotImplementedError: If a preview can't be generated. NotImplementedError: If a preview can't be generated.

View file

@ -1,4 +1,4 @@
"""Various bot interfaces, and a generic class to create new ones.""" """Various bot interfaces, and a common class to create new ones."""
from .generic import GenericBot from .generic import GenericBot
from .telegram import TelegramBot from .telegram import TelegramBot

View file

@ -5,7 +5,7 @@ from .generic import GenericBot
from ..utils import * from ..utils import *
from ..error import * from ..error import *
from ..audio import * from ..audio import *
from ..commands import * from ..packs import *
log = _logging.getLogger(__name__) log = _logging.getLogger(__name__)

View file

@ -9,7 +9,7 @@ from sentry_sdk.integrations.aiohttp import AioHttpIntegration
from sentry_sdk.integrations.logging import LoggingIntegration from sentry_sdk.integrations.logging import LoggingIntegration
from ..utils import * from ..utils import *
from ..database import * from ..database import *
from ..commands import * from ..packs import *
from ..error import * from ..error import *
@ -17,14 +17,14 @@ log = logging.getLogger(__name__)
class GenericBot: class GenericBot:
"""A generic bot class, to be used as base for the other more specific classes, such as """A common bot class, to be used as base for the other more specific classes, such as
:py:class:`royalnet.bots.TelegramBot` and :py:class:`royalnet.bots.DiscordBot`. """ :py:class:`royalnet.bots.TelegramBot` and :py:class:`royalnet.bots.DiscordBot`. """
interface_name = NotImplemented interface_name = NotImplemented
def _init_commands(self) -> None: def _init_commands(self) -> None:
"""Generate the ``commands`` dictionary required to handle incoming messages, and the ``network_handlers`` """Generate the ``packs`` dictionary required to handle incoming messages, and the ``network_handlers``
dictionary required to handle incoming requests. """ dictionary required to handle incoming requests. """
log.info(f"Registering commands...") log.info(f"Registering packs...")
self._Interface = self._interface_factory() self._Interface = self._interface_factory()
self._Data = self._data_factory() self._Data = self._data_factory()
self.commands = {} self.commands = {}
@ -126,7 +126,7 @@ class GenericBot:
}).to_dict() }).to_dict()
def _init_database(self): def _init_database(self):
"""Create an :py:class:`royalnet.database.Alchemy` with the tables required by the commands. Then, """Create an :py:class:`royalnet.database.Alchemy` with the tables required by the packs. Then,
find the chain that links the ``master_table`` to the ``identity_table``. """ find the chain that links the ``master_table`` to the ``identity_table``. """
if self.uninitialized_database_config: if self.uninitialized_database_config:
log.info(f"Database: enabled") log.info(f"Database: enabled")
@ -198,7 +198,7 @@ class GenericBot:
self.initialized = True self.initialized = True
def run(self): def run(self):
"""A blocking coroutine that should make the bot start listening to commands and requests.""" """A blocking coroutine that should make the bot start listening to packs and requests."""
raise NotImplementedError() raise NotImplementedError()
def run_blocking(self, verbose=False): def run_blocking(self, verbose=False):

View file

@ -5,10 +5,11 @@ import urllib3
import asyncio import asyncio
import sentry_sdk import sentry_sdk
import logging as _logging import logging as _logging
import warnings
from .generic import GenericBot from .generic import GenericBot
from ..utils import * from ..utils import *
from ..error import * from ..error import *
from ..commands import * from ..packs import *
log = _logging.getLogger(__name__) log = _logging.getLogger(__name__)
@ -84,6 +85,7 @@ class TelegramBot(GenericBot):
return result return result
async def keyboard(data, text: str, keyboard: typing.Dict[str, typing.Callable]) -> None: async def keyboard(data, text: str, keyboard: typing.Dict[str, typing.Callable]) -> None:
warnings.warn("keyboard is deprecated, please avoid using it", category=DeprecationWarning)
tg_keyboard = [] tg_keyboard = []
for key in keyboard: for key in keyboard:
press_id = uuid.uuid4() press_id = uuid.uuid4()

View file

@ -20,7 +20,7 @@ class Command:
"""The syntax of the command, to be displayed when a :py:exc:`royalnet.error.InvalidInputError` is raised, """The syntax of the command, to be displayed when a :py:exc:`royalnet.error.InvalidInputError` is raised,
in the format ``(required_arg) [optional_arg]``.""" in the format ``(required_arg) [optional_arg]``."""
require_alchemy_tables: typing.Set = set() tables: typing.Set = set()
"""A set of :py:class:`royalnet.database` tables that must exist for this command to work.""" """A set of :py:class:`royalnet.database` tables that must exist for this command to work."""
def __init__(self, interface: CommandInterface): def __init__(self, interface: CommandInterface):

View file

@ -1,4 +1,5 @@
import typing import typing
import warnings
from .commanderrors import UnsupportedError from .commanderrors import UnsupportedError
@ -22,6 +23,7 @@ class CommandData:
"""Send a keyboard having the keys of the dict as keys and calling the correspondent values on a press. """Send a keyboard having the keys of the dict as keys and calling the correspondent values on a press.
The function should be passed the :py:class:`CommandData` instance as a argument.""" The function should be passed the :py:class:`CommandData` instance as a argument."""
warnings.warn("keyboard is deprecated, please avoid using it", category=DeprecationWarning)
raise UnsupportedError("'keyboard' is not supported on this platform") raise UnsupportedError("'keyboard' is not supported on this platform")
async def delete_invoking(self, error_if_unavailable=False) -> None: async def delete_invoking(self, error_if_unavailable=False) -> None:

View file

@ -1,13 +0,0 @@
from .debug_error import DebugErrorCommand
from .debug_keyboard import DebugKeyboardCommand
from .debug_invoking import DebugInvokingCommand
commands = [
DebugErrorCommand,
DebugKeyboardCommand,
DebugInvokingCommand,
]
__all__ = [command.__name__ for command in commands]

View file

@ -1,13 +0,0 @@
import typing
from ..command import Command
from ..commandargs import CommandArgs
from ..commanddata import CommandData
class DebugErrorCommand(Command):
name: str = "debug_error"
description: str = "Causa un'eccezione nel bot."
async def run(self, args: CommandArgs, data: CommandData) -> None:
raise Exception("debug_error command was called")

View file

@ -1,14 +0,0 @@
import typing
from ..command import Command
from ..commandargs import CommandArgs
from ..commanddata import CommandData
class DebugInvokingCommand(Command):
name: str = "debug_invoking"
description: str = "Elimina il messaggio di invocazione."
async def run(self, args: CommandArgs, data: CommandData) -> None:
await data.delete_invoking(error_if_unavailable=True)
await data.reply("🗑 Messaggio eliminato.")

View file

@ -1,18 +0,0 @@
import typing
from ..command import Command
from ..commandargs import CommandArgs
from ..commanddata import CommandData
class DebugKeyboardCommand(Command):
name: str = "debug_keyboard"
description: str = "Invia una tastiera di prova."
async def _callback(self, data: CommandData):
await data.reply("OK.")
async def run(self, args: CommandArgs, data: CommandData) -> None:
await data.keyboard("This is a keyboard.", {
"✅ OK": self._callback
})

View file

@ -1,13 +0,0 @@
import typing
from ..command import Command
from ..commandargs import CommandArgs
from ..commanddata import CommandData
class PingCommand(Command):
name: str = "ping"
description: str = "Gioca a ping-pong con il bot."
async def run(self, args: CommandArgs, data: CommandData) -> None:
await data.reply("🏓 Pong!")

View file

@ -1,30 +0,0 @@
"""Commands that can be used in bots.
These probably won't suit your needs, as they are tailored for the bots of the User Games gaming community, but they
may be useful to develop new ones."""
from .pause import PauseCommand
from .play import PlayCommand
from .playmode import PlaymodeCommand
from .queue import QueueCommand
from .skip import SkipCommand
from .summon import SummonCommand
from .youtube import YoutubeCommand
from .soundcloud import SoundcloudCommand
from .zawarudo import ZawarudoCommand
commands = [
PauseCommand,
PlayCommand,
PlaymodeCommand,
QueueCommand,
SkipCommand,
SummonCommand,
YoutubeCommand,
SoundcloudCommand,
ZawarudoCommand
]
__all__ = [command.__name__ for command in commands]

View file

@ -3,6 +3,5 @@
from .alchemy import Alchemy from .alchemy import Alchemy
from .relationshiplinkchain import relationshiplinkchain from .relationshiplinkchain import relationshiplinkchain
from .databaseconfig import DatabaseConfig from .databaseconfig import DatabaseConfig
from . import tables
__all__ = ["Alchemy", "relationshiplinkchain", "DatabaseConfig", "tables"] __all__ = ["Alchemy", "relationshiplinkchain", "DatabaseConfig"]

View file

@ -1,22 +0,0 @@
from .users import User
from .telegram import Telegram
from .diario import Diario
from .aliases import Alias
from .activekvgroups import ActiveKvGroup
from .keyvalues import Keyvalue
from .keygroups import Keygroup
from .discord import Discord
from .wikipages import WikiPage
from .wikirevisions import WikiRevision
from .medals import Medal
from .medalawards import MedalAward
from .bios import Bio
from .reminders import Reminder
from .triviascores import TriviaScore
from .mmdecisions import MMDecision
from .mmevents import MMEvent
from .mmresponse import MMResponse
__all__ = ["User", "Telegram", "Diario", "Alias", "ActiveKvGroup", "Keyvalue", "Keygroup", "Discord", "WikiPage",
"WikiRevision", "Medal", "MedalAward", "Bio", "Reminder", "TriviaScore", "MMDecision", "MMEvent",
"MMResponse"]

View file

@ -1,39 +0,0 @@
from sqlalchemy import Column, \
Integer, \
DateTime, \
ForeignKey
from sqlalchemy.ext.declarative import declared_attr
from sqlalchemy.orm import relationship
from .users import User
from .medals import Medal
class MedalAward:
__tablename__ = "MedalAward"
@declared_attr
def award_id(self):
return Column(Integer, primary_key=True)
@declared_attr
def date(self):
return Column(DateTime)
@declared_attr
def medal_id(self):
return Column(Integer, ForeignKey("medals.mid"), nullable=False)
@declared_attr
def royal_id(self):
return Column(Integer, ForeignKey("users.uid"), nullable=False)
@declared_attr
def medal(self):
return relationship("Medal", backref="awarded_to")
@declared_attr
def royal(self):
return relationship("User", backref="medals_received")
def __repr__(self):
return f"<MedalAward of {self.medal} to {self.royal} on {self.date}>"

View file

@ -1,40 +0,0 @@
from sqlalchemy import Column, \
Integer, \
String
from sqlalchemy.ext.declarative import declared_attr
# noinspection PyUnresolvedReferences
from .keygroups import Keygroup
class Medal:
__tablename__ = "medals"
@declared_attr
def mid(self):
return Column(Integer, primary_key=True)
@declared_attr
def name(self):
return Column(String, nullable=False)
@declared_attr
def description(self):
return Column(String)
@declared_attr
def icon(self):
return Column(String)
@declared_attr
def classes(self):
return Column(String, nullable=False, default="")
@declared_attr
def score(self):
return Column(Integer, nullable=False)
def __str__(self):
return self.name
def __repr__(self):
return f"<Medal {self.mid}: {self.name}>"

View file

@ -0,0 +1,7 @@
from . import common
from . import royal
__all__ = [
"common",
"royal",
]

View file

@ -0,0 +1,6 @@
# This is a template Pack __init__. You can use this without changing anything in other packages too!
from .commands import commands
from .tables import tables
__all__ = ["commands", "tables"]

View file

@ -0,0 +1,10 @@
# Imports go here!
from .ping import PingCommand
# Enter the commands of your Pack here!
commands = [
PingCommand,
]
# Don't change this, it should automatically generate __all__
__all__ = [command.__class__.__qualname__ for command in commands]

View file

@ -0,0 +1,10 @@
from royalnet.commands import *
class PingCommand(Command):
name: str = "ping"
description: str = "Get a pong response."
async def run(self, args: CommandArgs, data: CommandData) -> None:
await data.reply("🏓 Pong!")

View file

@ -0,0 +1,14 @@
# Imports go here!
from .users import User
from .telegram import Telegram
from .discord import Discord
# Enter the tables of your Pack here!
tables = [
User,
Telegram,
Discord
]
# Don't change this, it should automatically generate __all__
__all__ = [table.__class__.__qualname__ for table in tables]

View file

@ -29,7 +29,7 @@ class User:
return Column(LargeBinary) return Column(LargeBinary)
def __repr__(self): def __repr__(self):
return f"<User {self.username}>" return f"<{self.__class__.__qualname__} {self.username}>"
def __str__(self): def __str__(self):
return self.username return self.username

View file

@ -0,0 +1,7 @@
# This is a template Pack __init__. You can use this without changing anything in other packages too!
from .commands import commands
from .tables import tables
__all__ = ["commands", "tables"]

View file

@ -0,0 +1,10 @@
# Imports go here!
# Enter the commands of your Pack here!
commands = [
]
# Don't change this, it should automatically generate __all__
__all__ = [command.__class__.__qualname__ for command in commands]

View file

@ -0,0 +1,10 @@
# Imports go here!
# Enter the tables of your Pack here!
tables = [
]
# Don't change this, it should automatically generate __all__
__all__ = [table.__class__.__qualname__ for table in tables]

View file

@ -0,0 +1,6 @@
# This is a template Pack __init__. You can use this without changing anything in other packages too!
from .commands import commands
from .tables import tables
__all__ = ["commands", "tables"]

View file

@ -1,13 +1,8 @@
"""Commands that can be used in bots. # Imports go here!
These probably won't suit your needs, as they are tailored for the bots of the User Games gaming community, but they
may be useful to develop new ones."""
from .ciaoruozi import CiaoruoziCommand from .ciaoruozi import CiaoruoziCommand
from .color import ColorCommand from .color import ColorCommand
from .cv import CvCommand from .cv import CvCommand
from .diario import DiarioCommand from .diario import DiarioCommand
from .ping import PingCommand
from .rage import RageCommand from .rage import RageCommand
from .reminder import ReminderCommand from .reminder import ReminderCommand
from .ship import ShipCommand from .ship import ShipCommand
@ -17,14 +12,22 @@ from .dnditem import DnditemCommand
from .dndspell import DndspellCommand from .dndspell import DndspellCommand
from .trivia import TriviaCommand from .trivia import TriviaCommand
from .mm import MmCommand from .mm import MmCommand
from .pause import PauseCommand
from .play import PlayCommand
from .playmode import PlaymodeCommand
from .queue import QueueCommand
from .skip import SkipCommand
from .summon import SummonCommand
from .youtube import YoutubeCommand
from .soundcloud import SoundcloudCommand
from .zawarudo import ZawarudoCommand
# Enter the commands of your Pack here!
commands = [ commands = [
CiaoruoziCommand, CiaoruoziCommand,
ColorCommand, ColorCommand,
CvCommand, CvCommand,
DiarioCommand, DiarioCommand,
PingCommand,
RageCommand, RageCommand,
ReminderCommand, ReminderCommand,
ShipCommand, ShipCommand,
@ -34,7 +37,16 @@ commands = [
DndspellCommand, DndspellCommand,
TriviaCommand, TriviaCommand,
MmCommand, MmCommand,
PauseCommand,
PlayCommand,
PlaymodeCommand,
QueueCommand,
SkipCommand,
SummonCommand,
YoutubeCommand,
SoundcloudCommand,
ZawarudoCommand
] ]
# Don't change this, it should automatically generate __all__
__all__ = [command.__name__ for command in commands] __all__ = [command.__class__.__qualname__ for command in commands]

View file

@ -1,8 +1,6 @@
import typing import typing
import telegram import telegram
from ..command import Command from royalnet.commands import *
from ..commandargs import CommandArgs
from ..commanddata import CommandData
class CiaoruoziCommand(Command): class CiaoruoziCommand(Command):
@ -12,7 +10,7 @@ class CiaoruoziCommand(Command):
syntax: str = "" syntax: str = ""
require_alchemy_tables: typing.Set = set() tables: typing.Set = set()
async def run(self, args: CommandArgs, data: CommandData) -> None: async def run(self, args: CommandArgs, data: CommandData) -> None:
if self.interface.name == "telegram": if self.interface.name == "telegram":

View file

@ -1,7 +1,4 @@
import typing from royalnet.commands import *
from ..command import Command
from ..commandargs import CommandArgs
from ..commanddata import CommandData
class ColorCommand(Command): class ColorCommand(Command):

View file

@ -1,20 +1,16 @@
import discord import discord
import typing import typing
from ..command import Command from royalnet.commands import *
from ..commandinterface import CommandInterface from royalnet.utils import NetworkHandler, andformat
from ..commandargs import CommandArgs from royalnet.bots import DiscordBot
from ..commanddata import CommandData from royalherald import Request, ResponseSuccess
from ...network import Request, ResponseSuccess
from ...utils import NetworkHandler, andformat
from ...bots import DiscordBot
from ..commanderrors import CommandError
class CvNH(NetworkHandler): class CvNH(NetworkHandler):
message_type = "discord_cv" message_type = "discord_cv"
@classmethod @classmethod
async def discord(cls, bot: "DiscordBot", data: dict): async def discord(cls, bot: DiscordBot, data: dict):
# Find the matching guild # Find the matching guild
if data["guild_name"]: if data["guild_name"]:
guilds: typing.List[discord.Guild] = bot.client.find_guild_by_name(data["guild_name"]) guilds: typing.List[discord.Guild] = bot.client.find_guild_by_name(data["guild_name"])

View file

@ -3,12 +3,9 @@ import re
import datetime import datetime
import telegram import telegram
import aiohttp import aiohttp
from ..command import Command from royalnet.commands import *
from ..commandargs import CommandArgs from royalnet.utils import asyncify
from ..commanddata import CommandData from ..tables import User, Diario, Alias
from ...database.tables import User, Diario, Alias
from ...utils import asyncify
from ..commanderrors import CommandError, InvalidInputError
async def to_imgur(imgur_api_key, photosizes: typing.List[telegram.PhotoSize], caption="") -> str: async def to_imgur(imgur_api_key, photosizes: typing.List[telegram.PhotoSize], caption="") -> str:
@ -38,7 +35,7 @@ class DiarioCommand(Command):
syntax = "[!] \"(testo)\" --[autore], [contesto]" syntax = "[!] \"(testo)\" --[autore], [contesto]"
require_alchemy_tables = {User, Diario, Alias} tables = {User, Diario, Alias}
async def run(self, args: CommandArgs, data: CommandData) -> None: async def run(self, args: CommandArgs, data: CommandData) -> None:
if self.interface.name == "telegram": if self.interface.name == "telegram":

View file

@ -1,11 +1,8 @@
import typing import typing
import aiohttp import aiohttp
import sortedcontainers import sortedcontainers
from ..command import Command from royalnet.commands import *
from ..commandargs import CommandArgs from royalnet.utils import parse_5etools_entry
from ..commanddata import CommandData
from ..commandinterface import CommandInterface
from ...utils import parse_5etools_entry
class DnditemCommand(Command): class DnditemCommand(Command):

View file

@ -1,11 +1,8 @@
import typing import typing
import aiohttp import aiohttp
import sortedcontainers import sortedcontainers
from ..command import Command from royalnet.commands import *
from ..commandargs import CommandArgs from royalnet.utils import parse_5etools_entry, ordinalformat, andformat
from ..commanddata import CommandData
from ..commandinterface import CommandInterface
from ...utils import parse_5etools_entry, ordinalformat, andformat
class DndspellCommand(Command): class DndspellCommand(Command):

View file

@ -5,12 +5,10 @@ import asyncio
import re import re
import logging import logging
import typing import typing
from ..command import Command from royalnet.commands import *
from ..commandargs import CommandArgs from royalnet.utils import asyncify, telegram_escape, sleep_until
from ..commanddata import CommandData from ..tables import MMEvent, MMDecision, MMResponse
from ...database.tables import MMEvent, MMDecision, MMResponse
from ..commanderrors import InvalidInputError, UnsupportedError
from ...utils import asyncify, telegram_escape, sleep_until
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -27,7 +25,7 @@ class MmCommand(Command):
syntax: str = "[ (data) ] (nomegioco)\n[descrizione]" syntax: str = "[ (data) ] (nomegioco)\n[descrizione]"
require_alchemy_tables = {MMEvent, MMDecision, MMResponse} tables = {MMEvent, MMDecision, MMResponse}
_cycle_duration = 10 _cycle_duration = 10

View file

@ -1,11 +1,9 @@
import typing import typing
import urllib.parse import urllib.parse
import asyncio import asyncio
from ..command import Command from royalnet.commands import *
from ..commandargs import CommandArgs from royalnet.utils import asyncify
from ..commanddata import CommandData from royalnet.audio import YtdlMp3
from ...utils import asyncify
from ...audio import YtdlMp3
class Mp3Command(Command): class Mp3Command(Command):

View file

@ -1,14 +1,9 @@
import typing import typing
import discord import discord
from ..command import Command from royalnet.commands import *
from ..commandinterface import CommandInterface from royalnet.utils import NetworkHandler
from ..commandargs import CommandArgs from royalnet.bots import DiscordBot
from ..commanddata import CommandData from royalherald import Request, ResponseSuccess
from ...utils import NetworkHandler
from ...network import Request, ResponseSuccess
from ..commanderrors import CommandError
if typing.TYPE_CHECKING:
from ...bots import DiscordBot
class PauseNH(NetworkHandler): class PauseNH(NetworkHandler):
@ -16,7 +11,7 @@ class PauseNH(NetworkHandler):
# noinspection PyProtectedMember # noinspection PyProtectedMember
@classmethod @classmethod
async def discord(cls, bot: "DiscordBot", data: dict): async def discord(cls, bot: DiscordBot, data: dict):
# Find the matching guild # Find the matching guild
if data["guild_name"]: if data["guild_name"]:
guilds: typing.List[discord.Guild] = bot.client.find_guild_by_name(data["guild_name"]) guilds: typing.List[discord.Guild] = bot.client.find_guild_by_name(data["guild_name"])

View file

@ -2,16 +2,11 @@ import typing
import pickle import pickle
import datetime import datetime
import discord import discord
from ..command import Command from royalnet.commands import *
from ..commandinterface import CommandInterface from royalnet.utils import NetworkHandler, asyncify
from ..commandargs import CommandArgs from royalnet.audio import YtdlDiscord
from ..commanddata import CommandData from royalnet.bots import DiscordBot
from ...utils import NetworkHandler, asyncify from royalherald import Request, ResponseSuccess
from ...network import Request, ResponseSuccess
from ..commanderrors import CommandError
from ...audio import YtdlDiscord
if typing.TYPE_CHECKING:
from ...bots import DiscordBot
class PlayNH(NetworkHandler): class PlayNH(NetworkHandler):

View file

@ -1,16 +1,11 @@
import typing import typing
import pickle import pickle
import discord import discord
from ..command import Command from royalnet.commands import *
from ..commandinterface import CommandInterface from royalnet.utils import NetworkHandler
from ..commandargs import CommandArgs from royalnet.audio.playmodes import Playlist, Pool, Layers
from ..commanddata import CommandData from royalnet.bots import DiscordBot
from ...utils import NetworkHandler from royalherald import Request, ResponseSuccess
from ...network import Request, ResponseSuccess
from ..commanderrors import CommandError
from ...audio.playmodes import Playlist, Pool, Layers
if typing.TYPE_CHECKING:
from ...bots import DiscordBot
class PlaymodeNH(NetworkHandler): class PlaymodeNH(NetworkHandler):

View file

@ -1,10 +1,7 @@
import typing import typing
import pickle import pickle
import discord import discord
from ..command import Command from royalnet.commands import *
from ..commandinterface import CommandInterface
from ..commandargs import CommandArgs
from ..commanddata import CommandData
from ...utils import NetworkHandler, numberemojiformat from ...utils import NetworkHandler, numberemojiformat
from ...network import Request, ResponseSuccess from ...network import Request, ResponseSuccess
from ..commanderrors import CommandError from ..commanderrors import CommandError

View file

@ -1,8 +1,6 @@
import typing import typing
import random import random
from ..command import Command from royalnet.commands import *
from ..commandargs import CommandArgs
from ..commanddata import CommandData
class RageCommand(Command): class RageCommand(Command):

View file

@ -5,10 +5,7 @@ import pickle
import telegram import telegram
import discord import discord
from sqlalchemy import and_ from sqlalchemy import and_
from ..command import Command from royalnet.commands import *
from ..commandargs import CommandArgs
from ..commandinterface import CommandInterface
from ..commanddata import CommandData
from ...utils import sleep_until, asyncify, telegram_escape, discord_escape from ...utils import sleep_until, asyncify, telegram_escape, discord_escape
from ...database.tables import Reminder from ...database.tables import Reminder
from ..commanderrors import InvalidInputError, UnsupportedError from ..commanderrors import InvalidInputError, UnsupportedError
@ -22,7 +19,7 @@ class ReminderCommand(Command):
syntax: str = "[ (data) ] (messaggio)" syntax: str = "[ (data) ] (messaggio)"
require_alchemy_tables = {Reminder} tables = {Reminder}
def __init__(self, interface: CommandInterface): def __init__(self, interface: CommandInterface):
super().__init__(interface) super().__init__(interface)

View file

@ -1,8 +1,6 @@
import typing import typing
import re import re
from ..command import Command from royalnet.commands import *
from ..commandargs import CommandArgs
from ..commanddata import CommandData
from ...utils import safeformat from ...utils import safeformat

View file

@ -1,10 +1,7 @@
import typing import typing
import pickle import pickle
import discord import discord
from ..command import Command from royalnet.commands import *
from ..commandinterface import CommandInterface
from ..commandargs import CommandArgs
from ..commanddata import CommandData
from ...utils import NetworkHandler, asyncify from ...utils import NetworkHandler, asyncify
from ...network import Request, ResponseSuccess from ...network import Request, ResponseSuccess
from ..commanderrors import CommandError from ..commanderrors import CommandError

View file

@ -1,8 +1,6 @@
import typing import typing
import random import random
from ..command import Command from royalnet.commands import *
from ..commandargs import CommandArgs
from ..commanddata import CommandData
from ...utils import safeformat from ...utils import safeformat

View file

@ -2,13 +2,9 @@ import typing
import pickle import pickle
import datetime import datetime
import discord import discord
from ..command import Command from royalnet.commands import *
from ..commandinterface import CommandInterface
from ..commandargs import CommandArgs
from ..commanddata import CommandData
from ...utils import NetworkHandler, asyncify from ...utils import NetworkHandler, asyncify
from ...network import Request, ResponseSuccess from ...network import Request, ResponseSuccess
from ..commanderrors import CommandError
from ...audio import YtdlDiscord from ...audio import YtdlDiscord
if typing.TYPE_CHECKING: if typing.TYPE_CHECKING:

View file

@ -1,9 +1,6 @@
import typing import typing
import discord import discord
from ..command import Command from royalnet.commands import *
from ..commandinterface import CommandInterface
from ..commandargs import CommandArgs
from ..commanddata import CommandData
from ...utils import NetworkHandler from ...utils import NetworkHandler
from ...network import Request, ResponseSuccess from ...network import Request, ResponseSuccess
from ..commanderrors import CommandError from ..commanderrors import CommandError

View file

@ -4,10 +4,7 @@ import aiohttp
import random import random
import uuid import uuid
import html import html
from ..command import Command from royalnet.commands import *
from ..commandargs import CommandArgs
from ..commanddata import CommandData
from ..commandinterface import CommandInterface
from ...utils import asyncify from ...utils import asyncify
from ..commanderrors import CommandError, KeyboardExpiredError from ..commanderrors import CommandError, KeyboardExpiredError
from ...database.tables import TriviaScore from ...database.tables import TriviaScore
@ -20,7 +17,7 @@ class TriviaCommand(Command):
description: str = "Manda una domanda dell'OpenTDB in chat." description: str = "Manda una domanda dell'OpenTDB in chat."
require_alchemy_tables = {TriviaScore} tables = {TriviaScore}
_letter_emojis = ["🇦", "🇧", "🇨", "🇩"] _letter_emojis = ["🇦", "🇧", "🇨", "🇩"]

View file

@ -1,9 +1,6 @@
import typing import typing
import discord import discord
from ..command import Command from royalnet.commands import *
from ..commandargs import CommandArgs
from ..commanddata import CommandData
from ..commanderrors import CommandError, UnsupportedError
class VideochannelCommand(Command): class VideochannelCommand(Command):

View file

@ -2,13 +2,9 @@ import typing
import pickle import pickle
import datetime import datetime
import discord import discord
from ..command import Command from royalnet.commands import *
from ..commandinterface import CommandInterface
from ..commandargs import CommandArgs
from ..commanddata import CommandData
from ...utils import NetworkHandler, asyncify from ...utils import NetworkHandler, asyncify
from ...network import Request, ResponseSuccess from ...network import Request, ResponseSuccess
from ..commanderrors import CommandError
from ...audio import YtdlDiscord from ...audio import YtdlDiscord
if typing.TYPE_CHECKING: if typing.TYPE_CHECKING:
from ...bots import DiscordBot from ...bots import DiscordBot

View file

@ -2,13 +2,9 @@ import typing
import discord import discord
import asyncio import asyncio
import datetime import datetime
from ..command import Command from royalnet.commands import *
from ..commandinterface import CommandInterface
from ..commandargs import CommandArgs
from ..commanddata import CommandData
from ...utils import NetworkHandler, asyncify from ...utils import NetworkHandler, asyncify
from ...network import Request, ResponseSuccess from ...network import Request, ResponseSuccess
from ..commanderrors import CommandError, InvalidInputError, UnsupportedError, KeyboardExpiredError
from ...audio import YtdlDiscord from ...audio import YtdlDiscord
from ...audio.playmodes import Playlist from ...audio.playmodes import Playlist
if typing.TYPE_CHECKING: if typing.TYPE_CHECKING:

View file

@ -0,0 +1,41 @@
# Imports go here!
from royalnet.packs.common.tables import User
from royalnet.packs.common.tables import Telegram
from royalnet.packs.common.tables import Discord
from .diario import Diario
from .aliases import Alias
from .activekvgroups import ActiveKvGroup
from .keyvalues import Keyvalue
from .keygroups import Keygroup
from .wikipages import WikiPage
from .wikirevisions import WikiRevision
from .bios import Bio
from .reminders import Reminder
from .triviascores import TriviaScore
from .mmdecisions import MMDecision
from .mmevents import MMEvent
from .mmresponse import MMResponse
# Enter the tables of your Pack here!
tables = [
User,
Telegram,
Discord,
Diario,
Alias,
ActiveKvGroup,
Keyvalue,
Keygroup,
WikiPage,
WikiRevision,
Bio,
Reminder,
TriviaScore,
MMDecision,
MMEvent,
MMResponse,
]
# Don't change this, it should automatically generate __all__
__all__ = [table.__class__.__qualname__ for table in tables]

View file

@ -4,10 +4,6 @@ from sqlalchemy import Column, \
ForeignKey ForeignKey
from sqlalchemy.orm import relationship from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declared_attr from sqlalchemy.ext.declarative import declared_attr
# noinspection PyUnresolvedReferences
from .users import User
# noinspection PyUnresolvedReferences
from .keygroups import Keygroup
class ActiveKvGroup: class ActiveKvGroup:

View file

@ -4,8 +4,6 @@ from sqlalchemy import Column, \
ForeignKey ForeignKey
from sqlalchemy.orm import relationship from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declared_attr from sqlalchemy.ext.declarative import declared_attr
# noinspection PyUnresolvedReferences
from .users import User
class Alias: class Alias:

View file

@ -4,7 +4,6 @@ from sqlalchemy import Column, \
ForeignKey ForeignKey
from sqlalchemy.orm import relationship, backref from sqlalchemy.orm import relationship, backref
from sqlalchemy.ext.declarative import declared_attr from sqlalchemy.ext.declarative import declared_attr
from .users import User
class Bio: class Bio:

View file

@ -8,8 +8,6 @@ from sqlalchemy import Column, \
String String
from sqlalchemy.orm import relationship from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declared_attr from sqlalchemy.ext.declarative import declared_attr
# noinspection PyUnresolvedReferences
from .users import User
class Diario: class Diario:

View file

@ -3,8 +3,6 @@ from sqlalchemy import Column, \
ForeignKey ForeignKey
from sqlalchemy.orm import relationship from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declared_attr from sqlalchemy.ext.declarative import declared_attr
# noinspection PyUnresolvedReferences
from .keygroups import Keygroup
class Keyvalue: class Keyvalue:

View file

@ -4,8 +4,6 @@ from sqlalchemy import Column, \
ForeignKey ForeignKey
from sqlalchemy.orm import relationship from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declared_attr from sqlalchemy.ext.declarative import declared_attr
from .users import User
from .mmevents import MMEvent
class MMDecision: class MMDecision:

View file

@ -1,5 +1,3 @@
import telegram
import typing
from sqlalchemy import Column, \ from sqlalchemy import Column, \
Integer, \ Integer, \
DateTime, \ DateTime, \
@ -9,10 +7,6 @@ from sqlalchemy import Column, \
BigInteger BigInteger
from sqlalchemy.orm import relationship from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declared_attr from sqlalchemy.ext.declarative import declared_attr
from .users import User
if typing.TYPE_CHECKING:
from .mmdecisions import MMDecision
from .mmresponse import MMResponse
class MMEvent: class MMEvent:

View file

@ -4,8 +4,6 @@ from sqlalchemy import Column, \
ForeignKey ForeignKey
from sqlalchemy.orm import relationship from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declared_attr from sqlalchemy.ext.declarative import declared_attr
from .users import User
from .mmevents import MMEvent
class MMResponse: class MMResponse:

View file

@ -6,8 +6,6 @@ from sqlalchemy import Column, \
ForeignKey ForeignKey
from sqlalchemy.orm import relationship from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declared_attr from sqlalchemy.ext.declarative import declared_attr
# noinspection PyUnresolvedReferences
from .users import User
class Reminder: class Reminder:

View file

@ -3,7 +3,6 @@ from sqlalchemy import Column, \
ForeignKey ForeignKey
from sqlalchemy.orm import relationship, backref from sqlalchemy.orm import relationship, backref
from sqlalchemy.ext.declarative import declared_attr from sqlalchemy.ext.declarative import declared_attr
from .users import User
class TriviaScore: class TriviaScore:

View file

@ -6,10 +6,6 @@ from sqlalchemy import Column, \
from sqlalchemy.dialects.postgresql import UUID from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.orm import relationship from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declared_attr from sqlalchemy.ext.declarative import declared_attr
# noinspection PyUnresolvedReferences
from .wikipages import WikiPage
# noinspection PyUnresolvedReferences
from .users import User
class WikiRevision: class WikiRevision:

View file

@ -41,14 +41,14 @@
{% if session["royal"]["avatar"] %} {% if session["royal"]["avatar"] %}
<img class="nav-image" alt="" src="{{ session["royal"]["avatar"] }}"> <img class="nav-image" alt="" src="{{ session["royal"]["avatar"] }}">
{% else %} {% else %}
<img class="nav-image" alt="" src="{{ url_for("static", filename="generic.png") }}"> <img class="nav-image" alt="" src="{{ url_for("static", filename="common.png") }}">
{% endif %} {% endif %}
</a> </a>
{% else %} {% else %}
<span class="nav-login"> <span class="nav-login">
<a class="no-icon" href="{{ url_for("tglogin.tglogin_index") }}"> <a class="no-icon" href="{{ url_for("tglogin.tglogin_index") }}">
Login Login
<img class="nav-image disabled" alt="" src="{{ url_for("static", filename="generic.png") }}"> <img class="nav-image disabled" alt="" src="{{ url_for("static", filename="common.png") }}">
</a> </a>
</span> </span>
{% endif %} {% endif %}