mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 19:44:20 +00:00
5.11.11
This commit is contained in:
parent
1a21e91681
commit
47cbff1fca
3 changed files with 36 additions and 26 deletions
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "royalnet"
|
name = "royalnet"
|
||||||
version = "5.11.10"
|
version = "5.11.11"
|
||||||
description = "A multipurpose bot and web framework"
|
description = "A multipurpose bot and web framework"
|
||||||
authors = ["Stefano Pigozzi <ste.pigozzi@gmail.com>"]
|
authors = ["Stefano Pigozzi <ste.pigozzi@gmail.com>"]
|
||||||
license = "AGPL-3.0+"
|
license = "AGPL-3.0+"
|
||||||
|
|
|
@ -95,8 +95,7 @@ def run(config_file: str):
|
||||||
else:
|
else:
|
||||||
log.debug("__serfs__: Configured")
|
log.debug("__serfs__: Configured")
|
||||||
|
|
||||||
def configure_serf(n: str, module):
|
def configure_serf(n: str, module, class_: Type[rs.Serf]):
|
||||||
class_ = module.__getattribute__(f"{n}Serf")
|
|
||||||
serf_cfg = serfs_cfg.get(n)
|
serf_cfg = serfs_cfg.get(n)
|
||||||
if module is None:
|
if module is None:
|
||||||
log.info(f"Serf.{n}: Not installed")
|
log.info(f"Serf.{n}: Not installed")
|
||||||
|
@ -123,8 +122,10 @@ def run(config_file: str):
|
||||||
processes[f"Serf.{n}"] = ru.RoyalnetProcess(serf_constructor, None)
|
processes[f"Serf.{n}"] = ru.RoyalnetProcess(serf_constructor, None)
|
||||||
log.info(f"Serf.{n}: Enabled")
|
log.info(f"Serf.{n}: Enabled")
|
||||||
|
|
||||||
configure_serf("Telegram", rst)
|
if rst is not None:
|
||||||
configure_serf("Discord", rsd)
|
configure_serf("Telegram", rst, rst.TelegramSerf)
|
||||||
|
if rsd is not None:
|
||||||
|
configure_serf("Discord", rsd, rsd.DiscordSerf)
|
||||||
|
|
||||||
# Constellation
|
# Constellation
|
||||||
constellation_cfg = config.get("Constellation")
|
constellation_cfg = config.get("Constellation")
|
||||||
|
|
|
@ -1,6 +1,15 @@
|
||||||
import royalnet.commands as rc
|
import royalnet.commands as rc
|
||||||
import royalnet.serf.discord as rsd
|
|
||||||
|
try:
|
||||||
import royalnet.serf.telegram as rst
|
import royalnet.serf.telegram as rst
|
||||||
|
except ImportError:
|
||||||
|
rst = None
|
||||||
|
|
||||||
|
try:
|
||||||
|
import royalnet.serf.discord as rsd
|
||||||
|
except ImportError:
|
||||||
|
rsd = None
|
||||||
|
|
||||||
import royalnet.utils as ru
|
import royalnet.utils as ru
|
||||||
from ..tables.discord import Discord
|
from ..tables.discord import Discord
|
||||||
from ..tables.telegram import Telegram
|
from ..tables.telegram import Telegram
|
||||||
|
@ -14,14 +23,15 @@ class RoyalnetsyncCommand(rc.Command):
|
||||||
syntax: str = "{username} {password}"
|
syntax: str = "{username} {password}"
|
||||||
|
|
||||||
async def run(self, args: rc.CommandArgs, data: rc.CommandData) -> None:
|
async def run(self, args: rc.CommandArgs, data: rc.CommandData) -> None:
|
||||||
author = await data.get_author(error_if_none=False)
|
async with data.session_acm() as session:
|
||||||
|
author = await data.find_author(session=session, required=False)
|
||||||
if author is not None:
|
if author is not None:
|
||||||
raise rc.UserError(f"This account is already connected to {author}!")
|
raise rc.UserError(f"This account is already connected to {author}!")
|
||||||
|
|
||||||
username = args[0]
|
username = args[0]
|
||||||
password = " ".join(args[1:])
|
password = " ".join(args[1:])
|
||||||
|
|
||||||
user = await data.find_user(username)
|
user = await data.find_user(session=session, identifier=username)
|
||||||
if user is None:
|
if user is None:
|
||||||
raise rc.UserError("No such user.")
|
raise rc.UserError("No such user.")
|
||||||
try:
|
try:
|
||||||
|
@ -31,8 +41,7 @@ class RoyalnetsyncCommand(rc.Command):
|
||||||
if not successful:
|
if not successful:
|
||||||
raise rc.InvalidInputError(f"Invalid password!")
|
raise rc.InvalidInputError(f"Invalid password!")
|
||||||
|
|
||||||
async with data.session_acm() as session:
|
if rst is not None and isinstance(self.serf, rst.TelegramSerf):
|
||||||
if isinstance(self.serf, rst.TelegramSerf):
|
|
||||||
import telegram
|
import telegram
|
||||||
message: telegram.Message = data.message
|
message: telegram.Message = data.message
|
||||||
from_user: telegram.User = message.from_user
|
from_user: telegram.User = message.from_user
|
||||||
|
@ -58,7 +67,7 @@ class RoyalnetsyncCommand(rc.Command):
|
||||||
await ru.asyncify(session.commit)
|
await ru.asyncify(session.commit)
|
||||||
await data.reply(f"↔️ Account {tg_user} synced to {user}!")
|
await data.reply(f"↔️ Account {tg_user} synced to {user}!")
|
||||||
|
|
||||||
elif isinstance(self.serf, rsd.DiscordSerf):
|
elif rsd is not None and isinstance(self.serf, rsd.DiscordSerf):
|
||||||
import discord
|
import discord
|
||||||
message: discord.Message = data.message
|
message: discord.Message = data.message
|
||||||
ds_author: discord.User = message.author
|
ds_author: discord.User = message.author
|
||||||
|
|
Loading…
Reference in a new issue