mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-27 13:34:28 +00:00
Do... stuff?
This commit is contained in:
parent
4656ab92a9
commit
65b965ed4c
7 changed files with 31 additions and 12 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -9,3 +9,4 @@ opusfiles/
|
||||||
ignored/
|
ignored/
|
||||||
markovmodels/
|
markovmodels/
|
||||||
logs/
|
logs/
|
||||||
|
royalnet.egg-info/
|
||||||
|
|
|
@ -10,7 +10,7 @@ loop = asyncio.get_event_loop()
|
||||||
commands = [PingCommand, ShipCommand, SmecdsCommand, ColorCommand, CiaoruoziCommand, DebugCreateCommand, SyncCommand]
|
commands = [PingCommand, ShipCommand, SmecdsCommand, ColorCommand, CiaoruoziCommand, DebugCreateCommand, SyncCommand]
|
||||||
|
|
||||||
master = RoyalnetServer("localhost", 1234, "sas")
|
master = RoyalnetServer("localhost", 1234, "sas")
|
||||||
tg_bot = TelegramBot(os.environ["TG_AK"], "localhost:1234", "sas", commands, "sqlite://")
|
tg_bot = TelegramBot(os.environ["TG_AK"], "localhost:1234", "sas", commands, os.environ["DB_PATH"])
|
||||||
loop.create_task(master.run())
|
loop.create_task(master.run())
|
||||||
loop.create_task(tg_bot.run())
|
loop.create_task(tg_bot.run())
|
||||||
print("Starting loop...")
|
print("Starting loop...")
|
||||||
|
|
|
@ -13,4 +13,4 @@ class DebugCreateCommand(Command):
|
||||||
royal = call.interface_alchemy.Royal(username=args[0], role="Member")
|
royal = call.interface_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 {royal} creato!")
|
await call.reply(f"✅ Utente <code>{royal}</code> creato!")
|
||||||
|
|
|
@ -24,6 +24,9 @@ class SyncCommand(Command):
|
||||||
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.interface_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
|
||||||
|
telegram = await asyncify(call.session.query(call.interface_alchemy.Telegram).filter_by(tg_id=user.id).one_or_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.interface_alchemy.Telegram(royal=royal,
|
||||||
|
@ -32,5 +35,14 @@ class SyncCommand(Command):
|
||||||
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>")
|
||||||
|
else:
|
||||||
|
# Update the Telegram data
|
||||||
|
# Avatar is WIP
|
||||||
|
telegram.tg_first_name = user.first_name
|
||||||
|
telegram.tg_last_name = user.last_name
|
||||||
|
telegram.tg_username = user.username
|
||||||
|
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
|
||||||
|
|
|
@ -10,7 +10,9 @@ loop = asyncio.get_event_loop()
|
||||||
|
|
||||||
|
|
||||||
class Alchemy:
|
class Alchemy:
|
||||||
def __init__(self, database_uri: str = "sqlite://", tables: typing.Optional[typing.Set] = None):
|
def __init__(self, database_uri: str, tables: typing.Optional[typing.Set] = None):
|
||||||
|
if database_uri.startswith("sqlite"):
|
||||||
|
raise NotImplementedError("Support for sqlite databases is currently missing")
|
||||||
self.engine = create_engine(database_uri)
|
self.engine = create_engine(database_uri)
|
||||||
self.Base = declarative_base(bind=self.engine)
|
self.Base = declarative_base(bind=self.engine)
|
||||||
self.Session = sessionmaker(bind=self.engine)
|
self.Session = sessionmaker(bind=self.engine)
|
||||||
|
|
|
@ -17,4 +17,4 @@ class Royal:
|
||||||
return f"<Royal {self.username}>"
|
return f"<Royal {self.username}>"
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.username
|
return f"royalnet:{self.username}"
|
||||||
|
|
|
@ -5,6 +5,7 @@ from sqlalchemy import Column, \
|
||||||
LargeBinary, \
|
LargeBinary, \
|
||||||
ForeignKey
|
ForeignKey
|
||||||
from sqlalchemy.orm import relationship
|
from sqlalchemy.orm import relationship
|
||||||
|
from .royals import Royal
|
||||||
|
|
||||||
|
|
||||||
class Telegram:
|
class Telegram:
|
||||||
|
@ -23,6 +24,9 @@ class Telegram:
|
||||||
return f"<Telegram {str(self)}>"
|
return f"<Telegram {str(self)}>"
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
return f"telegram:{self.mention()}"
|
||||||
|
|
||||||
|
def mention(self) -> str:
|
||||||
if self.tg_username is not None:
|
if self.tg_username is not None:
|
||||||
return f"@{self.tg_username}"
|
return f"@{self.tg_username}"
|
||||||
elif self.tg_last_name is not None:
|
elif self.tg_last_name is not None:
|
||||||
|
|
Loading…
Reference in a new issue