1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-27 13:34:28 +00:00

let's try this again

This commit is contained in:
Steffo 2017-10-08 00:43:41 +02:00
parent 7323981c52
commit f39b077844
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG key ID: C27544372FBB445D
4 changed files with 5 additions and 123 deletions

7
db.py
View file

@ -61,6 +61,7 @@ class Steam(Base):
steam_id = Column(String, primary_key=True)
persona_name = Column(String)
avatar_hex = Column(String)
trade_token = Column(String)
def __repr__(self):
return f"<Steam {self.steam_id}>"
@ -114,9 +115,11 @@ class RocketLeague(Base):
rl = session.query(RocketLeague).filter(RocketLeague.steam_id == steam_id).first()
if rl is not None:
return None
r = requests.get(f"https://api.rocketleaguestats.com/v1/player?apikey={config['Rocket League']['rlstats_api_key']}&unique_id={steam_id}&platform_id=1")
if r.status_code != 200:
r = requests.get(f"https://api.rocketleaguestats.com/v1/player?apikey={config['Rocket League']['rlstats_api_key']}&unique_id={str(steam_id)}&platform_id=1")
if r.status_code == 404:
return None
elif r.status_code == 500:
raise RequestError("Rocket League Stats returned {r.status_code}")
new_record = RocketLeague(steam_id=steam_id)
new_record.update()
return new_record

View file

@ -1,21 +0,0 @@
from db import session, Steam, RocketLeague
from time import sleep
def check_for_new_players():
steam_users = session.query(Steam).all()
for user in steam_users:
print(user)
rl = RocketLeague.check_and_create(user.steam_id)
if rl is not None:
session.add(rl)
sleep(1)
session.commit()
def update_existing_players():
rocket_league_players = session.query(RocketLeague).all()
for player in rocket_league_players:
player.update()
session.commit()
if __name__ == "__main__":
check_for_new_players()

View file

@ -1,48 +0,0 @@
from flask import Flask
from flask import session as flask_session
from flask_openid import OpenID
from db import session, Royal, Steam
import requests
import re
# Init the config reader
import configparser
config = configparser.ConfigParser()
config.read("config.ini")
# Init Flask and Flask_OpenID
app = Flask(__name__)
app.secret_key = config["Steam"]["secret_key"]
oid = OpenID(app)
@app.route("/login/<int:royal_id>")
@oid.loginhandler
def page_steam_login(royal_id):
flask_session["royal_id"] = royal_id
return oid.try_login("http://steamcommunity.com/openid")
@oid.after_login
def page_after_login(response):
steam_id = re.search("https?://steamcommunity\.com/openid/id/(.+)", response.identity_url).group(1)
db_steam = session.query(Steam).filter(Steam.steam_id == steam_id).first()
if db_steam is None:
db_steam = Steam(royal_id=flask_session["royal_id"],
steam_id=steam_id)
session.add(db_steam)
db_steam.update()
session.commit()
return "Account Steam collegato con successo!"
else:
return "Il tuo account Steam è già collegato."
@app.route("/update/<int:royal_id>")
def page_steam_update(royal_id):
db_steam = session.query(Steam).filter(Steam.royal_id == royal_id).first()
db_steam.update()
return "Dati account aggiornati."
if __name__ == "__main__":
app.run(host="0.0.0.0", port="1234")

View file

@ -1,52 +0,0 @@
from telegram import Bot, Update
from telegram.ext import Updater, CommandHandler
import logging
from db import session, Royal, Telegram
# Init the config reader
import configparser
config = configparser.ConfigParser()
config.read("config.ini")
# Init the logger
logging.basicConfig(level=logging.DEBUG, format="[%(levelname)s] %(asctime)s | %(message)s")
# Init the Telegram Bot
updater = Updater(token=config["Telegram"]["bot_token"])
def message_sync(bot: Bot, update: Update):
tg_user = update.message.from_user
db_user = session.query(Telegram).filter(Telegram.telegram_id == tg_user.id).first()
if db_user is None:
# Find the royals table record matching the command argument
try:
tg_royal = update.message.text.split(" ", 1)[1]
except IndexError:
bot.send_message(update.message.chat.id, "⚠️ Non hai specificato nessun username!")
return
db_royal = session.query(Royal).filter(Royal.username == tg_royal).first()
if db_royal is None:
bot.send_message(update.message.chat.id, "⚠️ L'username che hai specificato non è valido!")
return
# Create the new user and link it to the royals table
db_user = Telegram(royal_id=db_royal.id,
telegram_id=tg_user.id,
first_name=tg_user.first_name,
last_name=tg_user.last_name,
username=tg_user.username)
session.add(db_user)
session.commit()
else:
# Update user data
db_user.first_name = tg_user.first_name
db_user.last_name = tg_user.last_name
db_user.username = tg_user.username
session.commit()
bot.send_message(update.message.chat.id, f"✅ Sincronizzazione Telegram completata!\n"
f"Sincronizza il tuo account Steam qui:\n"
f"http://79.26.47.209:1234/login/{db_user.royal_id}")
updater.dispatcher.add_handler(CommandHandler("sync", message_sync))
updater.start_polling()