mirror of
https://github.com/RYGhub/royalnet.git
synced 2025-02-17 10:53:57 +00:00
Rename interface_alchemy to the simpler alchemy
This commit is contained in:
parent
59baf31dfe
commit
f7dec4d8cf
4 changed files with 11 additions and 12 deletions
|
@ -45,7 +45,7 @@ class TelegramBot:
|
||||||
class TelegramCall(Call):
|
class TelegramCall(Call):
|
||||||
interface_name = "telegram"
|
interface_name = "telegram"
|
||||||
interface_obj = self
|
interface_obj = self
|
||||||
interface_alchemy = self.alchemy
|
alchemy = self.alchemy
|
||||||
|
|
||||||
async def reply(call, text: str):
|
async def reply(call, text: str):
|
||||||
await asyncify(call.channel.send_message, text, parse_mode="HTML")
|
await asyncify(call.channel.send_message, text, parse_mode="HTML")
|
||||||
|
|
|
@ -10,7 +10,7 @@ class DebugCreateCommand(Command):
|
||||||
require_alchemy_tables = {Royal}
|
require_alchemy_tables = {Royal}
|
||||||
|
|
||||||
async def common(self, call: Call, args: CommandArgs):
|
async def common(self, call: Call, args: CommandArgs):
|
||||||
royal = call.interface_alchemy.Royal(username=args[0], role="Member")
|
royal = call.alchemy.Royal(username=args[0], role="Member")
|
||||||
call.session.add(royal)
|
call.session.add(royal)
|
||||||
call.session.commit()
|
call.session.commit()
|
||||||
await call.reply(f"✅ Utente <code>{royal}</code> creato!")
|
await call.reply(f"✅ Utente <code>{royal}</code> creato!")
|
||||||
|
|
|
@ -21,19 +21,19 @@ class SyncCommand(Command):
|
||||||
if user is None:
|
if user is None:
|
||||||
raise ValueError("Trying to sync a None user.")
|
raise ValueError("Trying to sync a None user.")
|
||||||
# Find the Royal
|
# Find the Royal
|
||||||
royal = await asyncify(call.session.query(call.interface_alchemy.Royal).filter_by(username=args[0]).one_or_none)
|
royal = await asyncify(call.session.query(call.alchemy.Royal).filter_by(username=args[0]).one_or_none)
|
||||||
if royal is None:
|
if royal is None:
|
||||||
await call.reply("⚠️ Non esiste alcun account Royalnet con quel nome.")
|
await call.reply("⚠️ Non esiste alcun account Royalnet con quel nome.")
|
||||||
# Find if the user is already synced
|
# Find if the user is already synced
|
||||||
telegram = await asyncify(call.session.query(call.interface_alchemy.Telegram).filter_by(tg_id=user.id).one_or_none)
|
telegram = await asyncify(call.session.query(call.alchemy.Telegram).filter_by(tg_id=user.id).one_or_none)
|
||||||
if telegram is None:
|
if telegram is None:
|
||||||
# Create a Telegram to connect to the Royal
|
# Create a Telegram to connect to the Royal
|
||||||
# Avatar is WIP
|
# Avatar is WIP
|
||||||
telegram = call.interface_alchemy.Telegram(royal=royal,
|
telegram = call.alchemy.Telegram(royal=royal,
|
||||||
tg_id=user.id,
|
tg_id=user.id,
|
||||||
tg_first_name=user.first_name,
|
tg_first_name=user.first_name,
|
||||||
tg_last_name=user.last_name,
|
tg_last_name=user.last_name,
|
||||||
tg_username=user.username)
|
tg_username=user.username)
|
||||||
call.session.add(telegram)
|
call.session.add(telegram)
|
||||||
await call.reply(f"✅ Connessione completata: <code>{str(royal)}</code> ⬌ <code>{str(telegram)}</code>")
|
await call.reply(f"✅ Connessione completata: <code>{str(royal)}</code> ⬌ <code>{str(telegram)}</code>")
|
||||||
else:
|
else:
|
||||||
|
@ -45,4 +45,3 @@ class SyncCommand(Command):
|
||||||
await call.reply(f"✅ Dati di <code>{str(telegram)}</code> aggiornati.")
|
await call.reply(f"✅ Dati di <code>{str(telegram)}</code> aggiornati.")
|
||||||
# Commit the session
|
# Commit the session
|
||||||
await asyncify(call.session.commit())
|
await asyncify(call.session.commit())
|
||||||
# Notify the user
|
|
||||||
|
|
|
@ -15,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
|
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."""
|
||||||
|
@ -37,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(None, self.interface_alchemy.Session)
|
self.session = await loop.run_in_executor(None, self.alchemy.Session)
|
||||||
|
|
||||||
async def session_end(self):
|
async def session_end(self):
|
||||||
if not self.session:
|
if not self.session:
|
||||||
|
|
Loading…
Add table
Reference in a new issue