1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 19:44:20 +00:00

Realize everything you were doing was a mistake and rollback

This commit is contained in:
Steffo 2019-04-01 15:38:59 +02:00
parent 7100193bd1
commit 7beb2fb193
2 changed files with 31 additions and 4 deletions

26
royalnet/commands/sync.py Normal file
View file

@ -0,0 +1,26 @@
import typing
from telegram import Update, User
from ..utils import Command, CommandArgs, Call
from ..database.tables import Royal
class SyncCommand(Command):
command_name = "sync"
command_title = "Connect your current account to Royalnet"
require_alchemy_tables = [Royal]
async def common(self, call: Call, args: CommandArgs):
raise NotImplementedError()
async def telegram(self, call: Call, args: CommandArgs):
update: Update = args.kwargs["update"]
# Find the user
user: typing.Optional[User] = update.effective_user
if user is None:
raise ValueError("Trying to sync a None user.")
# Find the Royal
royal = call.session.query(call.interface_alchemy.Royal).filter_by(username=args[0]).one_or_none()
if royal is None:
await call.reply("⚠️ Non esiste alcun account Royalnet con quel nome.")

View file

@ -2,7 +2,8 @@ import typing
import asyncio
from ..network.messages import Message
from .command import Command, CommandArgs
from ..database import Alchemy
if typing.TYPE_CHECKING:
from ..database import Alchemy
loop = asyncio.get_event_loop()
@ -14,7 +15,7 @@ class Call:
# These parameters / methods should be overridden
interface_name = NotImplemented
interface_obj = NotImplemented
interface_alchemy: Alchemy = NotImplemented
interface_alchemy: "Alchemy" = NotImplemented
async def reply(self, text: str):
"""Send a text message to the channel the call was made."""
@ -36,7 +37,7 @@ class Call:
async def session_init(self):
if not self.command.require_alchemy_tables:
return
self.session = await loop.run_in_executor(self.interface_alchemy.Session)
self.session = await loop.run_in_executor(None, self.interface_alchemy.Session)
async def session_end(self):
if not self.session:
@ -52,5 +53,5 @@ class Call:
try:
result = await coroutine(self.command, self, CommandArgs(*self.args, **self.kwargs))
finally:
self.session.close()
await self.session_end()
return result