mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-24 03:54:20 +00:00
unfinished
This commit is contained in:
parent
eeba4d8e3f
commit
8fec58827f
3 changed files with 24 additions and 3 deletions
|
@ -89,6 +89,7 @@ def new_diario_entry(dt, text):
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: improve this
|
||||||
async def update_lol(lid):
|
async def update_lol(lid):
|
||||||
# Create a new database session
|
# Create a new database session
|
||||||
session = Session()
|
session = Session()
|
||||||
|
@ -122,3 +123,5 @@ async def update_lol(lid):
|
||||||
user.lol.ttq_division = None
|
user.lol.ttq_division = None
|
||||||
# Mark the user as updated
|
# Mark the user as updated
|
||||||
user.lol.last_updated = datetime.datetime.now()
|
user.lol.last_updated = datetime.datetime.now()
|
||||||
|
# Commit the changes
|
||||||
|
session.commit()
|
2
lol.py
2
lol.py
|
@ -31,7 +31,7 @@ divisions = {
|
||||||
async def get_json(url, **kwargs):
|
async def get_json(url, **kwargs):
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
async with session.get(url, **kwargs) as response:
|
async with session.get(url, **kwargs) as response:
|
||||||
json = await session.json()
|
json = await response.json()
|
||||||
if response.status != 200:
|
if response.status != 200:
|
||||||
raise LoLAPIError(f"Riot API returned {response.status}")
|
raise LoLAPIError(f"Riot API returned {response.status}")
|
||||||
return json
|
return json
|
||||||
|
|
20
royalbot.py
20
royalbot.py
|
@ -2,6 +2,7 @@ import asyncio
|
||||||
import random
|
import random
|
||||||
import extradiscord
|
import extradiscord
|
||||||
import database
|
import database
|
||||||
|
import lol
|
||||||
import royalbotconfig
|
import royalbotconfig
|
||||||
import telegram
|
import telegram
|
||||||
|
|
||||||
|
@ -252,6 +253,7 @@ Sintassi: `{symbol}syncdiscord`"""
|
||||||
await answer(bot, thing, "✅ Account registrato con successo!")
|
await answer(bot, thing, "✅ Account registrato con successo!")
|
||||||
|
|
||||||
|
|
||||||
|
# DISCORD ONLY!
|
||||||
async def synclol(bot, thing, arguments):
|
async def synclol(bot, thing, arguments):
|
||||||
"""Connetti il tuo account di LoL all'account Royal Games!
|
"""Connetti il tuo account di LoL all'account Royal Games!
|
||||||
|
|
||||||
|
@ -259,10 +261,25 @@ Sintassi: `{symbol}synclol <nome evocatore>`"""
|
||||||
# Set status to typing
|
# Set status to typing
|
||||||
await status_typing(bot, thing)
|
await status_typing(bot, thing)
|
||||||
# Check the command syntax
|
# Check the command syntax
|
||||||
if len(arguments) != 0:
|
if len(arguments) != 1:
|
||||||
await display_help(bot, thing, synclol)
|
await display_help(bot, thing, synclol)
|
||||||
return
|
return
|
||||||
|
# Open a new database session
|
||||||
|
session = database.Session()
|
||||||
# Create a new lol account and connect it to the user
|
# Create a new lol account and connect it to the user
|
||||||
|
user = session.query(database.Account).filter_by(id=thing.author.id).first()
|
||||||
|
if user is None:
|
||||||
|
await answer(bot, thing, "⚠ Fai il login prima di sincronizzare l'account di LoL.")
|
||||||
|
return
|
||||||
|
# Create a new LoL account and link it to the user
|
||||||
|
# TODO: IMPROVE THIS
|
||||||
|
summoner_name = " ".join(arguments)
|
||||||
|
data = await lol.get_summoner_data("euw", summoner_name=summoner_name)
|
||||||
|
lolaccount = database.LoL(data["id"])
|
||||||
|
lolaccount.parentid = user.id
|
||||||
|
session.add(lolaccount)
|
||||||
|
session.commit()
|
||||||
|
database.update_lol(data["id"])
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# Init universal bot commands
|
# Init universal bot commands
|
||||||
|
@ -275,6 +292,7 @@ if __name__ == "__main__":
|
||||||
d.commands["helpme"] = helpme
|
d.commands["helpme"] = helpme
|
||||||
b.commands["cv"] = cv
|
b.commands["cv"] = cv
|
||||||
d.commands["syncdiscord"] = syncdiscord
|
d.commands["syncdiscord"] = syncdiscord
|
||||||
|
d.commands["synclol"] = synclol
|
||||||
# Init Telegram bot
|
# Init Telegram bot
|
||||||
loop.create_task(b.run())
|
loop.create_task(b.run())
|
||||||
print("Telegram bot start scheduled!")
|
print("Telegram bot start scheduled!")
|
||||||
|
|
Loading…
Reference in a new issue