2022-03-06 16:48:16 +00:00
|
|
|
import logging
|
|
|
|
import pathlib
|
|
|
|
import re
|
|
|
|
|
|
|
|
import coloredlogs
|
2021-04-29 23:19:16 +00:00
|
|
|
import discord
|
2021-04-30 13:22:58 +00:00
|
|
|
import pkg_resources
|
2021-04-03 16:43:34 +00:00
|
|
|
import royalnet.engineer as engi
|
|
|
|
import royalnet.scrolls as sc
|
2021-04-26 02:54:02 +00:00
|
|
|
import royalnet_discordpy as rd
|
2022-03-06 16:48:16 +00:00
|
|
|
import royalnet_telethon as rt
|
2021-04-30 13:22:58 +00:00
|
|
|
import sentry_sdk.integrations.atexit
|
|
|
|
import sentry_sdk.integrations.dedupe
|
|
|
|
import sentry_sdk.integrations.modules
|
|
|
|
import sentry_sdk.integrations.threading
|
2021-04-03 16:43:34 +00:00
|
|
|
|
|
|
|
from . import commands
|
2021-04-06 01:58:55 +00:00
|
|
|
from .database import engine, base
|
2021-04-03 16:43:34 +00:00
|
|
|
|
2021-04-30 13:22:58 +00:00
|
|
|
coloredlogs.install(level="DEBUG" if __debug__ else "INFO", isatty=True)
|
2021-04-06 01:58:55 +00:00
|
|
|
config = sc.Scroll.from_file(namespace="ROYALPACK", file_path=pathlib.Path("royalpack.cfg.toml"))
|
2021-04-03 16:43:34 +00:00
|
|
|
|
2021-04-30 13:22:58 +00:00
|
|
|
if dsn := config.get("sentry.dsn", None):
|
|
|
|
logging.info("Enabling Sentry...")
|
|
|
|
sentry_sdk.init(
|
|
|
|
dsn=dsn,
|
|
|
|
debug=__debug__,
|
|
|
|
release=pkg_resources.get_distribution("royalpack").version,
|
|
|
|
environment="Development" if __debug__ else "Production",
|
|
|
|
default_integrations=False,
|
|
|
|
integrations=[
|
|
|
|
sentry_sdk.integrations.atexit.AtexitIntegration(),
|
|
|
|
sentry_sdk.integrations.dedupe.DedupeIntegration(),
|
|
|
|
sentry_sdk.integrations.modules.ModulesIntegration(),
|
|
|
|
sentry_sdk.integrations.threading.ThreadingIntegration(),
|
|
|
|
],
|
|
|
|
traces_sample_rate=1.0
|
|
|
|
)
|
|
|
|
|
2021-04-13 22:43:19 +00:00
|
|
|
engine_ = engine.lazy_engine.evaluate()
|
|
|
|
base.Base.metadata.create_all(engine_)
|
2021-04-03 16:43:34 +00:00
|
|
|
|
2021-04-13 22:43:19 +00:00
|
|
|
pda = engi.PDA(implementations=[
|
2021-04-14 02:12:54 +00:00
|
|
|
rt.TelethonPDAImplementation(
|
|
|
|
name="1",
|
|
|
|
tg_api_id=config["telegram.api.id"],
|
|
|
|
tg_api_hash=config["telegram.api.hash"],
|
|
|
|
bot_username=config["telegram.bot.username"],
|
|
|
|
bot_token=config["telegram.bot.token"],
|
2021-04-26 02:54:02 +00:00
|
|
|
),
|
|
|
|
rd.DiscordpyPDAImplementation(
|
|
|
|
name="2",
|
|
|
|
bot_token=config["discord.bot.token"],
|
2021-04-29 23:19:16 +00:00
|
|
|
intents=discord.Intents.all(),
|
2021-04-26 02:54:02 +00:00
|
|
|
),
|
2021-04-13 22:43:19 +00:00
|
|
|
])
|
2021-04-06 01:58:55 +00:00
|
|
|
|
2021-04-17 02:19:11 +00:00
|
|
|
|
2021-04-29 21:12:43 +00:00
|
|
|
def register_telegram(router, conv, names, syntax=None):
|
2021-04-17 02:19:11 +00:00
|
|
|
name_regex = rf"(?:{'|'.join(names)})"
|
|
|
|
bot_regex = rf"(?:@{config['telegram.bot.username']})?"
|
|
|
|
if syntax:
|
2021-04-25 22:42:27 +00:00
|
|
|
syntax_regex = rf"\s+{syntax}"
|
2021-04-17 02:19:11 +00:00
|
|
|
else:
|
|
|
|
syntax_regex = ""
|
|
|
|
regex = rf"^/{name_regex}{bot_regex}{syntax_regex}$"
|
2021-04-29 21:12:43 +00:00
|
|
|
router.register_conversation(conv, names, [re.compile(regex)])
|
2021-04-17 02:19:11 +00:00
|
|
|
|
|
|
|
|
2021-04-29 21:12:43 +00:00
|
|
|
def register_discord(router, conv, names, syntax=None):
|
2021-04-26 02:54:02 +00:00
|
|
|
name_regex = rf"(?:{'|'.join(names)})"
|
|
|
|
if syntax:
|
|
|
|
syntax_regex = rf"\s+{syntax}"
|
|
|
|
else:
|
|
|
|
syntax_regex = ""
|
|
|
|
prefix_regex = rf"{config['discord.bot.prefix']}"
|
|
|
|
regex = rf"^{prefix_regex}{name_regex}{syntax_regex}$"
|
2021-04-29 21:12:43 +00:00
|
|
|
router.register_conversation(conv, names, [re.compile(regex)])
|
|
|
|
|
|
|
|
|
|
|
|
tg_router = engi.Router()
|
|
|
|
|
|
|
|
register_telegram(tg_router, commands.ahnonlosoio, ["ahnonlosoio"])
|
|
|
|
register_telegram(tg_router, commands.answer, ["answer"], r".+")
|
|
|
|
register_telegram(tg_router, commands.cat, ["cat", "catto", "gatto", "nyaa", "nya"])
|
|
|
|
register_telegram(tg_router, commands.ciaoruozi, ["ciaoruozi"])
|
|
|
|
register_telegram(tg_router, commands.color, ["color"])
|
|
|
|
register_telegram(tg_router, commands.ping, ["ping"])
|
|
|
|
register_telegram(tg_router, commands.ship, ["ship"], r"(?P<first>[A-Za-z]+)[\s+&]+(?P<second>[A-Za-z]+)")
|
|
|
|
register_telegram(tg_router, commands.emojify, ["emojify"], r"(?P<message>.+)")
|
|
|
|
register_telegram(tg_router, commands.dog_any, ["dog", "doggo", "cane", "woof", "bau"])
|
|
|
|
register_telegram(tg_router, commands.dog_breedlist, ["dog", "doggo", "cane", "woof", "bau"], r"(?:list|help|aiuto)")
|
|
|
|
register_telegram(tg_router, commands.dog_breed, ["dog", "doggo", "cane", "woof", "bau"], r"(?P<breed>[A-Za-z/]+)")
|
|
|
|
register_telegram(tg_router, commands.fortune, ["fortune"])
|
|
|
|
register_telegram(tg_router, commands.pmots, ["pmots"])
|
|
|
|
register_telegram(tg_router, commands.spell, ["spell", "cast"], r"(?P<spellname>.+)")
|
|
|
|
register_telegram(tg_router, commands.smecds, ["smecds"])
|
|
|
|
register_telegram(tg_router, commands.man, ["man", "help"], r"(?P<commandname>[A-Za-z]+)")
|
|
|
|
register_telegram(tg_router, commands.login, ["login"])
|
|
|
|
register_telegram(tg_router, commands.whoami, ["whoami"])
|
|
|
|
register_telegram(tg_router, commands.fiorygi_balance_self, ["balance"])
|
|
|
|
register_telegram(tg_router, commands.fiorygi_balance_other, ["balance"], r"(?P<target>\S+)")
|
|
|
|
register_telegram(tg_router, commands.fiorygi_give, ["give"], r"(?P<target>\S+)\s+(?P<amount>[0-9]+)\s+(?P<reason>.+)")
|
2022-03-06 16:48:16 +00:00
|
|
|
register_telegram(tg_router, commands.fiorygi_magick, ["magick"],
|
|
|
|
r"(?P<target>\S+)\s+(?P<amount>[0-9]+)\s+(?P<reason>.+)")
|
2021-04-29 21:12:43 +00:00
|
|
|
register_telegram(tg_router, commands.fiorygi_transactions_self, ["transactions"])
|
|
|
|
register_telegram(tg_router, commands.fiorygi_transactions_other, ["transactions"], r"(?P<target>\S+)")
|
|
|
|
register_telegram(tg_router, commands.fiorygi_dig, ["dig"], r"(?P<slug>[a-z0-9-]+)")
|
2022-03-06 16:48:16 +00:00
|
|
|
register_telegram(tg_router, commands.fiorygi_bury, ["bury"],
|
|
|
|
r"(?P<slug>[a-z0-9-]+)\s+(?P<value>[0-9]+)(?:\s+(?P<message>.+))?")
|
2021-04-29 21:12:43 +00:00
|
|
|
register_telegram(tg_router, commands.version, ["version"])
|
2021-04-30 11:01:17 +00:00
|
|
|
register_telegram(tg_router, commands.cv, ["cv", "civù"])
|
2021-05-08 00:00:57 +00:00
|
|
|
register_telegram(tg_router, commands.rocoinflip, ["rocoinflip"], r'"(?P<teama>[^"]+)"\s+"(?P<teamb>[^"]+)"')
|
2022-08-20 23:44:38 +00:00
|
|
|
register_telegram(tg_router, commands.roll, ["roll"], r"(?P<qty>[0-9]*)d(?P<die>[0-9]+)(?P<mod>[+-][0-9]+)?")
|
2022-02-22 03:15:08 +00:00
|
|
|
register_telegram(tg_router, commands.diobot, ["diobot", "phrase"])
|
2022-03-05 16:37:46 +00:00
|
|
|
register_telegram(tg_router, commands.loginprogress, ["loginprogress"])
|
2021-04-29 21:12:43 +00:00
|
|
|
|
|
|
|
ds_router = engi.Router()
|
|
|
|
|
2021-04-30 11:01:17 +00:00
|
|
|
register_discord(ds_router, commands.ahnonlosoio, ["ahnonlosoio"])
|
|
|
|
register_discord(ds_router, commands.answer, ["answer"], r".+")
|
|
|
|
register_discord(ds_router, commands.cat, ["cat", "catto", "gatto", "nyaa", "nya"])
|
|
|
|
register_discord(ds_router, commands.ciaoruozi, ["ciaoruozi"])
|
|
|
|
register_discord(ds_router, commands.color, ["color"])
|
2021-04-29 21:12:43 +00:00
|
|
|
register_discord(ds_router, commands.ping, ["ping"])
|
2021-04-30 11:01:17 +00:00
|
|
|
register_discord(ds_router, commands.ship, ["ship"], r"(?P<first>[A-Za-z]+)[\s+&]+(?P<second>[A-Za-z]+)")
|
|
|
|
register_discord(ds_router, commands.emojify, ["emojify"], r"(?P<message>.+)")
|
|
|
|
register_discord(ds_router, commands.dog_any, ["dog", "doggo", "cane", "woof", "bau"])
|
|
|
|
register_discord(ds_router, commands.dog_breedlist, ["dog", "doggo", "cane", "woof", "bau"], r"(?:list|help|aiuto)")
|
|
|
|
register_discord(ds_router, commands.dog_breed, ["dog", "doggo", "cane", "woof", "bau"], r"(?P<breed>[A-Za-z/]+)")
|
|
|
|
register_discord(ds_router, commands.fortune, ["fortune"])
|
|
|
|
register_discord(ds_router, commands.pmots, ["pmots"])
|
|
|
|
register_discord(ds_router, commands.spell, ["spell", "cast"], r"(?P<spellname>.+)")
|
|
|
|
register_discord(ds_router, commands.smecds, ["smecds"])
|
|
|
|
register_discord(ds_router, commands.man, ["man", "help"], r"(?P<commandname>[A-Za-z]+)")
|
|
|
|
register_discord(ds_router, commands.login, ["login"])
|
|
|
|
register_discord(ds_router, commands.whoami, ["whoami"])
|
|
|
|
register_discord(ds_router, commands.fiorygi_balance_self, ["balance"])
|
|
|
|
register_discord(ds_router, commands.fiorygi_balance_other, ["balance"], r"(?P<target>\S+)")
|
|
|
|
register_discord(ds_router, commands.fiorygi_give, ["give"], r"(?P<target>\S+)\s+(?P<amount>[0-9]+)\s+(?P<reason>.+)")
|
2022-03-06 16:48:16 +00:00
|
|
|
register_discord(ds_router, commands.fiorygi_magick, ["magick"],
|
|
|
|
r"(?P<target>\S+)\s+(?P<amount>[0-9]+)\s+(?P<reason>.+)")
|
2021-04-30 11:01:17 +00:00
|
|
|
register_discord(ds_router, commands.fiorygi_transactions_self, ["transactions"])
|
|
|
|
register_discord(ds_router, commands.fiorygi_transactions_other, ["transactions"], r"(?P<target>\S+)")
|
|
|
|
register_discord(ds_router, commands.fiorygi_dig, ["dig"], r"(?P<slug>[a-z0-9-]+)")
|
2022-03-06 16:48:16 +00:00
|
|
|
register_discord(ds_router, commands.fiorygi_bury, ["bury"],
|
|
|
|
r"(?P<slug>[a-z0-9-]+)\s+(?P<value>[0-9]+)(?:\s+(?P<message>.+))?")
|
2021-04-30 11:01:17 +00:00
|
|
|
register_discord(ds_router, commands.version, ["version"])
|
2021-05-08 00:00:57 +00:00
|
|
|
register_discord(ds_router, commands.rocoinflip, ["rocoinflip"], r'"(?P<teama>[^"]+)"\s+"(?P<teamb>[^"]+)"')
|
2021-05-11 02:05:20 +00:00
|
|
|
register_discord(ds_router, commands.hack, ["hack"], r'(?P<activity>.+)')
|
2022-02-22 03:15:08 +00:00
|
|
|
register_discord(ds_router, commands.diobot, ["diobot", "phrase"])
|
2022-03-05 16:37:46 +00:00
|
|
|
register_discord(ds_router, commands.loginprogress, ["loginprogress"])
|
2021-04-29 21:12:43 +00:00
|
|
|
|
2022-08-20 23:44:56 +00:00
|
|
|
# noinspection PyTypeChecker
|
|
|
|
tg_pdai: engi.ConversationListImplementation = pda.implementations["telethon.1"]
|
|
|
|
# noinspection PyTypeChecker
|
|
|
|
ds_pdai: engi.ConversationListImplementation = pda.implementations["discordpy.2"]
|
|
|
|
|
|
|
|
tg_pdai.register_conversation(tg_router)
|
|
|
|
ds_pdai.register_conversation(ds_router)
|
2021-04-06 01:58:55 +00:00
|
|
|
|
2021-04-13 22:43:19 +00:00
|
|
|
pda.run()
|