Added chrono

This commit is contained in:
termite 2025-01-22 11:48:51 -08:00
parent 48f116c041
commit 1c5e9dcac2
4 changed files with 101 additions and 1 deletions

22
bot.py
View file

@ -50,7 +50,8 @@ possible_games = [
"Genshindle",
"Planespottle",
"Travle",
"Costcodle"
"Costcodle",
"Chrono"
]
chat_limit = 1000
@ -283,6 +284,20 @@ async def stats(
f"Win Rate: {win_rate:.2f}%\n",
ephemeral=False # Send message only to the user who called the command
)
case "chrono":
total_games = data[1]
wins = data[2]
win_rate = data[3]
total_guesses = data[4]
average_guesses = data[5]
await interaction.followup.send(
f"Chrono 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 _:
await interaction.followup.send(
"Not a game.",
@ -326,6 +341,10 @@ async def get_table_options(ctx : discord.AutocompleteContext):
return ["games","total wins","win rate","average guesses"]
case "travle":
return ["games","total wins","win rate","average guesses","perfects","perfect_rate"]
case "costcodle":
return ["games","total wins","win rate","average guesses"]
case "chrono":
return ["games","total wins","win rate","average guesses"]
case _:
return ["HOW DID YOU GET HERE? SCREW YOU FOR MESSING WITH MY PROGRAM"]
@ -418,6 +437,7 @@ def process_message(message : discord.message, reverse : bool):
gamlog.planespottle : r"Planespottle #[0-9]+ (failed to guess|in \d/5 guesses)!",
gamlog.travle : r"#travle.* #[0-9]+ (\+([0-9]+)|\(([0-9]+) away\))",
gamlog.costcodle : r"Costcodle #[0-9]+ ./6",
gamlog.chrono : r". CHRONO ?#[0-9]+"
}

9
db.py
View file

@ -104,6 +104,15 @@ def create_table():
GUESS_AVG REAL NOT NULL,
LAST_SYNC INTEGER NOT NULL
); ''',
''' CREATE TABLE IF NOT EXISTS CHRONO(
NAME INTEGER PRIMARY KEY NOT NULL,
GAMES INTEGER NOT NULL,
WINS INTEGER NOT NULL,
WIN_RATE REAL NOT NULL,
GUESSES INTEGER NOT NULL,
GUESS_AVG REAL NOT NULL,
LAST_SYNC INTEGER NOT NULL
); ''',
''' CREATE TABLE IF NOT EXISTS GENSHINDLE(
NAME INTEGER PRIMARY KEY NOT NULL,
GAMES INTEGER NOT NULL,

View file

@ -12,3 +12,4 @@ from .wheretaken import wheretaken
from .wheretaken import whentaken
from .travle import travle
from .costcodle import costcodle
from .chrono import chrono

70
gamelogic/chrono.py Normal file
View file

@ -0,0 +1,70 @@
import sys
import time
import discord
import re
import sqlite3
def chrono(message : discord.message, reverse):
if reverse == True:
reverse = -1
else:
reverse = 1
conn = sqlite3.connect('stats.db')
cursor = conn.cursor()
PATTERN = r"(.) CHRONO ?#[0-9]+"
total_guesses = 0
total_games = 0
wins = 0
sync_time = 0
new_sync_time = (int)(time.mktime(message.created_at.timetuple()))
cursor.execute('''SELECT * FROM CHRONO WHERE NAME = ?''', (message.author.id,))
data = cursor.fetchone()
if data:
total_games = data[1]
wins = data[2]
total_guesses = data[4]
sync_time = data[6]
if sync_time > new_sync_time and reverse == 1:
return
match = re.search(PATTERN, message.content.strip())
guesses = match.group(1)
match guesses:
case "🥇":
guesses = 1
case "🥈":
guesses = 2
case "🥉":
guesses = 3
case _:
guesses = 4
total_guesses += int(guesses) * reverse
if(guesses < 4):
wins += 1 * reverse
total_games += 1 * reverse
if wins != 0:
average_guesses = total_guesses / wins
else:
average_guesses = 0
win_rate = (wins / total_games) * 100
cursor.execute('''INSERT OR REPLACE INTO CHRONO VALUES(?, ?, ?, ?, ?, ?, ?)''',
(message.author.id,total_games,wins,win_rate,total_guesses,average_guesses,new_sync_time))
conn.commit()
conn.close()