2021-04-03 16:43:34 +00:00
|
|
|
import royalnet.engineer as engi
|
2021-04-17 02:19:11 +00:00
|
|
|
from royalnet.engineer import router
|
2021-04-03 16:43:34 +00:00
|
|
|
import royalnet.scrolls as sc
|
2021-04-14 02:12:54 +00:00
|
|
|
import royalnet_telethon as rt
|
2021-04-03 16:43:34 +00:00
|
|
|
import pathlib
|
2021-04-17 02:19:11 +00:00
|
|
|
import re
|
2021-04-14 02:12:54 +00:00
|
|
|
import coloredlogs
|
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-14 02:12:54 +00:00
|
|
|
coloredlogs.install(level="DEBUG", 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-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-13 22:43:19 +00:00
|
|
|
])
|
2021-04-06 01:58:55 +00:00
|
|
|
|
2021-04-17 02:19:11 +00:00
|
|
|
r = router.Router()
|
|
|
|
|
|
|
|
|
|
|
|
def register_telegram(conv, names, syntax=None):
|
|
|
|
name_regex = rf"(?:{'|'.join(names)})"
|
|
|
|
bot_regex = rf"(?:@{config['telegram.bot.username']})?"
|
|
|
|
if syntax:
|
|
|
|
syntax_regex = f" {syntax}"
|
|
|
|
else:
|
|
|
|
syntax_regex = ""
|
|
|
|
regex = rf"^/{name_regex}{bot_regex}{syntax_regex}$"
|
|
|
|
r.register_conversation(conv, names, [re.compile(regex)])
|
|
|
|
|
|
|
|
|
|
|
|
register_telegram(commands.ahnonlosoio, ["ahnonlosoio"])
|
|
|
|
register_telegram(commands.answer, ["answer"], r".+")
|
2021-04-20 00:50:25 +00:00
|
|
|
register_telegram(commands.cat, ["cat", "catto", "gatto", "nyaa", "nya"])
|
2021-04-17 02:19:11 +00:00
|
|
|
register_telegram(commands.ciaoruozi, ["ciaoruozi"])
|
|
|
|
register_telegram(commands.color, ["color"])
|
|
|
|
register_telegram(commands.ping, ["ping"])
|
|
|
|
register_telegram(commands.ship, ["ship"], r"(?P<first>[A-Za-z]+)[\s+&]+(?P<second>[A-Za-z]+)")
|
2021-04-18 14:29:59 +00:00
|
|
|
register_telegram(commands.emojify, ["emojify"], r"(?P<message>.+)")
|
2021-04-20 00:50:25 +00:00
|
|
|
register_telegram(commands.dog_any, ["dog", "doggo", "cane", "woof", "bau"])
|
2021-04-25 00:31:15 +00:00
|
|
|
register_telegram(commands.dog_breedlist, ["dog", "doggo", "cane", "woof", "bau"], r"(?:list|help|aiuto)")
|
|
|
|
register_telegram(commands.dog_breed, ["dog", "doggo", "cane", "woof", "bau"], r"(?P<breed>[A-Za-z/]+)")
|
2021-04-18 15:00:16 +00:00
|
|
|
register_telegram(commands.fortune, ["fortune"])
|
2021-04-18 15:02:32 +00:00
|
|
|
register_telegram(commands.pmots, ["pmots"])
|
2021-04-25 00:31:15 +00:00
|
|
|
register_telegram(commands.spell, ["spell", "cast"], r"(?P<spellname>.+)")
|
2021-04-18 15:18:19 +00:00
|
|
|
register_telegram(commands.smecds, ["smecds"])
|
2021-04-25 00:31:15 +00:00
|
|
|
register_telegram(commands.man, ["man", "help"], r"(?P<commandname>[A-Za-z]+)")
|
2021-04-19 03:26:20 +00:00
|
|
|
register_telegram(commands.login, ["login"])
|
2021-04-19 14:56:36 +00:00
|
|
|
register_telegram(commands.whoami, ["whoami"])
|
2021-04-25 00:31:15 +00:00
|
|
|
register_telegram(commands.fiorygi_balance_self, ["balance"])
|
|
|
|
register_telegram(commands.fiorygi_balance_other, ["balance"], r"(?P<target>\S+)")
|
|
|
|
register_telegram(commands.fiorygi_give, ["give"], r"(?P<target>\S+)\s+(?P<amount>[0-9]+)\s+(?P<reason>.+)")
|
|
|
|
register_telegram(commands.fiorygi_magick, ["magick"], r"(?P<target>\S+)\s+(?P<amount>[0-9]+)\s+(?P<reason>.+)")
|
|
|
|
register_telegram(commands.fiorygi_transactions_self, ["transactions"])
|
|
|
|
register_telegram(commands.fiorygi_transactions_other, ["transactions"], r"(?P<target>\S+)")
|
2021-04-25 21:23:24 +00:00
|
|
|
register_telegram(commands.fiorygi_dig, ["dig"], r"(?P<slug>[a-z0-9-]+)")
|
|
|
|
register_telegram(commands.fiorygi_bury, ["bury"], r"(?P<slug>[a-z0-9-]+)\s+(?P<value>[0-9]+)(?:\s+(?P<message>.+))?")
|
2021-04-25 21:33:35 +00:00
|
|
|
register_telegram(commands.version, ["version"])
|
2021-04-18 14:29:59 +00:00
|
|
|
|
2021-04-17 02:19:11 +00:00
|
|
|
|
|
|
|
pda.implementations["telethon.1"].register_conversation(r)
|
2021-04-06 01:58:55 +00:00
|
|
|
|
2021-04-03 16:43:34 +00:00
|
|
|
|
2021-04-13 22:43:19 +00:00
|
|
|
pda.run()
|