From 7d662ee3c3d5f0a52fe2113eafd46ded83f7a49a Mon Sep 17 00:00:00 2001 From: Kamal Curi Date: Wed, 19 Jul 2023 16:20:01 -0300 Subject: [PATCH] ADD: '--rqlb' feature --- settings/config.py | 3 +++ utils/commands.py | 30 +++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/settings/config.py b/settings/config.py index 9eb6d5d..cfcb9d1 100644 --- a/settings/config.py +++ b/settings/config.py @@ -34,6 +34,9 @@ LOGLEVEL = os.environ.get('LOGLEVEL', 'info').upper() # Define the path for the quote ID stack file QUOTE_STACK = os.environ.get('NEEBLE_STACK_FILE', '/opt/neeble/id.list') +# Define the path for the --rq leaderboard file +RQ_LEADERBOARD = os.environ.get('RQ_LEADERBOARD_FILE', '/opt/neeble/rqlb.list') + # Logging custom config. LOGGING_CONFIG = { 'version': 1, diff --git a/utils/commands.py b/utils/commands.py index 1fe48e2..42135f4 100644 --- a/utils/commands.py +++ b/utils/commands.py @@ -11,7 +11,7 @@ from random import randrange from discord import Embed, Intents from discord.ext import commands -from settings.config import IMAGE_TYPES, OW_API_CONFIG, PERMISSIONS, QUOTE_STACK +from settings.config import IMAGE_TYPES, OW_API_CONFIG, PERMISSIONS, QUOTE_STACK, RQ_LEADERBOARD from utils.database import (count_quotes, count_quotes_user, get_by_id, get_quote_contains, get_quotes, remove_quote, set_quote) @@ -28,6 +28,9 @@ stack_limit = int((count_quotes() * .25)) with open(QUOTE_STACK, mode='r') as f: quote_id_stack = json.load(f) +with open(RQ_LEADERBOARD, mode='r') as f: + rq_leaderboard = json.load(f) + quote_content = {} last_quote = 0 @@ -106,6 +109,12 @@ async def random_quote(bot: object) -> str: chosen_one = get_quotes(quote_id_stack) stack_len = len(quote_id_stack) + #Adds to --rq leaderboard + if bot.author.name in rq_leaderboard.keys(): + rq_leaderboard[bot.author.name] += 1 + else: + rq_leaderboard[bot.author.name] = 1 + if not chosen_one and stack_len > 0: quote_id_stack.pop(0) chosen_one = get_quotes(quote_id_stack) @@ -124,6 +133,10 @@ async def random_quote(bot: object) -> str: with open(QUOTE_STACK, mode='w') as f: json.dump(quote_id_stack, f) + # Writes to persistent rq leaderboard + with open(RQ_LEADERBOARD, mode='w') as f: + json.dump(rq_leaderboard, f) + try: # To image links. if 'http' in chosen_one.quote: @@ -470,6 +483,21 @@ async def count_leaderboard(bot:object) -> str: return await bot.send(qlb) +@client.command(aliases=['rqlb']) +async def random_quote_leaderboard(bot:object) -> str: + """ + Returns a list of --rq invokers, sorted by amount + """ + data = "```\nLista de rqueiros\n" + lis = rq_leaderboard + lis = sorted(lis.items(), key=lambda x:x[1], reverse=True) + for people in lis: + data = data + people[0] + " - " + str(people[1]) + "\n" + data = data + "```" + + return await bot.send(data) + + @client.command(aliases=['dbg']) async def neeble_debug(bot:object) -> str: """