Compare commits

...

81 Commits

Author SHA1 Message Date
d72a6ef6f2 Removed completed Todo 2025-08-15 19:35:42 +10:00
b3b8c2917e Deleted test files
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2025-08-15 19:27:37 +10:00
0fdf305cd4 Test again
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2025-08-14 18:09:40 +10:00
01170a3849 Docker changes
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2025-08-14 18:06:43 +10:00
c088dd276e noo
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2025-08-13 21:50:13 +10:00
6f30a23b49 a bit more bs
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2025-08-13 21:46:38 +10:00
adfafa5af0 fasdfhjaksdf
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2025-08-13 21:44:57 +10:00
519528830c gemini will mess with me at all times is
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2025-08-13 21:43:58 +10:00
0d280777ff Gemini is stupid
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2025-08-13 21:42:54 +10:00
b7d1ecb8d6 debugging 2025-08-13 21:42:01 +10:00
9abaa12dce Idek
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2025-08-13 21:37:32 +10:00
1ceaa85589 debug
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2025-08-13 21:32:49 +10:00
2502b8e70e what
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2025-08-13 21:22:16 +10:00
7bdb6f613c Remove placeholders
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2025-08-13 21:19:37 +10:00
53458625c9 More syntax fixing
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2025-08-13 21:18:47 +10:00
7c1a21d802 Edit to fix syntax
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2025-08-13 21:17:48 +10:00
17178704a3 New from Gemini 2025-08-13 21:16:46 +10:00
ffa748f5de A bit of debug
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2025-08-13 21:12:10 +10:00
24dba9d952 Added safe directory in woodpecker
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2025-08-13 21:09:03 +10:00
14e64ba038 Added safe directory on server
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2025-08-13 21:08:29 +10:00
d58d35f354 Added git
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2025-08-13 21:07:31 +10:00
a46962fdcb Test
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2025-08-13 21:06:24 +10:00
d5ec4ad054 Adding sleep
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2025-08-13 21:04:55 +10:00
50e100d2ff Just shutdown
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2025-08-13 21:03:59 +10:00
659de90936 removing bs
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2025-08-13 21:02:42 +10:00
ff4d40b81c every time
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2025-08-13 21:01:59 +10:00
500c6ee002 syntax err
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2025-08-13 21:01:11 +10:00
ff53fd25cd More debugging 2025-08-13 21:00:14 +10:00
e664ad9d03 compose
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2025-08-13 20:58:08 +10:00
4465e6a84b Slimming
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2025-08-13 20:57:31 +10:00
0b1b4bc503 ffs
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2025-08-13 20:56:13 +10:00
b1b040f2a5 Added debugging
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2025-08-13 20:55:36 +10:00
ce7dd4ab94 Hard restart
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2025-08-13 20:51:13 +10:00
a53903bd36 Updates and testing
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2025-08-13 20:49:43 +10:00
42555b8920 docker?
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2025-08-13 20:46:25 +10:00
6ee556ff60 debian again
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2025-08-13 20:45:07 +10:00
acdf1a393c Added daemon path
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2025-08-13 20:41:39 +10:00
4f7e2373cd Removed bottom volumes moving host path upwards
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2025-08-13 20:40:42 +10:00
28245c231d Added some logging for assistance
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2025-08-13 20:39:06 +10:00
cbce0eec68 added dash
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2025-08-13 20:38:28 +10:00
bc33de6a1f removed latest
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2025-08-13 20:37:59 +10:00
ecc6f4cabc Short syntax
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2025-08-13 20:37:29 +10:00
2b4dd965f5 Adding app path
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2025-08-13 20:35:58 +10:00
ac8dd1ad42 Uncomment bottom volumes
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2025-08-13 20:35:28 +10:00
3723bc2b82 Commenting top volumes
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2025-08-13 20:34:47 +10:00
27c3b7dc48 Comment bottom volumes 2025-08-13 20:34:24 +10:00
69fad2c469 Gemini Test 2025-08-13 20:33:44 +10:00
e433d622f9 Type docker 2025-08-13 20:32:42 +10:00
d0d8e24623 Debian 2025-08-13 20:29:59 +10:00
70abd8977b Reverting again 2025-08-13 20:29:26 +10:00
cc403c9789 Going back to debian 2025-08-13 20:28:55 +10:00
2614ad052c Manually reverting changes 2025-08-13 20:28:26 +10:00
7ef3a32e68 Removing volumes
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2025-08-13 20:22:30 +10:00
b22269a5b8 Debian 2025-08-13 20:22:04 +10:00
261f4e87ed Test 2025-08-13 20:20:54 +10:00
0373b51af9 Test 2025-08-13 20:19:55 +10:00
1bc5dd7198 Test 2025-08-13 20:13:52 +10:00
adfaafaf67 test 2025-08-13 20:12:21 +10:00
dccfb79ace Update .woodpecker.yml 2025-08-13 20:06:38 +10:00
028cab2de8 Update .woodpecker.yml
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2025-08-13 20:03:14 +10:00
d40308e1a4 Edits 2025-08-13 19:23:23 +10:00
7990cec65c edits 2025-08-13 19:21:41 +10:00
a1eca76102 Delete .woodpecker/test
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2025-08-13 18:45:41 +10:00
b891e3d00b Update .woodpecker.yml
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2025-08-13 18:45:25 +10:00
Gary
61b29eea67 Added test file 2025-08-13 18:35:03 +10:00
43b53d3ee8 edits 2025-08-13 18:29:33 +10:00
1073882d31 test 2025-08-13 18:27:30 +10:00
5bdc618d5c More changes for getting woodpecker to work 2025-08-13 18:26:15 +10:00
ab56bd5319 Updated for compose 2025-08-13 18:25:01 +10:00
68d366822b Added woodpecker file 2025-08-13 18:21:13 +10:00
692a160972 Added docker files for remote 2025-08-13 16:51:59 +10:00
d743e5610a Implemented card counting. Refactored blackjack code a bit.
Removed gamepicker references
2025-08-13 14:45:57 +10:00
48f9389100 Moved shit to recycle bin etc etc 2025-08-11 21:58:43 +10:00
686e5d6617 Main addition: Russian Roulette 2024-02-18 10:00:21 +10:00
bdf4c32e70 Merge branch 'Game-Pick-Bot' 2023-11-30 16:37:22 +10:00
b18f0ae688 master pre merge commit 2023-11-30 16:37:11 +10:00
9501737b43 Fixed multiple session bug for blackjack 2023-11-30 16:35:37 +10:00
a6bc671231 Updated gitignore 2023-11-23 09:48:26 +10:00
f9785f0e8a BlackJack Finished 2023-11-23 09:46:08 +10:00
a7fc6da2cb Preperations for setting up game picker 1.0 2023-11-22 12:06:58 +10:00
c2ea96445d Added dice roller 2023-09-12 11:09:27 +10:00
28 changed files with 334 additions and 78 deletions

