1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 11:34:18 +00:00
This commit is contained in:
Steffo 2020-09-15 22:14:41 +02:00
parent 1a21e91681
commit 47cbff1fca
3 changed files with 36 additions and 26 deletions

View file

@ -5,7 +5,7 @@
[tool.poetry]
name = "royalnet"
version = "5.11.10"
version = "5.11.11"
description = "A multipurpose bot and web framework"
authors = ["Stefano Pigozzi <ste.pigozzi@gmail.com>"]
license = "AGPL-3.0+"

View file

@ -95,8 +95,7 @@ def run(config_file: str):
else:
log.debug("__serfs__: Configured")
def configure_serf(n: str, module):
class_ = module.__getattribute__(f"{n}Serf")
def configure_serf(n: str, module, class_: Type[rs.Serf]):
serf_cfg = serfs_cfg.get(n)
if module is None:
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)
log.info(f"Serf.{n}: Enabled")
configure_serf("Telegram", rst)
configure_serf("Discord", rsd)
if rst is not None:
configure_serf("Telegram", rst, rst.TelegramSerf)
if rsd is not None:
configure_serf("Discord", rsd, rsd.DiscordSerf)
# Constellation
constellation_cfg = config.get("Constellation")

View file

@ -1,6 +1,15 @@
import royalnet.commands as rc
import royalnet.serf.discord as rsd
import royalnet.serf.telegram as rst
try:
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
from ..tables.discord import Discord
from ..tables.telegram import Telegram
@ -14,25 +23,25 @@ class RoyalnetsyncCommand(rc.Command):
syntax: str = "{username} {password}"
async def run(self, args: rc.CommandArgs, data: rc.CommandData) -> None:
author = await data.get_author(error_if_none=False)
if author is not None:
raise rc.UserError(f"This account is already connected to {author}!")
username = args[0]
password = " ".join(args[1:])
user = await data.find_user(username)
if user is None:
raise rc.UserError("No such user.")
try:
successful = user.test_password(password)
except ValueError:
raise rc.UserError(f"User {user} has no password set!")
if not successful:
raise rc.InvalidInputError(f"Invalid password!")
async with data.session_acm() as session:
if isinstance(self.serf, rst.TelegramSerf):
author = await data.find_author(session=session, required=False)
if author is not None:
raise rc.UserError(f"This account is already connected to {author}!")
username = args[0]
password = " ".join(args[1:])
user = await data.find_user(session=session, identifier=username)
if user is None:
raise rc.UserError("No such user.")
try:
successful = user.test_password(password)
except ValueError:
raise rc.UserError(f"User {user} has no password set!")
if not successful:
raise rc.InvalidInputError(f"Invalid password!")
if rst is not None and isinstance(self.serf, rst.TelegramSerf):
import telegram
message: telegram.Message = data.message
from_user: telegram.User = message.from_user
@ -58,7 +67,7 @@ class RoyalnetsyncCommand(rc.Command):
await ru.asyncify(session.commit)
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
message: discord.Message = data.message
ds_author: discord.User = message.author