Skip to content

Commit

Permalink
Best Game Stat, fixed countryle.py
Browse files Browse the repository at this point in the history
Added a brand new stat, Best Game which just is the users best game (least amount of guesses). Also fixed countryle.py showing the wrong information.
  • Loading branch information
coreyhsGames committed Mar 4, 2023
1 parent bd11258 commit 849b80d
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 8 deletions.
13 changes: 11 additions & 2 deletions cogs/countryle.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async def play_countryle(self, ctx):
user_stats = db_countryle.find_one({"id": ctx.author.id})
if not ctx.author.bot:
if user_stats is None:
insert = {"id": ctx.author.id, "wins": 0, "games_played": 0}
insert = {"id": ctx.author.id, "wins": 0, "games_played": 0, "best_game": 0}
db_countryle.insert_one(insert)

time.sleep(3)
Expand Down Expand Up @@ -161,7 +161,7 @@ def generate_guessed_country(guess, answer, puzzle_id):
if guessed_hemisphere == correct_hemisphere:
hemisphere_str = f"{guessed_hemisphere} ✅"
else:
continent_str = f"{guessed_continent} ❌"
hemisphere_str = f"{guessed_hemisphere} ❌"

if guessed_continent == correct_continent:
continent_str = f"{guessed_continent} ✅"
Expand Down Expand Up @@ -210,6 +210,15 @@ def update_embed(embed: discord.Embed, guess: str, user: discord.Member) -> disc
user_stats = db_countryle.find_one({'id': user.id})
wins = user_stats['wins'] + 1
db_countryle.update_one({"id": user.id}, {"$set":{"wins": wins}})

best_guess = user_stats['best_guess']
if best_guess > 0:
if best_guess > num_of_guesses:
best_guess = num_of_guesses
db_countryle.update_one({"id": user.id}, {"$set":{"best_guess": best_guess}})
elif best_guess == 0:
best_guess = num_of_guesses
db_countryle.update_one({"id": user.id}, {"$set":{"best_guess": best_guess}})
else:
embed.add_field(name = f"{guess}:", value = f"{guessed_result}", inline=False)
return embed
Expand Down
42 changes: 37 additions & 5 deletions cogs/db.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import discord, json
import discord, json, time
from discord.ext import commands
from pymongo import MongoClient

Expand All @@ -16,20 +16,21 @@ def __init__(self, client):

@commands.group(invoke_without_command = True)
async def lb(self, ctx):
await ctx.reply("**In order to see the leaderboards, please specify the game. Currently there is only 1 avaliable game. The list is below:\n• Countryle: `pylb countryle`**")
await ctx.reply("In order to see the leaderboards, please specify the game. Currently there is only 1 avaliable game.**\n\nThe list is below:\n• Countryle: `pylb countryle`**")

@lb.command(name = "countryle")
async def lb_countryle(self, ctx):
rankings = db_countryle.find().sort("wins", -1)
i = 1
embed = discord.Embed(title = "PyGuessr Leaderboard", description = f"Displays the top 10 people in all of Discord in PyGuessr's Countryle, sorted by most wins.", colour = 0xBA55D3)
embed = discord.Embed(title = "Countryle Leaderboard", description = f"Displays the top 10 people in all of Discord in PyGuessr's Countryle, sorted by most wins.", colour = 0xBA55D3)
for x in rankings:
try:
temp = ctx.guild.get_member(x["id"])
temp = self.client.get_user(x["id"])
temp_wins = x["wins"]
temp_games_played = x["games_played"]
temp_best_guess = x["best_guess"]

field_stats = f'👑 **Wins:** {temp_wins} | 🗓️ **Games Played:** {temp_games_played}'
field_stats = f'👑 **Wins:** {temp_wins} | 🗓️ **Games Played:** {temp_games_played} | 🔥 **Best Game: ** {temp_best_guess}'
if i == 1:
i = "🥇"
embed.add_field(name = f"{i}: {temp.name}", value = field_stats, inline = False)
Expand All @@ -56,5 +57,36 @@ async def lb_countryle(self, ctx):
break
await ctx.reply(embed=embed)

@commands.group(invoke_without_command = True)
async def rank(self, ctx):
await ctx.reply("In order to see a users rank, please specify the game. Currently there is only 1 avaliable game.**\n\nThe list is below:\n• Countryle: `pyrank countryle [user]`**")

@rank.command(name = "countryle")
async def rank_countryle(self, ctx, user: discord.Member = None):
if user is None:
user = ctx.author

if not ctx.author.bot and user.id != self.client.user.id:
user_stats = db_countryle.find_one({"id": user.id})
if user_stats is None:
insert = {"id": user.id, "wins": 0, "games_played": 0, "best_guess": 0}
db_countryle.insert_one(insert)

time.sleep(3)

user_stats = db_countryle.find_one({"id": user.id})

temp_wins = user_stats["wins"]
temp_games_played = user_stats["games_played"]
temp_best_guess = user_stats["best_guess"]

embed = discord.Embed(title = f"{user.name}'s Countryle Stats", colour = 0xBA55D3)
embed.add_field(name = "User", value = user.mention, inline = False)
embed.add_field(name = "👑 Wins:", value = f"{temp_wins}", inline = True)
embed.add_field(name = "🗓️ Games Played:", value = f"{temp_games_played}", inline = True)
embed.add_field(name = "🔥 Best Game:", value = f"{temp_best_guess}")
embed.set_thumbnail(url = user.display_avatar)
await ctx.reply(embed = embed)

async def setup(client):
await client.add_cog(database(client))
3 changes: 2 additions & 1 deletion help.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"countryle": "A country guessing game, based off https://countryle.com."
},
"Stats": {
"lb": "Used to display leaderboards for Pygusser's games."
"lb": "Used to display leaderboards for Pygusser's games.",
"rank": "Used to see individual stats for Pygusser's games."
},
"Misc": {
"stats": "Shows Pygusser's current bot stats.",
Expand Down

0 comments on commit 849b80d

Please sign in to comment.