Added satle, and globle

This commit is contained in:
termite 2025-01-13 11:55:52 -08:00
parent 76dae333e6
commit 0f5b65586a

129
bot.py
View file

@ -10,6 +10,10 @@ from dotenv import load_dotenv
WORDLE_CHANNEL = 1317916234863480832 WORDLE_CHANNEL = 1317916234863480832
MISC_GEOGRAPHY = 1317916442342981722
GLOBLE_CHANNEL = 1320505660701413511
load_dotenv() load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN') TOKEN = os.getenv('DISCORD_TOKEN')
@ -22,7 +26,9 @@ bot = commands.Bot()
guild_ids=[261345598987436033] guild_ids=[261345598987436033]
) )
async def stats(interaction: discord.Interaction, game, user: discord.User = None): async def stats(interaction: discord.Interaction, game, user: discord.User = None):
if game.lower() == 'wordle': await interaction.response.defer()
match game.lower():
case "wordle":
channel = bot.get_channel(WORDLE_CHANNEL) channel = bot.get_channel(WORDLE_CHANNEL)
if user is None: if user is None:
@ -48,7 +54,7 @@ async def stats(interaction: discord.Interaction, game, user: discord.User = Non
if total_games == 0: if total_games == 0:
await interaction.response.send_message( await interaction.followup.send(
"No Wordle results found.", "No Wordle results found.",
ephemeral=True ephemeral=True
) )
@ -57,15 +63,14 @@ async def stats(interaction: discord.Interaction, game, user: discord.User = Non
average_guesses = total_guesses / wins average_guesses = total_guesses / wins
win_rate = (wins / total_games) * 100 win_rate = (wins / total_games) * 100
await interaction.response.send_message( await interaction.followup.send(
f"Wordle stats for {user.mention}:\n" f"Wordle stats for {user.mention}:\n"
f"Total Games Played: {total_games}\n" f"Total Games Played: {total_games}\n"
f"Total Guesses: {total_guesses}\n"
f"Average Guesses per Winning Game: {average_guesses:.2f}\n" f"Average Guesses per Winning Game: {average_guesses:.2f}\n"
f"Win Rate: {win_rate:.2f}%\n", f"Win Rate: {win_rate:.2f}%\n",
ephemeral=False # Send message only to the user who called the command ephemeral=False # Send message only to the user who called the command
) )
elif game.lower() == 'connections': case "connections":
channel = bot.get_channel(WORDLE_CHANNEL) channel = bot.get_channel(WORDLE_CHANNEL)
if user is None: if user is None:
@ -99,7 +104,7 @@ async def stats(interaction: discord.Interaction, game, user: discord.User = Non
if total_games == 0: if total_games == 0:
await interaction.response.send_message( await interaction.followup.send(
"No Connections results found.", "No Connections results found.",
ephemeral=True ephemeral=True
) )
@ -108,7 +113,7 @@ async def stats(interaction: discord.Interaction, game, user: discord.User = Non
average_guesses = total_guesses / wins average_guesses = total_guesses / wins
win_rate = (wins / total_games) * 100 win_rate = (wins / total_games) * 100
await interaction.response.send_message( await interaction.followup.send(
f"Connections stats for {user.mention}:\n" f"Connections stats for {user.mention}:\n"
f"Total Games Played: {total_games}\n" f"Total Games Played: {total_games}\n"
f"Average Guesses per Winning Game: {average_guesses:.2f}\n" f"Average Guesses per Winning Game: {average_guesses:.2f}\n"
@ -117,8 +122,114 @@ async def stats(interaction: discord.Interaction, game, user: discord.User = Non
ephemeral=False # Send message only to the user who called the command ephemeral=False # Send message only to the user who called the command
) )
else: case "satle":
await interaction.response.send_message( channel = bot.get_channel(MISC_GEOGRAPHY)
if user is None:
user = interaction.user
SATLE_PATTERN = r"🛰Satle #[0-9]+ (\d)/6"
total_guesses = 0
total_games = 0
wins = 0
async for message in channel.history(limit=1000): # Limit can be adjusted
if message.author == user:
lines = message.content.splitlines()
for line in lines:
match = re.match(SATLE_PATTERN, line.strip())
if match:
total_games += 1
guesses = match.group(1)
if lines[lines.index(line)+1].__contains__("🟩"):
total_guesses += int(guesses)
wins += 1
break
if total_games == 0:
await interaction.followup.send(
"No Satle results found.",
ephemeral=True
)
return
average_guesses = total_guesses / wins
win_rate = (wins / total_games) * 100
await interaction.followup.send(
f"Satle stats for {user.mention}:\n"
f"Total Games Played: {total_games}\n"
f"Average Guesses per Winning Game: {average_guesses:.2f}\n"
f"Win Rate: {win_rate:.2f}%\n",
ephemeral=False # Send message only to the user who called the command
)
case "globle":
misc_channel = bot.get_channel(MISC_GEOGRAPHY)
globle_channel = bot.get_channel(GLOBLE_CHANNEL)
if user is None:
user = interaction.user
GLOBLE_PATTERN = r"I guessed todays Globle in ([0-9]+) tries:"
BAD_GLOBLE_PATTERN = r".* = ([0-9]+)"
total_guesses = 0
total_games = 0
async for message in misc_channel.history(limit=1000): # Limit can be adjusted
if message.author == user:
lines = message.content.splitlines()
for line in lines:
match = re.match(GLOBLE_PATTERN, line.strip())
if match:
total_games += 1
guesses = match.group(1)
total_guesses += int(guesses)
break
match = re.match(BAD_GLOBLE_PATTERN, line.strip())
if match:
total_games += 1
guesses = match.group(1)
total_guesses += int(guesses)
break
async for message in globle_channel.history(limit=1000): # Limit can be adjusted
if message.author == user:
lines = message.content.splitlines()
for line in lines:
match = re.match(GLOBLE_PATTERN, line.strip())
if match:
total_games += 1
guesses = match.group(1)
total_guesses += int(guesses)
break
match = re.match(BAD_GLOBLE_PATTERN, line.strip())
if match:
total_games += 1
guesses = match.group(1)
total_guesses += int(guesses)
break
if total_games == 0:
await interaction.followup.send(
"No Globle results found.",
ephemeral=True
)
return
average_guesses = total_guesses / total_games
await interaction.followup.send(
f"Globle stats for {user.mention}:\n"
f"Total Games Played: {total_games}\n"
f"Average Guesses per Game: {average_guesses:.2f}\n",
ephemeral=False # Send message only to the user who called the command
)
case _:
await interaction.followup.send(
"Not a game.", "Not a game.",
ephemeral=True ephemeral=True
) )