ADD: Roulette leaderboard

ipm
Kamal Curi 2 years ago
parent 239b03e486
commit 09cd36823d

@ -5,7 +5,7 @@
█ ▄ █ ▄▄▄█ ▄▄▄█ ▄ ██ █▄▄▄█ ▄▄▄█ █ ▄ █ ▄▄▄█ ▄▄▄█ ▄ ██ █▄▄▄█ ▄▄▄█
█ █ █ █ █▄▄▄█ █▄▄▄█ █▄█ █ █ █▄▄▄ █ █ █ █ █▄▄▄█ █▄▄▄█ █▄█ █ █ █▄▄▄
█▄█ █▄▄█▄▄▄▄▄▄▄█▄▄▄▄▄▄▄█▄▄▄▄▄▄▄█▄▄▄▄▄▄▄█▄▄▄▄▄▄▄█ █▄█ █▄▄█▄▄▄▄▄▄▄█▄▄▄▄▄▄▄█▄▄▄▄▄▄▄█▄▄▄▄▄▄▄█▄▄▄▄▄▄▄█
Neeble version: 2023.10.05 Neeble version: 2023.10.09
Help with the development of neeble-bot in Help with the development of neeble-bot in
https://brejela.club/gitea/neeble-club/neeble https://brejela.club/gitea/neeble-club/neeble
Thank you! Thank you!

@ -37,6 +37,10 @@ QUOTE_STACK = os.environ.get('NEEBLE_STACK_FILE', '/opt/neeble/id.list')
# Define the path for the --rq leaderboard file # Define the path for the --rq leaderboard file
RQ_LEADERBOARD = os.environ.get('RQ_LEADERBOARD_FILE', '/opt/neeble/rqlb.list') 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: ## INSTRUCTIONS ON SETTING UP PERMISSIONS:
# Permissions are now granular, more than one distinct role # Permissions are now granular, more than one distinct role
# can execute the commands, whatever roles are inside the # can execute the commands, whatever roles are inside the

@ -10,7 +10,7 @@ from random import randrange
from discord import Embed, Intents from discord import Embed, Intents
from discord.ext import commands 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, from utils.database import (count_quotes, count_quotes_user, get_by_id, get_quote_contains,
get_quotes, remove_quote, set_quote) 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 # 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)) 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 # 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 # prevents repeating quotes in between restarts
with open(QUOTE_STACK, mode='r') as f: with open(QUOTE_STACK, mode='r') as f:
@ -45,6 +45,10 @@ comlock = {'roulette': False
# Used in `roulette(bot: object)` # Used in `roulette(bot: object)`
drum = [] drum = []
chamber = -1 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, # 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. # 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))}`") return await bot.send(f":game_die: : `{str(randrange(1, size + 1))}`")
@client.command(aliases=[]) @client.command(aliases=[])
async def roulette(bot:object) -> str: async def roulette(bot:object, *option:str) -> str:
""" """
Russian Roulette Russian Roulette
""" """
@ -557,8 +561,21 @@ async def roulette(bot:object) -> str:
global drum global drum
global chamber global chamber
global comlock global comlock
global pot
global russians
global roulette_leaderboard
spin = 0 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: if comlock['roulette'] == True:
return await bot.send(bot.author.name + " can't take the gun as it is still on someone's hand!") 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': if drum[chamber] == 'bang':
chamber = -1 chamber = -1
drum = [] drum = []
pot = 1
await bot.send(f"BANG! {bot.author.name} died.") 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 comlock['roulette'] = False
return 0 return 0
else: else:
if chamber == 4: 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 chamber = -1
drum = [] drum = []
drum.extend(['click']*6) drum.extend(['click']*6)
@ -589,6 +620,11 @@ async def roulette(bot:object) -> str:
await bot.send("Click!") await bot.send("Click!")
return await bot.send("FIFTH SHOT! Re-spinning the drum...") 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!") await bot.send("Click!")
comlock['roulette'] = False comlock['roulette'] = False
return 0 return 0
@ -627,4 +663,6 @@ async def neeble_debug(bot:object) -> str:
abusers = rq_abusers abusers = rq_abusers
rl_drum = drum rl_drum = drum
rl_chmb = chamber 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}```") 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}```")
Loading…
Cancel
Save