1
.gitignore vendored
View File

@@ -1,3 +1,4 @@
ledger.db ledger.db
__pycache__/* __pycache__/*
src/py/__pycache__/*
*.drawio *.drawio

57
.woodpecker.yml Normal file
View File

@@ -0,0 +1,57 @@
kind: pipeline
type: docker # All steps will run in Docker containers.
name: update-and-restart-discord-bot # A descriptive name for the pipeline.
when:
- branch: main # This pipeline triggers on pushes to the 'main' branch.
event: push
steps:
- name: pull-latest-source # Step 1: Pull the latest code from Gitea.
image: alpine/git # A lightweight image that includes the 'git' command.
volumes:
# Mount your bot's source code directory with read-write permissions.
# This is crucial for 'git pull' to update the files on your host machine.
- /home/gary/Discord/Acrybot:/app:rw # ':rw' ensures read-write access.
commands:
- echo "--- Pulling latest source code from Git ---"
- cd /app # Navigate to the mounted project directory.
# Configure Git to trust the mounted directory to avoid 'unsafe repository' warnings.
- git config --global --add safe.directory /app
- git pull # Pulls the latest changes from the tracking branch.
- echo "Source code updated."
- name: manage-bot-containers # Step 2: Manage your bot's Docker containers.
# Changed image to 'docker:latest' to use the unhyphenated 'docker compose'
image: docker:latest
volumes:
# Mount the Docker socket from the host to allow control over host Docker daemon.
- /var/run/docker.sock:/var/run/docker.sock
# Mount your Docker Compose project directory into the container.
- /home/gary/Discord/Acrybot:/app
environment:
# IMPORTANT: Explicitly set the Docker Compose project name to lowercase.
# This ensures containers are managed with the 'acrybot' prefix,
# matching your existing containers.
COMPOSE_PROJECT_NAME: acrybot # Changed to lowercase 'acrybot'
commands:
- echo "--- Building 'python-app' image without cache to ensure latest code ---"
# Explicitly build the image for 'python-app' with --no-cache
- docker compose build --no-cache python-app
- echo "--- Stopping Discord bot service python-app ---"
# Stop the specific Discord bot service using the unhyphenated 'docker compose'.
- docker compose stop python-app
- echo "--- Bringing Discord bot service up python-app ---"
# Bring the specific Discord bot service back up using the unhyphenated 'docker compose'.
# '--build' is no longer needed here as it was already forced by 'docker compose build --no-cache'.
- docker compose up -d python-app
- echo "--- Verifying bot status ---"
# Directly check the status of the service using docker compose ps
- docker compose ps python-app
- echo "--- Logs of Discord bot service ---"
# Fetch the logs of the bot service using docker compose logs
- docker compose logs python-app

View File

@@ -1,11 +1,11 @@
FROM python:3 # Use a full Python runtime image to ensure necessary build tools are available.
FROM python
RUN pip install discord # Set the working directory to organize application files.
WORKDIR /app
WORKDIR /usr/app/src # Copy requirements file to allow pip to find dependencies during build.
COPY requirements.txt /app/
COPY Acronymbot.py ./ # Install Python dependencies for the application to run correctly.
COPY BlackJack.py ./ RUN pip install --no-cache-dir -r requirements.txt
COPY Ledger.py ./
CMD [ "python", "./Acronymbot.py" ]

View File

@@ -1,31 +0,0 @@
import discord
import random
# Temporary List
games = ["Left 4 Dead 2",
"Aragami",
"Astroneer",
"Factorio",
"Borderlands",
"Stardew Valley",
"Viscera Cleanup Detail",
"SCP",
"Satisfactory",
"Backrooms (Alternate Ending)",
"Ghost Recon Wildlands"
]
def add_game(game: str):
games.append(game)
def pick_game():
randomIndex = random.randrange(0, len(games))
coinFlip = random.randrange(0, 2)
if coinFlip:
return f"Valorant ({games[randomIndex]})"
else:
return games[randomIndex]

34
Recycle Bin/Gamepicker.py Normal file
View File

@@ -0,0 +1,34 @@
import discord
import random
# Temporary List
# games = ["Left 4 Dead 2",
# "Aragami",
# "Astroneer",
# "Factorio",
# "Borderlands",
# "Stardew Valley",
# "Viscera Cleanup Detail",
# "SCP",
# "Satisfactory",
# "Ghost Recon Wildlands"
# ]
games = ["Plate Up",
"Terraria",
"Ghost Recon"]
def add_game(game: str):
games.append(game)
def pick_game():
randomIndex = random.randrange(0, len(games))
coinFlip = random.randrange(0, 2)
if coinFlip:
return f"Valorant ({games[randomIndex]})"
else:
return games[randomIndex]

View File

@@ -0,0 +1,20 @@
version: "3.3"
networks:
net:
driver: bridge
services:
acronymbot:
build: ./src/py
volumes:
- "./src/py:/usr/app/src"
networks:
- "net"
depends_on:
- database
database:
image: mariadb:latest
networks:
- "net"

View File

@@ -3,7 +3,7 @@ GAMEINFO:
ID, NAME, GENRE, GAMEPASS ID, NAME, GENRE, GAMEPASS
WHOOWNSIT (bitmap index): WHOOWNSIT (bitmap index):
ID, MARCUS, BENSON, ALEX, TIM ID, MARCUS, BENSON, ALEX, TIM, AIDAN
GAMEFACTORS: GAMEFACTORS:
ID, BRAINLEVEL, TIMETOPLAY, CAMPAIGN ID, BRAINLEVEL, TIMETOPLAY, CAMPAIGN

5
Recycle Bin/plan.txt Normal file
View File

@@ -0,0 +1,5 @@
Microservices:
- Some sort of database for storing the data
- Image for the python code that runs the bot
- Something to interface the two, like sparkSQL for interacting with the database

14
docker-compose.yml Normal file
View File

@@ -0,0 +1,14 @@
# Define the services (containers) that make up your application
services:
# 'python-app' is the name of your service
python-app:
# Build the Docker image using the Dockerfile in the current directory
build: .
# Mount the current directory on the host machine to '/app' inside the container.
# This enables real-time code changes during development.
volumes:
- "/home/gary/Discord/Acrybot:/app"
# EXPLICITLY set the entrypoint for your container.
# This ensures your Python script runs as the primary process and only once.
# Replace 'your_script_name.py' with the actual name of your Python file.
entrypoint: ["python", "src/py/Acronymbot.py"]

BIN
ledger.db

Binary file not shown.

2
requirements.txt Normal file
View File

@@ -0,0 +1,2 @@
discord
mariadb

View File

@@ -1,9 +1,9 @@
import random
import discord import discord
import sqlite3 import sqlite3
from discord import app_commands from discord import app_commands
from BlackJack import BlackJack from BlackJack import BlackJack
from Calculator import Calculator from Calculator import Calculator
from Gamepicker import pick_game
botIntents = discord.Intents.all() botIntents = discord.Intents.all()
@@ -50,7 +50,7 @@ class Buttons(discord.ui.View):
@tree.command(description="Lmao") @tree.command(description="Lmao")
async def test(interaction:discord.Interaction): async def test(interaction:discord.Interaction):
print(f"{interaction.user} used command! Woohoo!") print(f"{interaction.user} used command! BAHHHH!")
try: try:
await interaction.response.send_message("Pay $5 for a Mario Moment", view=Buttons()) await interaction.response.send_message("Pay $5 for a Mario Moment", view=Buttons())
except discord.app_commands.errors.CommandInvokeError: except discord.app_commands.errors.CommandInvokeError:
@@ -112,16 +112,110 @@ async def calculator(interaction: discord.Interaction):
calculator = Calculator() calculator = Calculator()
await interaction.followup.send(content="`" + " " * calculator.MAXIMUMBARSIZE + "0`", view=calculator) await interaction.followup.send(content="`" + " " * calculator.MAXIMUMBARSIZE + "0`", view=calculator)
@tree.command(description="Roll a Dice")
@app_commands.choices(dice = [
app_commands.Choice(name = 'd4', value=4),
app_commands.Choice(name = 'd6', value=6),
app_commands.Choice(name = 'd8', value=8),
app_commands.Choice(name = 'd10', value=10),
app_commands.Choice(name = 'd12', value=12),
app_commands.Choice(name = 'd20', value=20),
app_commands.Choice(name = 'd100', value=100),
])
async def roll(interaction: discord.Interaction, dice:app_commands.Choice[int]):
roll = random.randint(1, dice.value)
await interaction.response.send_message(f"{dice.name}: {roll}")
""" """
#### Game Picker #### #### Russian Roulette ####
""" """
@tree.command(description="Pick a game") MAXLINELENGTH = 12
async def gg(interaction: discord.Interaction): tooLong = lambda x: len(x) > MAXLINELENGTH
tooShort = lambda x: len(x) < MAXLINELENGTH
difference = lambda x: MAXLINELENGTH - len(x)
sidePad = lambda x: " " * (difference(x) // 2)
evenPad = lambda x: sidePad(x) + x + sidePad(x)
oddPad = lambda x: evenPad(x) + " "
game = pick_game() def demon_text_helper(line):
await interaction.response.send_message("Barotrauma") if tooShort(line):
if difference(line) % 2 == 0:
return evenPad(line)
else:
return oddPad(line)
return line
def demon_text(lineOne="", lineTwo="", lineThree=""):
if tooLong(lineOne) or tooLong(lineTwo) or tooLong(lineThree):
print("Line too long lol")
lineOne = demon_text_helper(lineOne)
lineTwo = demon_text_helper(lineTwo)
lineThree = demon_text_helper(lineThree)
demon = f"``` , , /\ /\ \n\
/( /\ )\ _\ \_/ /_ ____________\n\
|\_||_/| < \_ _/ > / \ \n\
\______/ \|0 0|/ | {lineOne} |\n\
_\/_ _(_ ^ _)_ | {lineTwo} |\n\
( () ) /`\|V\"\"\"V|/`\ | {lineThree} |\n\
{{}} \ \_____/ / <______________/\n\
() /\ )=( /\ \n\
{{}} / \_/\=/\_/ \ \n```"
return demon
class ShootOrNoShoot(discord.ui.View):
def __init__(self, *, timeout=180):
super().__init__(timeout=timeout)
self.bullets = 6
@discord.ui.button(label="Shoot", style=discord.ButtonStyle.red)
async def shoot(self, interaction: discord.Interaction, button: discord.ui.Button):
if self.bullets == 0:
for child in self.children:
child.disabled = True
await interaction.response.edit_message(content=f"What?", view=self)
if random.randrange(0,self.bullets) == 0:
for child in self.children:
child.disabled = True
demonDeath = demon_text(lineOne="You died!", lineTwo="Bahahahah!", lineThree=f"Score: {6 - self.bullets}")
await interaction.response.edit_message(content=f"{demonDeath}", view=self)
else:
self.bullets -= 1
button.label = f"Shoot again"
demonLife = demon_text(lineOne="You live", lineTwo="This time!!",
lineThree=f"({6 - self.bullets}/5) blanks")
await interaction.response.edit_message(content=f"{demonLife}", view=self)
@discord.ui.button(label="PussyOut", style=discord.ButtonStyle.blurple)
async def noshoot(self, interaction: discord.Interaction, button: discord.ui.Button):
for child in self.children:
child.disabled = True
demonPussy = demon_text(lineOne="You are such", lineTwo="a huge pussy", lineThree= "0 bitches 4u")
await interaction.response.edit_message(content=f"{demonPussy}", view=self)
@tree.command(description="????")
async def rr(interaction: discord.Interaction):
await interaction.response.defer()
buttons = ShootOrNoShoot()
demon = demon_text(lineTwo="Shoot urself")
await interaction.followup.send(content=f"{demon}", view=buttons)
""" """
#### Fin #### #### Fin ####

View File

@@ -1,7 +1,6 @@
import random import random
from Ledger import Ledger from Ledger import Ledger
#TODO Starting a game with 21 fucks with hidden cards
#TODO Look into 5card jack thingo that Tim mentioned #TODO Look into 5card jack thingo that Tim mentioned
#TODO Insurance - If dealer starts with 21, you can bet against it and win your money back #TODO Insurance - If dealer starts with 21, you can bet against it and win your money back
#TODO Make each game session more distinct (Embeds?) #TODO Make each game session more distinct (Embeds?)
@@ -29,10 +28,23 @@ class Card():
self.value = value self.value = value
self.suit = suit self.suit = suit
self.hidden = False self.hidden = False
if self.value in range(2,7):
self.count_value = 1
elif self.value in range(7,10):
self.count_value = 0
def turn_card(self): else:
# XOR to flip hidden element self.count_value = -1
self.hidden = self.hidden != True
def hide_card(self):
self.hidden = True
def show_card(self):
self.hidden = False
def get_value(self): def get_value(self):
return self.value return self.value
@@ -51,7 +63,7 @@ class Card():
strValue = str(self.value) strValue = str(self.value)
string = "" string = ""
string = f"{suits[self.suit]}{strValue}" string = f"{suits[self.suit]}{strValue}: ({self.count_value})"
if self.hidden: if self.hidden:
string = "??" string = "??"
return string return string
@@ -67,11 +79,11 @@ class Deck():
self.discard = [] self.discard = []
self.joker = joker self.joker = joker
self.deck.extend([Card(x, Card.HEARTS) for x in range(1, 13)]) self.deck.extend([Card(x, Card.HEARTS) for x in range(1, 14)])
self.deck.extend([Card(x, Card.DIAMONDS) for x in range(1, 13)]) self.deck.extend([Card(x, Card.DIAMONDS) for x in range(1, 14)])
self.deck.extend([Card(x, Card.SPADES) for x in range(1, 13)]) self.deck.extend([Card(x, Card.SPADES) for x in range(1, 14)])
self.deck.extend([Card(x, Card.CLUBS) for x in range(1, 13)]) self.deck.extend([Card(x, Card.CLUBS) for x in range(1, 14)])
print(len(self.deck))
if joker: if joker:
self.deck.append(Card(0, 0)) self.deck.append(Card(0, 0))
@@ -113,6 +125,7 @@ class Deck():
class Hand(): class Hand():
def __init__(self) -> None: def __init__(self) -> None:
self.hand = [] self.hand = []
self.hidden_cards = []
def sortHand(self): def sortHand(self):
self.hand.sort() self.hand.sort()
@@ -130,11 +143,26 @@ class Hand():
return self.hand[index] return self.hand[index]
def hide_card(self, index): def hide_card(self, index):
self.peek_card(index).turn_card() card = self.peek_card(index)
card.hide_card()
self.hidden_cards.append(card)
def show_card(self, index):
card = self.peek_card(index)
card.show_card()
try:
self.hidden_cards.remove(card)
except ValueError:
print("Card not hidden")
def show_hand(self):
extra_count = 0
for card in self.hidden_cards:
card.show_card()
extra_count += card.count_value
self.hidden_cards.remove(card)
return extra_count
def __len__(self):
return len(self.hand)
def __str__(self) -> str: def __str__(self) -> str:
string = "" string = ""
for card in self.hand: for card in self.hand:
@@ -147,11 +175,14 @@ class Hand():
aces = 0 aces = 0
# Add static values # Add static values
for card in self.hand: for card in self.hand:
if card.hidden:
continue
if card.value == 1: if card.value == 1:
aces += 1 aces += 1
continue continue
if card.value > 10: if card.value > 10:
card.value = 10 value += 10
continue
value += card.value value += card.value
# Dynamically add ace value based on ideal rules # Dynamically add ace value based on ideal rules
@@ -174,6 +205,8 @@ class Hand():
def __next__(self): def __next__(self):
return next(self.iter) return next(self.iter)
def __len__(self):
return len(self.hand)
class BlackJack: class BlackJack:
def __init__(self) -> None: def __init__(self) -> None:
@@ -181,34 +214,49 @@ class BlackJack:
self.playerHand = Hand() self.playerHand = Hand()
self.dealerHand = Hand() self.dealerHand = Hand()
self.ledger = Ledger() self.ledger = Ledger()
self.playing = False
self.count = 0
def deal_card(self, hand): def deal_card(self, hand):
card = self.deck.take_from_deck()
hand.add_to_hand(card)
self.count += card.count_value
def deal_hidden_card(self, hand):
hand.add_to_hand(self.deck.take_from_deck()) hand.add_to_hand(self.deck.take_from_deck())
# Hide one of the dealers cards
self.dealerHand.hide_card(1)
def game_setup(self): def game_setup(self):
# Deal cards in alternate order # Deal cards in alternate order
self.deck.shuffle() self.deck.shuffle()
for _ in range(2): for i in range(2):
self.deal_card(self.playerHand) self.deal_card(self.playerHand)
self.deal_card(self.dealerHand) if i == 0:
self.deal_card(self.dealerHand)
else:
self.deal_hidden_card(self.dealerHand)
# Hide one of the dealers cards
self.dealerHand.hide_card(1)
def discard_hand(self, hand): def discard_hand(self, hand):
hand.show_hand()
for _ in range(len(hand)): for _ in range(len(hand)):
card = hand.remove_from_hand(0) card = hand.remove_from_hand(0)
self.deck.addToDiscard(card) self.deck.addToDiscard(card)
async def show_cards(self, send, displayDealerScore=False): async def show_cards(self, send):
# Show Cards to player # Show Cards to player
string = f"Player Hand = {repr(self.playerHand)}: {self.playerHand}\nDealer Hand = ??: {self.dealerHand}" string = f"Player Hand = {repr(self.playerHand)}: {self.playerHand}\nDealer Hand = {repr(self.dealerHand)}: {self.dealerHand}\nCount = {self.count}"
if displayDealerScore:
string = f"Player Hand = {repr(self.playerHand)}: {self.playerHand}\nDealer Hand = {repr(self.dealerHand)}: {self.dealerHand}"
await send(string) await send(string)
async def play_game(self, ID, bet, recv, send): async def play_game(self, ID, bet, recv, send):
if self.playing:
await send("Game in Progress")
return
else:
self.playing = True
gameState = INIT gameState = INIT
while gameState != OVER: while gameState != OVER:
@@ -219,6 +267,9 @@ class BlackJack:
playerStats = self.ledger.read(ID) playerStats = self.ledger.read(ID)
self.game_setup() self.game_setup()
gameState = PLAYERTURN gameState = PLAYERTURN
if int(repr(self.playerHand)) >= 21:
gameState = FINISHED
if gameState == PLAYERTURN: if gameState == PLAYERTURN:
@@ -227,17 +278,15 @@ class BlackJack:
if playerHit: if playerHit:
self.deal_card(self.playerHand) self.deal_card(self.playerHand)
else: else:
#TODO Rename hide_card function
self.dealerHand.hide_card(1)
gameState = DEALERTURN gameState = DEALERTURN
if int(repr(self.playerHand)) >= 21: if int(repr(self.playerHand)) >= 21:
self.dealerHand.hide_card(1)
gameState = FINISHED gameState = FINISHED
if gameState == DEALERTURN: if gameState == DEALERTURN:
extra_count = self.dealerHand.show_hand()
self.count += extra_count
if int(repr(self.dealerHand)) > int(repr(self.playerHand)): if int(repr(self.dealerHand)) > int(repr(self.playerHand)):
gameState = FINISHED gameState = FINISHED
continue continue
@@ -256,7 +305,7 @@ class BlackJack:
tie = False tie = False
playerScore = int(repr(self.playerHand)) playerScore = int(repr(self.playerHand))
dealerScore = int(repr(self.dealerHand)) dealerScore = int(repr(self.dealerHand))
await self.show_cards(send, True) await self.show_cards(send)
if playerScore == 21: if playerScore == 21:
playerBlackJack = True playerBlackJack = True
if dealerScore == 21: if dealerScore == 21:
@@ -308,8 +357,10 @@ class BlackJack:
if len(self.deck) < 0.25 * 51: if len(self.deck) < 0.25 * 51:
self.deck.return_all_from_discard() self.deck.return_all_from_discard()
self.deck.shuffle() self.deck.shuffle()
self.count = 0
await send("Everyday I'm shuffling") await send("Everyday I'm shuffling")
gameState = OVER gameState = OVER
self.playing = False
def main(): def main():
game = BlackJack() game = BlackJack()
@@ -319,6 +370,4 @@ def main():
if __name__ == "__main__": if __name__ == "__main__":
main() main()

11
src/py/Dockerfile Normal file
View File

@@ -0,0 +1,11 @@
FROM python:3
RUN pip install discord \
&& pip install mariadb
WORKDIR /usr/app/src
VOLUME /usr/app/src
# -v flag to mount to this volume. -v [from]:/usr/app/src
CMD [ "python", "./Acronymbot.py" ]

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.