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

Start work on the new runbot script

This commit is contained in:
Steffo 2019-09-27 21:21:52 +02:00
parent db954f97b8
commit b1ee018254
6 changed files with 65 additions and 127 deletions

View file

@ -19,3 +19,4 @@ markdown2>=2.3.8
mcstatus>=2.2.1 mcstatus>=2.2.1
sortedcontainers>=2.1.0 sortedcontainers>=2.1.0
sentry-sdk>=0.11.1 sentry-sdk>=0.11.1
click>=7.0

View file

@ -2,4 +2,12 @@ from .debug_error import DebugErrorCommand
from .debug_keyboard import DebugKeyboardCommand from .debug_keyboard import DebugKeyboardCommand
from .debug_invoking import DebugInvokingCommand from .debug_invoking import DebugInvokingCommand
__all__ = ["DebugErrorCommand", "DebugKeyboardCommand", "DebugInvokingCommand"]
commands = [
DebugErrorCommand,
DebugKeyboardCommand,
DebugInvokingCommand,
]
__all__ = [command.__name__ for command in commands]

View file

@ -26,27 +26,31 @@ from .trivia import TriviaCommand
from .mm import MmCommand from .mm import MmCommand
from .zawarudo import ZawarudoCommand from .zawarudo import ZawarudoCommand
__all__ = [
"CiaoruoziCommand", commands = [
"ColorCommand", CiaoruoziCommand,
"CvCommand", ColorCommand,
"DiarioCommand", CvCommand,
"Mp3Command", DiarioCommand,
"PauseCommand", Mp3Command,
"PingCommand", PauseCommand,
"PlayCommand", PingCommand,
"PlaymodeCommand", PlayCommand,
"QueueCommand", PlaymodeCommand,
"RageCommand", QueueCommand,
"ReminderCommand", RageCommand,
"ShipCommand", ReminderCommand,
"SkipCommand", ShipCommand,
"SmecdsCommand", SkipCommand,
"SummonCommand", SmecdsCommand,
"VideochannelCommand", SummonCommand,
"DnditemCommand", VideochannelCommand,
"DndspellCommand", DnditemCommand,
"TriviaCommand", DndspellCommand,
"MmCommand", TriviaCommand,
"ZawarudoCommand" MmCommand,
ZawarudoCommand
] ]
__all__ = [command.__name__ for command in commands]

View file

@ -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()

26
royalnet/run.py Normal file
View file

@ -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()

View file

@ -30,7 +30,8 @@ setuptools.setup(
"markdown2>=2.3.8", "markdown2>=2.3.8",
"mcstatus>=2.2.1", "mcstatus>=2.2.1",
"sortedcontainers>=2.1.0", "sortedcontainers>=2.1.0",
"sentry-sdk>=0.11.1"], "sentry-sdk>=0.11.1",
"click>=7.0"],
python_requires=">=3.7", python_requires=">=3.7",
classifiers=[ classifiers=[
"Development Status :: 3 - Alpha", "Development Status :: 3 - Alpha",