diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4b01427 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +# Use an official Python runtime as the base image +FROM python:3.13-slim + +# Set the working directory in the container +WORKDIR /bot + +# Copy the current directory contents into the container at /app +COPY . /bot + +# Install any needed packages specified in requirements.txt +RUN pip install --no-cache-dir -r requirements.txt + +# Make port 80 available to the world outside this container +EXPOSE 80 +EXPOSE 443 + +# Define environment variable +ENV NAME DISCORD_TOKEN + +# Run app.py when the container launches +CMD ["python", "bot.py"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..1930ac2 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +To use the docker container, just use it, ports 443 and 80 for discord api, that simple diff --git a/bot.py b/bot.py index 2263d7e..14b2552 100644 --- a/bot.py +++ b/bot.py @@ -49,7 +49,8 @@ possible_games = [ "Flagle", "Genshindle", "Planespottle", - "Travle" + "Travle", + "Costcodle" ] chat_limit = 1000 @@ -266,6 +267,20 @@ async def stats( f"Win Rate: {win_rate:.2f}%\n" f"Perfect Games: {perfects}\n", + ephemeral=False # Send message only to the user who called the command + ) + case "costcodle": + total_games = data[1] + wins = data[2] + win_rate = data[3] + total_guesses = data[4] + average_guesses = data[5] + + await interaction.followup.send( + f"Costcodle 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 _: @@ -401,7 +416,8 @@ def process_message(message : discord.message, reverse : bool): gamlog.flagle : r"#Flagle #[0-9]+ \(.*\) ./6", gamlog.genshindle : r"I (found|couldn't find) today's #Genshindle", 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.travle : r"#travle.* #[0-9]+ (\+([0-9]+)|\(([0-9]+) away\))", + gamlog.costcodle : r"Costcodle #[0-9]+ ./6", } diff --git a/db.py b/db.py index 6581125..771b1a0 100644 --- a/db.py +++ b/db.py @@ -95,6 +95,15 @@ def create_table(): GUESS_AVG REAL NOT NULL, LAST_SYNC INTEGER NOT NULL ); ''', + ''' CREATE TABLE IF NOT EXISTS COSTCODLE( + 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, diff --git a/gamelogic/__init__.py b/gamelogic/__init__.py index a45b7bd..5bcc60b 100644 --- a/gamelogic/__init__.py +++ b/gamelogic/__init__.py @@ -11,4 +11,4 @@ from .planespottle import planespottle from .wheretaken import wheretaken from .wheretaken import whentaken from .travle import travle - +from .costcodle import costcodle diff --git a/gamelogic/costcodle.py b/gamelogic/costcodle.py new file mode 100644 index 0000000..1faa7ba --- /dev/null +++ b/gamelogic/costcodle.py @@ -0,0 +1,63 @@ +import sys +import time +import discord +import re + +import sqlite3 + + +def costcodle(message : discord.message, reverse): + if reverse == True: + reverse = -1 + else: + reverse = 1 + + conn = sqlite3.connect('stats.db') + cursor = conn.cursor() + + PATTERN = r"Costcodle #[0-9]+ (.)/6" + + match = re.match(PATTERN, message.content.strip()) + + + 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 COSTCODLE 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 + + guesses = match.group(1) + if guesses != 'X': + total_guesses += int(guesses) * reverse + wins += 1 * reverse + else: + total_guesses += 6 + + 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 COSTCODLE VALUES(?, ?, ?, ?, ?, ?, ?)''', + (message.author.id,total_games,wins,win_rate,total_guesses,average_guesses,new_sync_time)) + + conn.commit() + conn.close() diff --git a/gamelogic/travle.py b/gamelogic/travle.py index 374764a..c6400df 100644 --- a/gamelogic/travle.py +++ b/gamelogic/travle.py @@ -50,7 +50,7 @@ def travle(message : discord.message, reverse): else: colored_match = re.search(COLORED_PATTERN, message.content.strip()) guesses = int(match.group(3)) - guesses += str(colored_match).count('🟥') + guesses += len(str(colored_match)) - str(colored_match).count("🟩") total_guesses += guesses diff --git a/piprequirements.txt b/requirements.txt similarity index 100% rename from piprequirements.txt rename to requirements.txt