diff --git a/crap/Account.py b/crap/Account.py index dc764e3..764fa91 100644 --- a/crap/Account.py +++ b/crap/Account.py @@ -53,6 +53,10 @@ def create(username: str, password: str, email: str, osu_id: int, about: str): DB.do(query, params) + @staticmethod + def set_status(id: int, status: str): + DB.do("UPDATE accounts SET status = %s where id = %s", params=(status, id)) + @staticmethod def change_username(id: int, new_username: str): DB.do(f"update accounts set username = %s where id = %s;", params=(new_username, id)) diff --git a/crap/gentrys_quest_crap/GQManager.py b/crap/gentrys_quest_crap/GQManager.py index e67551b..5633d0a 100644 --- a/crap/gentrys_quest_crap/GQManager.py +++ b/crap/gentrys_quest_crap/GQManager.py @@ -1,6 +1,7 @@ import json from GPSystem.GPmain import GPSystem +from crap.Account import Account from crap.PSQLConnection import PSQLConnection as DB from crap.gentrys_quest_crap.Item import Item from crap.gentrys_quest_crap.UserRanking import UserRanking @@ -173,6 +174,16 @@ def submit_classic_data(id: int, start_amount: int, money: int): return ":thumbs_up:" + @staticmethod + def classic_check_in(id: int): + Account.set_status(id, "gqc_online") + return "" + + @staticmethod + def check_out(id: int): + Account.set_status(id, "offline") + return "" + # @staticmethod @@ -223,14 +234,24 @@ def get_weighted_rating(id, object_type: str, classic: bool) -> int: return rating @staticmethod - def get_leaderboard(classic: bool, start: int = 0, amount: int = 50) -> list: + def get_leaderboard(classic: bool, start: int = 0, amount: int = 50, online: bool = False) -> list: + """ + grab leaderboard data + + @param classic: targeting classic data + @param start: start index + @param amount: how many players to pull + @param online: targeting online players + @return: leaderboard data + """ prefix = 'c_' if classic else '' # c_ = classic prefix + online_prefix = 'gqc_' if classic else 'gq_' query = f""" SELECT rankings.id, accounts.username, rankings.{prefix + 'weighted'}, rankings.{prefix + 'rank'}, rankings.{prefix + 'tier'} FROM rankings INNER JOIN accounts ON rankings.id = accounts.id - WHERE accounts.status NOT IN ('restricted', 'test') + WHERE accounts.status NOT IN ('restricted', 'test') {f"AND accounts.status = '{online_prefix}online'" if online else ""} ORDER BY {prefix + 'weighted'} desc LIMIT %s OFFSET %s; """ diff --git a/main.py b/main.py index 5262932..0111e98 100644 --- a/main.py +++ b/main.py @@ -43,7 +43,7 @@ # Gentrys Quest data GQManager.load_rankings() -gentrys_quest_classic_version = "V2.0.0" +gentrys_quest_classic_version = "V2.1.0" # flask set up app = Flask( # Create a flask app @@ -356,9 +356,10 @@ async def gq_submit_leaderboard(leaderboard, user, score): # -@app.route("/api/gqc/get-leaderboard/+", methods=["GET"]) -async def get_gq_leaderboard(start, display_number): - return GQManager.get_leaderboard(True, int(start), int(display_number)) +@app.route("/api/gqc/get-leaderboard/++", methods=["GET"]) +async def get_gq_leaderboard(start, display_number, online): + online = online == "true" + return GQManager.get_leaderboard(True, int(start), int(display_number), online) # @@ -368,6 +369,11 @@ async def classic_get_version(): return gentrys_quest_classic_version +@app.route("/api/gqc/check-in/", methods=['POST']) +async def classic_check_in(id): + return GQManager.classic_check_in(id) + + @app.route("/api/gqc/update-data/", methods=['POST']) async def update_classic_data(id): data = request.json @@ -441,6 +447,10 @@ async def get_item(id): return "

Not found in database

" +@app.route("/api/gq/check-out/", methods=['POST']) +async def check_out(id): + return GQManager.check_out(id) + #
# @@ -488,23 +498,22 @@ async def gentrys_quest_leaderboard(): "gentrys quest/leaderboard.html", players=players, get_color=GQManager.get_color, - version=GPSystem.version + version=GPSystem.version, + classic_header="Leaderboard" ) @app.route("/gentrys-quest/online-players") async def gentrys_quest_online_players(): - players = GQManager.online_players - - def sort_thing(player): - return player.power_level.weighted - - players.sort(key=sort_thing, reverse=True) - return render_template( - "gentrys quest/online-players.html", - players=players, - version=GQManager.rater_version + "gentrys quest/leaderboard.html", + players=GQManager.get_leaderboard( + classic=True, + online=True + ), + get_color=GQManager.get_color, + version=GPSystem.version, + classic_header="Online Players" ) diff --git a/templates/base.html b/templates/base.html index 452c882..2eb720c 100644 --- a/templates/base.html +++ b/templates/base.html @@ -19,7 +19,7 @@ diff --git a/templates/gentrys quest/leaderboard.html b/templates/gentrys quest/leaderboard.html index abef9e9..671f10f 100644 --- a/templates/gentrys quest/leaderboard.html +++ b/templates/gentrys quest/leaderboard.html @@ -8,7 +8,7 @@ {% block body %} -

Gentry's Quest Leaderboard

+

{{classic_header}}

GPSystem Version {{version}}

{% set count = namespace(value=1) %} {% for player in players %} diff --git a/templates/gentrys quest/online-players.html b/templates/gentrys quest/online-players.html deleted file mode 100644 index c10819f..0000000 --- a/templates/gentrys quest/online-players.html +++ /dev/null @@ -1,34 +0,0 @@ -{% extends 'base.html' %} - - - {% block head %} - Online Players - - {% endblock %} - - - {% block body %} -

Gentry's Quest Online Players

-

GPSystem Version {{version}}

- {% set count = namespace(value=1) %} - {% for player in players %} -
-
- #{{count.value}} -
-
- {{player.account_name}} -
-
- {% if player.ranking[0] != 'unranked' %} - {{player.power_level['weighted']}} gp {{player.ranking[0]}} {{player.ranking[1]}} - {% else %} - {{player.power_level['weighted']}} gp - {% endif %} -
-
- {% set count.value = count.value + 1 %} - {% endfor %} - {% endblock %} - - \ No newline at end of file