mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-27 13:34:28 +00:00
Realize everything you were doing was a mistake and rollback
This commit is contained in:
parent
7100193bd1
commit
7beb2fb193
2 changed files with 31 additions and 4 deletions
26
royalnet/commands/sync.py
Normal file
26
royalnet/commands/sync.py
Normal 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.")
|
|
@ -2,6 +2,7 @@ import typing
|
||||||
import asyncio
|
import asyncio
|
||||||
from ..network.messages import Message
|
from ..network.messages import Message
|
||||||
from .command import Command, CommandArgs
|
from .command import Command, CommandArgs
|
||||||
|
if typing.TYPE_CHECKING:
|
||||||
from ..database import Alchemy
|
from ..database import Alchemy
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,7 +15,7 @@ class Call:
|
||||||
# These parameters / methods should be overridden
|
# These parameters / methods should be overridden
|
||||||
interface_name = NotImplemented
|
interface_name = NotImplemented
|
||||||
interface_obj = NotImplemented
|
interface_obj = NotImplemented
|
||||||
interface_alchemy: Alchemy = NotImplemented
|
interface_alchemy: "Alchemy" = NotImplemented
|
||||||
|
|
||||||
async def reply(self, text: str):
|
async def reply(self, text: str):
|
||||||
"""Send a text message to the channel the call was made."""
|
"""Send a text message to the channel the call was made."""
|
||||||
|
@ -36,7 +37,7 @@ class Call:
|
||||||
async def session_init(self):
|
async def session_init(self):
|
||||||
if not self.command.require_alchemy_tables:
|
if not self.command.require_alchemy_tables:
|
||||||
return
|
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):
|
async def session_end(self):
|
||||||
if not self.session:
|
if not self.session:
|
||||||
|
@ -52,5 +53,5 @@ class Call:
|
||||||
try:
|
try:
|
||||||
result = await coroutine(self.command, self, CommandArgs(*self.args, **self.kwargs))
|
result = await coroutine(self.command, self, CommandArgs(*self.args, **self.kwargs))
|
||||||
finally:
|
finally:
|
||||||
self.session.close()
|
await self.session_end()
|
||||||
return result
|
return result
|
||||||
|
|
Loading…
Reference in a new issue