From 09cd36823d04d25c86feb12352fd36473456c2af Mon Sep 17 00:00:00 2001 From: Kamal Curi Date: Mon, 9 Oct 2023 13:56:31 -0300 Subject: [PATCH] ADD: Roulette leaderboard --- motd | 2 +- settings/config.py | 4 ++++ utils/commands.py | 46 ++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 47 insertions(+), 5 deletions(-) diff --git a/motd b/motd index 1e1bd4f..336eca0 100644 --- a/motd +++ b/motd @@ -5,7 +5,7 @@ █ ▄ █ ▄▄▄█ ▄▄▄█ ▄ ██ █▄▄▄█ ▄▄▄█ █ █ █ █ █▄▄▄█ █▄▄▄█ █▄█ █ █ █▄▄▄ █▄█ █▄▄█▄▄▄▄▄▄▄█▄▄▄▄▄▄▄█▄▄▄▄▄▄▄█▄▄▄▄▄▄▄█▄▄▄▄▄▄▄█ -Neeble version: 2023.10.05 +Neeble version: 2023.10.09 Help with the development of neeble-bot in https://brejela.club/gitea/neeble-club/neeble Thank you! diff --git a/settings/config.py b/settings/config.py index 82a059a..9773c6e 100644 --- a/settings/config.py +++ b/settings/config.py @@ -37,6 +37,10 @@ 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') +# Define the path for the --roulette leaderboard +ROULETTE_LEADERBOARD = os.environ.get('ROULETTE_LEADERBOARD', '/opt/neeble/roulette.list') + + ## INSTRUCTIONS ON SETTING UP PERMISSIONS: # Permissions are now granular, more than one distinct role # can execute the commands, whatever roles are inside the diff --git a/utils/commands.py b/utils/commands.py index 585ed74..3978a7f 100644 --- a/utils/commands.py +++ b/utils/commands.py @@ -10,7 +10,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, RQ_LEADERBOARD +from settings.config import IMAGE_TYPES, OW_API_CONFIG, PERMISSIONS, QUOTE_STACK, RQ_LEADERBOARD, ROULETTE_LEADERBOARD from utils.database import (count_quotes, count_quotes_user, get_by_id, get_quote_contains, get_quotes, remove_quote, set_quote) @@ -24,7 +24,7 @@ client = commands.Bot(command_prefix='--', intents=Intents.all()) # This defines how big Neeble's quote "memory" is. If --rq is called, the quotes in the stack are removed from the query stack_limit = int((count_quotes() * .25)) -# When starting the bot for the first time, repetitions are going to be common. If ,after a couple hundred saved quotes, the +# When starting the bot for the first time, repetitions are going to be common. If, after a couple hundred saved quotes, the # bot gets restarted a lot, the stack would reset and quotes would repeat themselves a lot more. Saving the stack on disk # prevents repeating quotes in between restarts with open(QUOTE_STACK, mode='r') as f: @@ -45,6 +45,10 @@ comlock = {'roulette': False # Used in `roulette(bot: object)` drum = [] chamber = -1 +pot = 1 +russians = {} +with open(ROULETTE_LEADERBOARD, mode='r') as f: + roulette_leaderboard = json.load(f) # last_rq is a dictionary that keeps track of each user's --rq call; Sorting that dictionary by time everytime --rq is called _would_ be possible, # but it would scale poorly, that's why last_rqer exists. rq_abusers is a dictionary that keeps track of how many failed --rq attempts each user has. @@ -548,7 +552,7 @@ async def dice_roll(bot:object, size:int=6) -> str: return await bot.send(f":game_die: : `{str(randrange(1, size + 1))}`") @client.command(aliases=[]) -async def roulette(bot:object) -> str: +async def roulette(bot:object, *option:str) -> str: """ Russian Roulette """ @@ -557,8 +561,21 @@ async def roulette(bot:object) -> str: global drum global chamber global comlock + global pot + global russians + global roulette_leaderboard spin = 0 + if 'lb' in option: + with open(ROULETTE_LEADERBOARD, mode='r') as file: + data = "```\nLeaderboard do --roulette:\n" + lis = json.load(file) + 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) + if comlock['roulette'] == True: return await bot.send(bot.author.name + " can't take the gun as it is still on someone's hand!") @@ -575,11 +592,25 @@ async def roulette(bot:object) -> str: if drum[chamber] == 'bang': chamber = -1 drum = [] + pot = 1 await bot.send(f"BANG! {bot.author.name} died.") + russians[bot.author.name] = 0 + for r in russians.keys(): + if bot.author.name in roulette_leaderboard.keys(): + roulette_leaderboard[r] += russians[r] + else: + roulette_leaderboard[r] = russians[r] + with open(ROULETTE_LEADERBOARD, mode='w') as file: + json.dump(roulette_leaderboard, file) comlock['roulette'] = False return 0 else: if chamber == 4: + if bot.author.name in russians.keys(): + russians[bot.author.name] += pot + else: + russians[bot.author.name] = pot + pot += 1 chamber = -1 drum = [] drum.extend(['click']*6) @@ -589,6 +620,11 @@ async def roulette(bot:object) -> str: await bot.send("Click!") return await bot.send("FIFTH SHOT! Re-spinning the drum...") + if bot.author.name in russians.keys(): + russians[bot.author.name] += pot + else: + russians[bot.author.name] = pot + pot += 1 await bot.send("Click!") comlock['roulette'] = False return 0 @@ -627,4 +663,6 @@ async def neeble_debug(bot:object) -> str: abusers = rq_abusers rl_drum = drum rl_chmb = chamber - return await bot.send(f"```\ncomlock:{clock}\nqt_count:{qt_count}\nst_size:{st_size}\nst_limit:{stack_limit}\nlst_qt:{last_quote}\nct_authors:{ct_authors}\nlrqers:{lrqers}\nlrqer:{lrqer}\nabusers:{abusers}\nrl_drum:{rl_drum}\nrl_chmb:{rl_chmb}```") \ No newline at end of file + rl_pot = pot + rl_russians = russians + return await bot.send(f"```\ncomlock:{clock}\nqt_count:{qt_count}\nst_size:{st_size}\nst_limit:{stack_limit}\nlst_qt:{last_quote}\nct_authors:{ct_authors}\nlrqers:{lrqers}\nlrqer:{lrqer}\nabusers:{abusers}\nrl_drum:{rl_drum}\nrl_chmb:{rl_chmb}\nrl_pot:{rl_pot}\nrl_russians:{rl_russians}```") \ No newline at end of file