mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 19:44:20 +00:00
moar db stuff
This commit is contained in:
parent
9f5f6f8fea
commit
6758555ade
2 changed files with 24 additions and 1 deletions
|
@ -106,16 +106,20 @@ def new_diario_entry(dt, text):
|
|||
session.commit()
|
||||
|
||||
|
||||
# TODO: this can be moved to a method of the LoL class
|
||||
async def update_lol(discord_id):
|
||||
# Create a new database session
|
||||
session = Session()
|
||||
# Find the user
|
||||
user = session.query(Account).filter_by(id=discord_id).join(LoL).first()
|
||||
# TODO: ewww
|
||||
for account in user.lol:
|
||||
# Find the League of Legends ID
|
||||
lid = account.id
|
||||
# Poll the League API for more information
|
||||
data = await lol.get_summoner_data("euw", summoner_id=lid)
|
||||
# Change tracker: if anything meaningful changes, set this to True
|
||||
changes = False
|
||||
# Update the user data
|
||||
account.summoner_name = data["name"]
|
||||
account.level = data["summonerLevel"]
|
||||
|
|
21
royalbot.py
21
royalbot.py
|
@ -287,7 +287,23 @@ Sintassi: `{symbol}synclol <nome evocatore>`"""
|
|||
# Update the newly added user
|
||||
await database.update_lol(thing.author.id)
|
||||
# Send some info to Discord
|
||||
await d.client.send_message(thing.channel, embed=lolaccount.generate_discord_embed())
|
||||
await d.client.send_message(thing.channel, "Successfully connected: ", embed=lolaccount.generate_discord_embed())
|
||||
|
||||
|
||||
async def job_updatelol(singletimeout=1, alltimeout=300):
|
||||
await d.client.wait_until_ready()
|
||||
while True:
|
||||
# Open a new database session
|
||||
session = database.Session()
|
||||
# Query all the LoL accounts
|
||||
users = session.query(database.LoL).all()
|
||||
# Update all the users' stats
|
||||
for user in users:
|
||||
await database.update_lol(user.parent_id)
|
||||
await asyncio.sleep(singletimeout)
|
||||
await asyncio.sleep(alltimeout)
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Init universal bot commands
|
||||
|
@ -307,5 +323,8 @@ if __name__ == "__main__":
|
|||
# Init Discord bot
|
||||
loop.create_task(d.run())
|
||||
print("Discord bot start scheduled!")
|
||||
# Init LoL stats updater
|
||||
loop.create_task(job_updatelol())
|
||||
print("LoL database updater scheduled!")
|
||||
# Run everything!
|
||||
loop.run_forever()
|
||||
|
|
Loading…
Reference in a new issue