diff --git a/royalpack/__main__.py b/royalpack/__main__.py index 8db47439..f62b35f9 100644 --- a/royalpack/__main__.py +++ b/royalpack/__main__.py @@ -83,11 +83,37 @@ register_telegram(tg_router, commands.fiorygi_transactions_other, ["transactions register_telegram(tg_router, commands.fiorygi_dig, ["dig"], r"(?P[a-z0-9-]+)") register_telegram(tg_router, commands.fiorygi_bury, ["bury"], r"(?P[a-z0-9-]+)\s+(?P[0-9]+)(?:\s+(?P.+))?") register_telegram(tg_router, commands.version, ["version"]) -register_telegram(tg_router, commands.cv, ["cv"]) +register_telegram(tg_router, commands.cv, ["cv", "civù"]) ds_router = engi.Router() +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"]) register_discord(ds_router, commands.ping, ["ping"]) +register_discord(ds_router, commands.ship, ["ship"], r"(?P[A-Za-z]+)[\s+&]+(?P[A-Za-z]+)") +register_discord(ds_router, commands.emojify, ["emojify"], r"(?P.+)") +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[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.+)") +register_discord(ds_router, commands.smecds, ["smecds"]) +register_discord(ds_router, commands.man, ["man", "help"], r"(?P[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\S+)") +register_discord(ds_router, commands.fiorygi_give, ["give"], r"(?P\S+)\s+(?P[0-9]+)\s+(?P.+)") +register_discord(ds_router, commands.fiorygi_magick, ["magick"], r"(?P\S+)\s+(?P[0-9]+)\s+(?P.+)") +register_discord(ds_router, commands.fiorygi_transactions_self, ["transactions"]) +register_discord(ds_router, commands.fiorygi_transactions_other, ["transactions"], r"(?P\S+)") +register_discord(ds_router, commands.fiorygi_dig, ["dig"], r"(?P[a-z0-9-]+)") +register_discord(ds_router, commands.fiorygi_bury, ["bury"], r"(?P[a-z0-9-]+)\s+(?P[0-9]+)(?:\s+(?P.+))?") +register_discord(ds_router, commands.version, ["version"]) pda.implementations["telethon.1"].register_conversation(tg_router) pda.implementations["discordpy.2"].register_conversation(ds_router) diff --git a/royalpack/commands/login.py b/royalpack/commands/login.py index 1711ff32..ffda3b3d 100644 --- a/royalpack/commands/login.py +++ b/royalpack/commands/login.py @@ -1,9 +1,11 @@ +import discord import royalnet.royaltyping as t import royalnet.engineer as engi import sqlalchemy.orm as so import royalpack.database as db import royalpack.config as cfg import royalnet_telethon.bullet.contents +import royalnet_discordpy import aiohttp import asyncio import logging @@ -84,6 +86,16 @@ async def login(*, _msg: engi.Message, _session: so.Session, _imp, **__): log.debug(f"Done, notifying the user...") await private.send_message(text=f"↔️ Sincronizzazione con Telegram riuscita! Sei loggato come {tg.mention()}!") + elif isinstance(_imp, royalnet_discordpy.DiscordpyPDAImplementation): + sender = await _msg.sender + tg = await register_user_discord(session=_session, user_info=ui, discord_user=sender._user) + + log.debug(f"Committing session...") + _session.commit() + + log.debug(f"Done, notifying the user...") + await private.send_message(text=f"↔️ Sincronizzazione con Telegram riuscita! Sei loggato come {tg.mention()}!") + async def enforce_private_message(msg: engi.Message) -> engi.Channel: """ @@ -314,4 +326,31 @@ async def register_user_telethon( return tg +async def register_user_discord( + session: so.Session, + user_info: dict[str, t.Any], + discord_user: discord.User, +) -> db.DiscordAccount: + """ + Sync an user's Discord account via a Discord.py message. + + :param session: The :class:`~.so.Session` to use. + :param user_info: The user_info obtained by the Identity Provider. + :param discord_user: The Discord.py user to base the user data on. + :return: The created/updated :class:`~.db.DiscordAccount` + """ + + log.debug("Syncing telethon user...") + + ds = db.DiscordAccount( + user_fk=user_info["sub"], + id=discord_user.id, + username=discord_user.name, + discriminator=discord_user.discriminator, + avatar_url=str(discord_user.avatar_url), + ) + session.merge(ds) + return ds + + __all__ = ("login",)