From b1ee0182545cea234e4a67a8bf075df4643a7887 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Fri, 27 Sep 2019 21:21:52 +0200 Subject: [PATCH] Start work on the new runbot script --- requirements.txt | 1 + royalnet/commands/debug/__init__.py | 10 ++- royalnet/commands/royalgames/__init__.py | 50 ++++++----- royalnet/royalgames.py | 102 ----------------------- royalnet/run.py | 26 ++++++ setup.py | 3 +- 6 files changed, 65 insertions(+), 127 deletions(-) delete mode 100644 royalnet/royalgames.py create mode 100644 royalnet/run.py diff --git a/requirements.txt b/requirements.txt index e7b5a9e5..aa73f73c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,3 +19,4 @@ markdown2>=2.3.8 mcstatus>=2.2.1 sortedcontainers>=2.1.0 sentry-sdk>=0.11.1 +click>=7.0 diff --git a/royalnet/commands/debug/__init__.py b/royalnet/commands/debug/__init__.py index 88169186..82735ce5 100644 --- a/royalnet/commands/debug/__init__.py +++ b/royalnet/commands/debug/__init__.py @@ -2,4 +2,12 @@ from .debug_error import DebugErrorCommand from .debug_keyboard import DebugKeyboardCommand from .debug_invoking import DebugInvokingCommand -__all__ = ["DebugErrorCommand", "DebugKeyboardCommand", "DebugInvokingCommand"] + +commands = [ + DebugErrorCommand, + DebugKeyboardCommand, + DebugInvokingCommand, +] + + +__all__ = [command.__name__ for command in commands] diff --git a/royalnet/commands/royalgames/__init__.py b/royalnet/commands/royalgames/__init__.py index aac75dfd..346f1d9f 100644 --- a/royalnet/commands/royalgames/__init__.py +++ b/royalnet/commands/royalgames/__init__.py @@ -26,27 +26,31 @@ from .trivia import TriviaCommand from .mm import MmCommand from .zawarudo import ZawarudoCommand -__all__ = [ - "CiaoruoziCommand", - "ColorCommand", - "CvCommand", - "DiarioCommand", - "Mp3Command", - "PauseCommand", - "PingCommand", - "PlayCommand", - "PlaymodeCommand", - "QueueCommand", - "RageCommand", - "ReminderCommand", - "ShipCommand", - "SkipCommand", - "SmecdsCommand", - "SummonCommand", - "VideochannelCommand", - "DnditemCommand", - "DndspellCommand", - "TriviaCommand", - "MmCommand", - "ZawarudoCommand" + +commands = [ + CiaoruoziCommand, + ColorCommand, + CvCommand, + DiarioCommand, + Mp3Command, + PauseCommand, + PingCommand, + PlayCommand, + PlaymodeCommand, + QueueCommand, + RageCommand, + ReminderCommand, + ShipCommand, + SkipCommand, + SmecdsCommand, + SummonCommand, + VideochannelCommand, + DnditemCommand, + DndspellCommand, + TriviaCommand, + MmCommand, + ZawarudoCommand ] + + +__all__ = [command.__name__ for command in commands] diff --git a/royalnet/royalgames.py b/royalnet/royalgames.py deleted file mode 100644 index e16782c6..00000000 --- a/royalnet/royalgames.py +++ /dev/null @@ -1,102 +0,0 @@ -"""The production Royalnet, active at @royalgamesbot on Telegram and Royalbot on Discord.""" - -import os -import asyncio -import logging -import sentry_sdk -from royalnet.bots import DiscordBot, DiscordConfig, TelegramBot, TelegramConfig -from royalnet.commands.royalgames import * -from royalnet.commands.debug import * -from royalnet.network import RoyalnetServer, RoyalnetConfig -from royalnet.database import DatabaseConfig -from royalnet.database.tables import Royal, Telegram, Discord - -loop = asyncio.get_event_loop() - -log = logging.getLogger("royalnet.bots") -stream_handler = logging.StreamHandler() -stream_handler.formatter = logging.Formatter("{asctime}\t{name}\t{levelname}\t{message}", style="{") -log.addHandler(stream_handler) - - -sentry_dsn = os.environ.get("SENTRY_DSN") - -# noinspection PyUnreachableCode -if __debug__: - commands = [ - CiaoruoziCommand, - ColorCommand, - CvCommand, - DiarioCommand, - Mp3Command, - PauseCommand, - PingCommand, - PlayCommand, - PlaymodeCommand, - QueueCommand, - RageCommand, - ReminderCommand, - ShipCommand, - SkipCommand, - SmecdsCommand, - SummonCommand, - VideochannelCommand, - TriviaCommand, - MmCommand, - ZawarudoCommand, - DebugInvokingCommand - ] - log.setLevel(logging.DEBUG) -else: - commands = [ - CiaoruoziCommand, - ColorCommand, - CvCommand, - DiarioCommand, - Mp3Command, - PauseCommand, - PingCommand, - PlayCommand, - PlaymodeCommand, - QueueCommand, - RageCommand, - ReminderCommand, - ShipCommand, - SkipCommand, - SmecdsCommand, - SummonCommand, - VideochannelCommand, - DnditemCommand, - DndspellCommand, - TriviaCommand, - MmCommand, - ZawarudoCommand - ] - log.setLevel(logging.INFO) - -address, port = "127.0.0.1", 1234 - -print("Starting master...") -master = RoyalnetServer(address, port, os.environ["MASTER_KEY"]) -loop.run_until_complete(master.start()) - -print("Starting bots...") -ds_bot = DiscordBot(discord_config=DiscordConfig(os.environ["DS_AK"]), - royalnet_config=RoyalnetConfig(f"ws://{address}:{port}", os.environ["MASTER_KEY"]), - database_config=None, - sentry_dsn=sentry_dsn, - commands=commands) -tg_bot = TelegramBot(telegram_config=TelegramConfig(os.environ["TG_AK"]), - royalnet_config=RoyalnetConfig(f"ws://{address}:{port}", os.environ["MASTER_KEY"]), - database_config=None, - sentry_dsn=sentry_dsn, - commands=commands) -loop.create_task(tg_bot.run()) -loop.create_task(ds_bot.run()) - -print("Enabled commands:") -for command in commands: - print(f"{command.name} - {command.description}") - -print("Running loop...") -loop.run_forever() diff --git a/royalnet/run.py b/royalnet/run.py new file mode 100644 index 00000000..6f246d80 --- /dev/null +++ b/royalnet/run.py @@ -0,0 +1,26 @@ +import click +import typing +import royalnet as r + + +@click.command() +@click.option("--telegram/--no-telegram", default=None, + help="Enable/disable the Telegram module.") +@click.option("--discord/--no-discord", default=None, + help="Enable/disable the Discord module.") +@click.option("--database", type=str, default=None, + help="The PostgreSQL database path.") +@click.option("--commands", type=str, multiple=True, default=[], + help="The names of the command pack modules that should be imported.") +@click.option("--network", type=str, default=None, + help="The Royalnet master server uri and password, separated by a pipe.") +def run(telegram: typing.Optional[bool], + discord: typing.Optional[bool], + database: typing.Optional[str], + commands: typing.List[str], + network: typing.Optional[str]): + ... + + +if __name__ == "__main__": + run() diff --git a/setup.py b/setup.py index 3c0be22d..041f7fa2 100644 --- a/setup.py +++ b/setup.py @@ -30,7 +30,8 @@ setuptools.setup( "markdown2>=2.3.8", "mcstatus>=2.2.1", "sortedcontainers>=2.1.0", - "sentry-sdk>=0.11.1"], + "sentry-sdk>=0.11.1", + "click>=7.0"], python_requires=">=3.7", classifiers=[ "Development Status :: 3 - Alpha",