From f7dec4d8cfdda3846b379cb0e419aad7fa15a363 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Tue, 2 Apr 2019 11:27:21 +0200 Subject: [PATCH] Rename interface_alchemy to the simpler alchemy --- royalnet/bots/telegram.py | 2 +- royalnet/commands/debug_create.py | 2 +- royalnet/commands/sync.py | 15 +++++++-------- royalnet/utils/call.py | 4 ++-- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/royalnet/bots/telegram.py b/royalnet/bots/telegram.py index 6568e3eb..e7542094 100644 --- a/royalnet/bots/telegram.py +++ b/royalnet/bots/telegram.py @@ -45,7 +45,7 @@ class TelegramBot: class TelegramCall(Call): interface_name = "telegram" interface_obj = self - interface_alchemy = self.alchemy + alchemy = self.alchemy async def reply(call, text: str): await asyncify(call.channel.send_message, text, parse_mode="HTML") diff --git a/royalnet/commands/debug_create.py b/royalnet/commands/debug_create.py index 7e1021b0..940899e2 100644 --- a/royalnet/commands/debug_create.py +++ b/royalnet/commands/debug_create.py @@ -10,7 +10,7 @@ class DebugCreateCommand(Command): require_alchemy_tables = {Royal} 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.commit() await call.reply(f"✅ Utente {royal} creato!") diff --git a/royalnet/commands/sync.py b/royalnet/commands/sync.py index 6b0d9793..aece8edb 100644 --- a/royalnet/commands/sync.py +++ b/royalnet/commands/sync.py @@ -21,19 +21,19 @@ class SyncCommand(Command): if user is None: raise ValueError("Trying to sync a None user.") # 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: await call.reply("⚠️ Non esiste alcun account Royalnet con quel nome.") # 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: # Create a Telegram to connect to the Royal # Avatar is WIP - telegram = call.interface_alchemy.Telegram(royal=royal, - tg_id=user.id, - tg_first_name=user.first_name, - tg_last_name=user.last_name, - tg_username=user.username) + telegram = call.alchemy.Telegram(royal=royal, + tg_id=user.id, + tg_first_name=user.first_name, + tg_last_name=user.last_name, + tg_username=user.username) call.session.add(telegram) await call.reply(f"✅ Connessione completata: {str(royal)}{str(telegram)}") else: @@ -45,4 +45,3 @@ class SyncCommand(Command): await call.reply(f"✅ Dati di {str(telegram)} aggiornati.") # Commit the session await asyncify(call.session.commit()) - # Notify the user diff --git a/royalnet/utils/call.py b/royalnet/utils/call.py index 2fe4ddf2..c21c06a2 100644 --- a/royalnet/utils/call.py +++ b/royalnet/utils/call.py @@ -15,7 +15,7 @@ class Call: # These parameters / methods should be overridden interface_name = NotImplemented interface_obj = NotImplemented - interface_alchemy: "Alchemy" = NotImplemented + alchemy: "Alchemy" = NotImplemented async def reply(self, text: str): """Send a text message to the channel the call was made.""" @@ -37,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(None, self.interface_alchemy.Session) + self.session = await loop.run_in_executor(None, self.alchemy.Session) async def session_end(self): if not self.session: