Merge branch 'Game-Pick-Bot'

This commit is contained in:
2023-11-30 16:37:22 +10:00
22 changed files with 1308 additions and 468 deletions

4
.gitignore vendored
View File

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

3
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,3 @@
{
"python.analysis.typeCheckingMode": "off"
}

View File

@@ -1,249 +0,0 @@
import discord
import sqlite3
from discord import app_commands
from BlackJack import BlackJack
botIntents = discord.Intents.all()
client = discord.Client(intents=botIntents)
tree = app_commands.CommandTree(client)
blackJack = BlackJack()
@client.event
async def on_ready():
await tree.sync()
print('Itsa me Mario!')
# @client.event
# async def on_message_delete(message: discord.Message):
# channel = client.get_channel(message.channel.id)
# await channel.send(f"{message.author} deleted a message! @everyone, get him!")
# dmessage = await channel.send(f"Here's the message they deleted! \"{message.content}\". What a sick fuck")
# await dmessage.delete()
"""
#### Test ####
"""
class Buttons(discord.ui.View):
def __init__(self, *, timeout=180):
super().__init__(timeout=timeout)
@discord.ui.button(label="Pay $5", style=discord.ButtonStyle.green)
async def green_button(self, interaction: discord.Interaction, button: discord.ui.Button):
print(f"{interaction.user} pressed the green button")
button.disabled = True
button.label = "No Refunds!"
for child in self.children:
child.disabled = True
await interaction.response.edit_message(content=f"Mario Moment Achieved", view=self)
@discord.ui.button(label="Punch AcryBot", style=discord.ButtonStyle.red)
async def red_button(self, interaction: discord.Interaction, button: discord.ui.Button):
print(f"{interaction.user} pressed the red button")
button.disabled = True
button.label = f"fuck you {interaction.user}"
for child in self.children:
child.disabled = True
await interaction.response.edit_message(content=f"Ouch!", view=self)
@tree.command(description="Lmao")
async def test(interaction:discord.Interaction):
print(f"{interaction.user} used command! Woohoo!")
try:
await interaction.response.send_message("Pay $5 for a Mario Moment", view=Buttons())
except discord.app_commands.errors.CommandInvokeError:
print("Uh oh! It failed!")
"""
#### Black Jack ####
"""
class HitOrStand(discord.ui.View):
def __init__(self, *, timeout=180):
super().__init__(timeout=timeout)
self.content = None
@discord.ui.button(label="Hit", style=discord.ButtonStyle.green)
async def hit(self, interaction: discord.Interaction, button: discord.ui.Button):
self.content = "h"
for child in self.children:
child.disabled = True
await interaction.response.edit_message(content="You Hit!", view=self)
self.stop()
@discord.ui.button(label="Stand", style=discord.ButtonStyle.red)
async def stand(self, interaction: discord.Interaction, button: discord.ui.Button):
self.content = "s"
for child in self.children:
child.disabled = True
await interaction.response.edit_message(content="You stood!", view=self)
self.stop()
@tree.command(description="Play Black Jack!")
async def bj(interaction: discord.Interaction):
discinput = lambda m: discordInput(interaction, m)
discoutput = lambda m: discordOutput(interaction, m)
await interaction.response.send_message("Let's play Black Jack!")
await blackJack.play_game(interaction.user.id, 100, discinput, discoutput)
async def discordInput(interaction: discord.Interaction, message:str):
response = HitOrStand()
await interaction.followup.send(message, view=response)
await response.wait()
return response.content
async def discordOutput(interaction: discord.Interaction, message):
await interaction.followup.send(message)
@tree.command(description="Find your Balance")
async def bal(interaction: discord.Interaction):
conn = sqlite3.connect("ledger.db")
cur = conn.cursor()
ID = interaction.user.id
data = cur.execute("SELECT * FROM ledger WHERE USERID = ?", (ID,))
await interaction.response.send_message(data)
"""
#### Calculator ####
"""
class Calculator(discord.ui.View):
def __init__(self, *, timeout=180):
super().__init__(timeout=timeout)
self.numDigs = 0
self.MAXIMUMBARSIZE = 30
m = 0
self.inputOne = 0
self.inputTwo = None
self.expression = None
self.output = None
self.digit = 1
self.addition = lambda x, y: x + y
self.subtraction = lambda x, y: x - y
self.multiplication = lambda x, y: x * y
self.division = lambda x, y: x / y
self.exponent = lambda x, y: x ** y
self.funckyDict = {
self.addition: "+",
self.subtraction: "-",
self.multiplication: "*",
self.division: "/",
self.exponent: "^"
}
def numDigits(self, integer):
numDigits = 0
while(integer):
numDigits += 1
integer = integer // 10
return numDigits
def display(self):
inputOneLength = self.numDigits(self.inputOne)
inputTwoLength = self.numDigits(self.inputTwo)
outputLength = self.numDigits(self.output)
if (self.inputTwo is None) and (self.output is None):
padding = self.MAXIMUMBARSIZE - inputOneLength - 1
displayOutput = " ".join(['`', ' ' * padding, f"{self.inputOne}", "`"])
elif (self.output is None):
padding = self.MAXIMUMBARSIZE - inputOneLength - inputTwoLength - 3
displayOutput = " ".join(['`', ' ' * padding, f"{self.inputTwo}", f"{self.funckyDict[self.expression]}", f"{self.inputOne}", "`"])
else:
padding = self.MAXIMUMBARSIZE - inputOneLength - inputTwoLength - outputLength - 4
displayOutput = " ".join(['`', ' ' * padding, f"{self.inputTwo}", f"{self.funckyDict[self.expression]}", f"{self.inputOne}", "=", f"{self.output}", "`"])
return displayOutput
async def number(self, interaction: discord.Interaction, number):
self.inputOne = self.inputOne * 10 + number
self.numDigs = self.numDigs + 1
await interaction.response.edit_message(
content=self.display(),
view=self)
async def operator(self, interaction: discord.Interaction, operation):
self.inputTwo = self.inputOne
self.inputOne = 0
self.expression = operation
await interaction.response.edit_message(
content=self.display(),
view=self)
@discord.ui.button(label="^", style=discord.ButtonStyle.red, row=4)
async def power(self, interaction: discord.Interaction, button: discord.ui.Button):
await self.operator(interaction, self.exponent)
@discord.ui.button(label="0", style=discord.ButtonStyle.blurple,row=4)
async def zero(self, interaction: discord.Interaction, button: discord.ui.Button):
await self.number(interaction, 0)
@discord.ui.button(label="1", style=discord.ButtonStyle.blurple, row=1)
async def one(self, interaction: discord.Interaction, button: discord.ui.Button):
await self.number(interaction, 1)
@discord.ui.button(label="2", style=discord.ButtonStyle.blurple, row=1)
async def two(self, interaction: discord.Interaction, button: discord.ui.Button):
await self.number(interaction, 2)
@discord.ui.button(label="3", style=discord.ButtonStyle.blurple, row=1)
async def three(self, interaction: discord.Interaction, button: discord.ui.Button):
await self.number(interaction, 3)
@discord.ui.button(label="4", style=discord.ButtonStyle.blurple, row=2)
async def four(self, interaction: discord.Interaction, button: discord.ui.Button):
await self.number(interaction, 4)
@discord.ui.button(label="5", style=discord.ButtonStyle.blurple, row=2)
async def five(self, interaction: discord.Interaction, button: discord.ui.Button):
await self.number(interaction, 5)
@discord.ui.button(label="6", style=discord.ButtonStyle.blurple, row=2)
async def six(self, interaction: discord.Interaction, button: discord.ui.Button):
await self.number(interaction, 6)
@discord.ui.button(label="7", style=discord.ButtonStyle.blurple, row=3)
async def seven(self, interaction: discord.Interaction, button: discord.ui.Button):
await self.number(interaction, 7)
@discord.ui.button(label="8", style=discord.ButtonStyle.blurple, row=3)
async def eight(self, interaction: discord.Interaction, button: discord.ui.Button):
await self.number(interaction, 8)
@discord.ui.button(label="9", style=discord.ButtonStyle.blurple, row=3)
async def nine(self, interaction: discord.Interaction, button: discord.ui.Button):
await self.number(interaction, 9)
@discord.ui.button(label="+", style=discord.ButtonStyle.red, row=1)
async def plus(self, interaction: discord.Interaction, button: discord.ui.Button):
await self.operator(interaction, self.addition)
@discord.ui.button(label="*", style=discord.ButtonStyle.red, row=2)
async def mult(self, interaction: discord.Interaction, button: discord.ui.Button):
await self.operator(interaction, self.multiplication)
@discord.ui.button(label="-", style=discord.ButtonStyle.red, row=3)
async def minus(self, interaction: discord.Interaction, button: discord.ui.Button):
await self.operator(interaction, self.subtraction)
@discord.ui.button(label="=", style=discord.ButtonStyle.green, row=4)
async def equals(self, interaction: discord.Interaction, button: discord.ui.Button):
self.output = self.expression(self.inputTwo, self.inputOne)
await interaction.response.edit_message(
content=self.display(),
view=self)
@discord.ui.button(label="/", style=discord.ButtonStyle.red, row=4)
async def divide(self, interaction: discord.Interaction, button: discord.ui.Button):
await self.operator(interaction, self.division)
@tree.command(description="Do Meth")
async def calculator(interaction: discord.Interaction):
await interaction.response.defer()
calculator = Calculator()
await interaction.followup.send(content="`" + " " * calculator.MAXIMUMBARSIZE + "0`", view=calculator)
"""
#### Fin ####
"""
client.run('NzgwNzg4NDIwMjkzMDM0MDA0.GEKkUB.Bbl09D3lWMGea_mcIESPMLUyGlkW-6N53BPFjI')

View File

@@ -1,210 +0,0 @@
import random
import Ledger
def convertNumberToCard(cardNumber):
# Cards index from 0 i.e ace is 0, and the highest card value is 51
if cardNumber <= 12:
cardSuit = ""
elif cardNumber <= 25:
cardSuit = ""
elif cardNumber <= 38:
cardSuit = ""
elif cardNumber <= 51:
cardSuit = ""
cardNumber = cardNumber % 13
if cardNumber == 0:
cardNumber = "A"
elif cardNumber == 10:
cardNumber = "J"
elif cardNumber == 11:
cardNumber = "Q"
elif cardNumber == 12:
cardNumber = "K"
else:
cardNumber += 1
return "{value}{suit} ".format(value=str(cardNumber), suit=cardSuit)
def generateDeck():
return [x for x in range(0, 51)]
def addCardToHand(hand, deck):
card = deck.pop(0)
hand.append(card)
def generateHand(hand, deck, handSize = 2):
i = 0
while i < handSize:
addCardToHand(hand, deck)
i += 1
def handNumbersToCards(hand):
cards = ""
for card in hand:
cards += convertNumberToCard(card)
return cards
def getHandTotal(hand):
cardValue = lambda c: min(c % 13 + 1, 10)
i = 0
for card in hand:
card = cardValue(card)
if (card == 1) and (i < 20):
card = 11
if (i + card) > 21:
card = 1
i += card
return i
def showDeck(deck):
string = ""
for card in deck:
string += convertNumberToCard(card)
return string
class BlackJack:
def __init__(self):
self.playerTurn = True
self.deck = generateDeck()
random.shuffle(self.deck)
self.discard = []
self.playerHand = []
self.dealerHand = []
self.ledger = Ledger.Ledger()
def getPH(self):
return self.playerHand
def getDH(self):
return self.dealerHand
def returnCards(self):
self.discard.extend(self.playerHand)
self.playerHand.clear()
self.discard.extend(self.dealerHand)
self.dealerHand.clear()
def deal(self):
generateHand(self.playerHand, self.deck)
generateHand(self.dealerHand, self.deck)
def shuffle(self):
self.deck.extend(self.discard)
self.discard.clear()
random.shuffle(self.deck)
def stand(self):
if self.playerTurn:
self.playerTurn = False
def hit(self):
if self.playerTurn:
addCardToHand(self.playerHand, self.deck)
self.playerTurn = False
else:
addCardToHand(self.dealerHand, self.deck)
self.playerTurn = True
def checkHandState(self, hand):
# Check the hand state and return w if game is won, l if lost and c for continue
total = getHandTotal(hand)
if total == 21:
return "w"
elif total > 21:
return "l"
else:
return "c"
def dealerHitLogic(self, hand):
total = getHandTotal()
if total > 17:
self.stand()
elif total <= 16:
self.hit()
def checkGameOver(self, state):
gameOver = False
if state == "w":
gameOver = True
elif state == "l":
gameOver = True
return gameOver
async def play_game(self, ID, bet, recv, send):
gameOver = False
playerStats = self.ledger.read(ID)
if playerStats is None:
self.ledger.write(ID)
playerStats = self.ledger.read
self.deal()
while not gameOver:
play = None
playerStood = False
validInput = False
playerWinState = self.checkHandState(self.playerHand)
dealerWinState = self.checkHandState(self.dealerHand)
gameOver = self.checkGameOver(playerWinState) or self.checkGameOver(dealerWinState)
if gameOver:
continue
await send("Players hand = " + str(getHandTotal(self.playerHand)) + ": " + handNumbersToCards(
self.playerHand) + "\n" + "Dealers hand = ??: " + convertNumberToCard(self.dealerHand[0]) + "??")
play = await recv("Hit or Stand? (h/s)")
while not validInput:
if play == "h":
self.hit()
validInput = True
elif play == "s":
self.stand()
validInput = True
playerStood = True
playerWinState = self.checkHandState(self.playerHand)
if self.checkGameOver(playerWinState):
continue
# Dealers turn
if playerStood:
while dealerWinState == 'c':
# Dealer hits
self.hit()
# Player stands
self.stand()
# Loop ends when game is over
dealerWinState = self.checkHandState(self.dealerHand)
else:
self.hit()
dealerWinState = self.checkHandState(self.dealerHand)
if self.checkGameOver(dealerWinState):
continue
await send("Players hand = " + str(getHandTotal(self.playerHand)) + ": " + handNumbersToCards(self.playerHand) +
"\n" + "Dealers hand = " + str(getHandTotal(self.dealerHand)) + ": " + handNumbersToCards(self.dealerHand))
if playerWinState == "w":
await send("You won!")
win = (2*bet, 1, 0, ID)
# self.ledger.updateLedger(playerStats, win)
elif playerWinState == "l":
await send("You busted!")
loss = (-bet, 0, 1, ID)
# self.ledger.updateLedger(playerStats, loss)
elif dealerWinState == "w":
await send("The Dealer reached 21 before you!")
loss = (-bet, 0, 1, ID)
# self.ledger.updateLedger(playerStats, loss)
elif dealerWinState == "l":
await send("The Dealer busted before you!")
win = (2*bet, 1, 0, ID)
# self.ledger.updateLedger(playerStats, win)
self.returnCards()
if len(self.deck) < 0.25 * 52:
await send("Shuffling Deck")
self.shuffle()

View File

@@ -0,0 +1,258 @@
import random
import Ledger
# Game States
INIT = 0
PLAYING = 1
ENDING = 2
FINISHED = 3
OVER = 5
CHECKING = 6
def convertNumberToCard(cardNumber):
# Cards index from 0 i.e ace is 0, and the highest card value is 51
if cardNumber <= 12:
cardSuit = ""
elif cardNumber <= 25:
cardSuit = ""
elif cardNumber <= 38:
cardSuit = ""
elif cardNumber <= 51:
cardSuit = ""
cardNumber = cardNumber % 13
if cardNumber == 0:
cardNumber = "A"
elif cardNumber == 10:
cardNumber = "J"
elif cardNumber == 11:
cardNumber = "Q"
elif cardNumber == 12:
cardNumber = "K"
else:
cardNumber += 1
return "{value}{suit} ".format(value=str(cardNumber), suit=cardSuit)
def generateDeck():
return [x for x in range(0, 51)]
def addCardToHand(hand, deck):
card = deck.pop(0)
hand.append(card)
def generateHand(hand, deck, handSize = 2):
i = 0
while i < handSize:
addCardToHand(hand, deck)
i += 1
def handNumbersToCards(hand):
cards = ""
for card in hand:
cards += convertNumberToCard(card)
return cards
def getHandTotal(hand):
cardValue = lambda c: min(c % 13 + 1, 10)
i = 0
aces = 0
for card in hand:
card = cardValue(card)
if card == 1:
aces += 1
else:
i += card
while aces > 0:
if i < 20:
card = 11
if (i + card) > 21:
card = 1
i += card
aces -= 1
return i
def showDeck(deck):
string = ""
for card in deck:
string += convertNumberToCard(card)
return string
class BlackJack:
def __init__(self):
self.gameInSession = False
self.playerTurn = True
self.deck = generateDeck()
random.shuffle(self.deck)
self.discard = []
self.playerHand = []
self.dealerHand = []
self.ledger = Ledger.Ledger()
def returnCards(self):
self.discard.extend(self.playerHand)
self.playerHand.clear()
self.discard.extend(self.dealerHand)
self.dealerHand.clear()
def deal(self):
generateHand(self.playerHand, self.deck)
generateHand(self.dealerHand, self.deck)
def shuffle(self):
self.deck.extend(self.discard)
self.discard.clear()
random.shuffle(self.deck)
def stand(self):
if self.playerTurn:
self.playerTurn = False
def hit(self):
if self.playerTurn:
addCardToHand(self.playerHand, self.deck)
self.playerTurn = False
else:
addCardToHand(self.dealerHand, self.deck)
self.playerTurn = True
def checkHandState(self, hand):
# Check the hand state and return w if game is won, l if lost and c for continue
total = getHandTotal(hand)
if total == 21:
return "w"
elif total > 21:
return "l"
else:
return "c"
def dealerHitLogic(self):
total = getHandTotal(self.dealerHand)
if total >= 17:
self.stand()
return True
else:
self.hit()
def checkGameOver(self, state):
gameOver = False
if state == "w":
gameOver = True
elif state == "l":
gameOver = True
return gameOver
def compareHands(self):
dealerTotal = getHandTotal(self.dealerHand)
playerTotal = getHandTotal(self.playerHand)
if dealerTotal < playerTotal:
return "l"
else:
return "w"
async def play_game(self, ID, bet, recv, send):
if self.gameInSession:
await send("Fuck you")
return
else:
self.gameInSession = True
gameState = INIT
while gameState != OVER:
if gameState == INIT:
self.returnCards()
playerStats = self.ledger.read(ID)
if playerStats is None:
self.ledger.write(ID)
playerStats = self.ledger.read(ID)
self.deal()
playerWinState = self.checkHandState(self.playerHand)
dealerWinState = self.checkHandState(self.dealerHand)
play = None
playerStood = False
dealerStood = False
validInput = False
gameState = CHECKING
elif gameState == PLAYING:
await send("Players hand = " + str(getHandTotal(self.playerHand)) + ": " + handNumbersToCards(
self.playerHand) + "\n" + "Dealers hand = ??: " + convertNumberToCard(self.dealerHand[0]) + "??")
play = await recv("Hit or Stand?")
while not validInput:
if play == "h":
self.hit()
validInput = True
elif play == "s":
self.stand()
playerStood = True
validInput = True
dealerStood = self.dealerHitLogic()
playerWinState = self.checkHandState(self.playerHand)
dealerWinState = self.checkHandState(self.dealerHand)
gameState = CHECKING
elif gameState == ENDING:
# Players turn
self.stand()
# Dealers turn
dealerStood = self.dealerHitLogic()
# Loop ends when game is over
dealerWinState = self.checkHandState(self.dealerHand)
if dealerStood:
if dealerWinState == "c":
dealerWinState = self.compareHands()
gameState = CHECKING
elif gameState == CHECKING:
if self.checkGameOver(playerWinState) or self.checkGameOver(dealerWinState):
gameState = FINISHED
elif playerStood:
gameState = ENDING
else:
gameState = PLAYING
elif gameState == FINISHED:
await send("Players hand = " + str(getHandTotal(self.playerHand)) + ": " + handNumbersToCards(self.playerHand) +
"\n" + "Dealers hand = " + str(getHandTotal(self.dealerHand)) + ": " + handNumbersToCards(self.dealerHand))
if playerWinState == "w":
await send("You won!")
win = (2*bet, 1, 0, ID)
self.ledger.update(ID, win)
elif playerWinState == "l":
await send("You busted!")
loss = (-bet, 0, 1, ID)
self.ledger.update(ID, loss)
elif dealerWinState == "w":
await send("The Dealer reached 21 before you!")
loss = (-bet, 0, 1, ID)
self.ledger.update(ID, loss)
elif dealerWinState == "l":
await send("The Dealer busted before you!")
win = (2*bet, 1, 0, ID)
self.ledger.update(ID, win)
self.returnCards()
if len(self.deck) < 0.25 * 52:
await send("Shuffling Deck")
self.shuffle()
gameState = OVER
self.gameInSession = False

View File

@@ -0,0 +1,271 @@
import random
import Ledger
# Game States
INIT = 0
PLAYING = 1
ENDING = 2
FINISHED = 3
OVER = 5
CHECKING = 6
def convertNumberToCard(cardNumber):
# Cards index from 0 i.e ace is 0, and the highest card value is 51
if cardNumber <= 12:
cardSuit = ""
elif cardNumber <= 25:
cardSuit = ""
elif cardNumber <= 38:
cardSuit = ""
elif cardNumber <= 51:
cardSuit = ""
cardNumber = cardNumber % 13
if cardNumber == 0:
cardNumber = "A"
elif cardNumber == 10:
cardNumber = "J"
elif cardNumber == 11:
cardNumber = "Q"
elif cardNumber == 12:
cardNumber = "K"
else:
cardNumber += 1
return "{value}{suit} ".format(value=str(cardNumber), suit=cardSuit)
def generateDeck():
return [x for x in range(0, 51)]
def addCardToHand(hand, deck):
card = deck.pop(0)
hand.append(card)
def generateHand(hand, deck, handSize = 2):
i = 0
while i < handSize:
addCardToHand(hand, deck)
i += 1
def handNumbersToCards(hand):
cards = ""
for card in hand:
cards += convertNumberToCard(card)
return cards
def getHandTotal(hand):
cardValue = lambda c: min(c % 13 + 1, 10)
i = 0
aces = 0
for card in hand:
card = cardValue(card)
if card == 1:
aces += 1
else:
i += card
while aces > 0:
if i < 20:
card = 11
if (i + card) > 21:
card = 1
i += card
aces -= 1
return i
def showDeck(deck):
string = ""
for card in deck:
string += convertNumberToCard(card)
return string
class BlackJack:
def __init__(self):
self.gameInSession = False
self.playerTurn = True
self.deck = generateDeck()
random.shuffle(self.deck)
self.discard = []
self.playerHand = []
self.dealerHand = []
self.ledger = Ledger.Ledger()
def returnCards(self):
self.discard.extend(self.playerHand)
self.playerHand.clear()
self.discard.extend(self.dealerHand)
self.dealerHand.clear()
def deal(self):
generateHand(self.playerHand, self.deck)
generateHand(self.dealerHand, self.deck)
def shuffle(self):
self.deck.extend(self.discard)
self.discard.clear()
random.shuffle(self.deck)
def stand(self):
if self.playerTurn:
self.playerTurn = False
def hit(self):
if self.playerTurn:
addCardToHand(self.playerHand, self.deck)
self.playerTurn = False
else:
addCardToHand(self.dealerHand, self.deck)
self.playerTurn = True
def checkHandState(self, hand):
# Check the hand state and return w if game is won, l if lost and c for continue
total = getHandTotal(hand)
if total == 21:
return "w"
elif total > 21:
return "l"
else:
return "c"
def dealerHitLogic(self):
total = getHandTotal(self.dealerHand)
if total > 17:
self.stand()
return True
else:
self.hit()
def checkGameOver(self, state):
gameOver = False
if state == "w":
gameOver = True
elif state == "l":
gameOver = True
return gameOver
def compareHands(self):
dealerTotal = getHandTotal(self.dealerHand)
playerTotal = getHandTotal(self.playerHand)
if dealerTotal < playerTotal:
return "l"
else:
return "w"
def play_game(self, ID, bet, recv, send):
if self.gameInSession:
send("Fuck you")
return
else:
self.gameInSession = True
gameState = INIT
while gameState != OVER:
if gameState == INIT:
self.returnCards()
playerStats = self.ledger.read(ID)
if playerStats is None:
self.ledger.write(ID)
playerStats = self.ledger.read(ID)
self.deal()
playerWinState = self.checkHandState(self.playerHand)
dealerWinState = self.checkHandState(self.dealerHand)
play = None
playerStood = False
dealerStood = False
validInput = False
gameState = CHECKING
elif gameState == PLAYING:
send("Players hand = " + str(getHandTotal(self.playerHand)) + ": " + handNumbersToCards(
self.playerHand) + "\n" + "Dealers hand = ??: " + convertNumberToCard(self.dealerHand[0]) + "??")
play = recv("Hit or Stand?")
while not validInput:
if play == "h":
self.hit()
validInput = True
elif play == "s":
self.stand()
playerStood = True
validInput = True
dealerStood = self.dealerHitLogic()
playerWinState = self.checkHandState(self.playerHand)
dealerWinState = self.checkHandState(self.dealerHand)
gameState = CHECKING
elif gameState == ENDING:
# Players turn
self.stand()
# Dealers turn
dealerStood = self.dealerHitLogic()
# Loop ends when game is over
dealerWinState = self.checkHandState(self.dealerHand)
if dealerStood:
if dealerWinState == "c":
dealerWinState = self.compareHands()
gameState = CHECKING
elif gameState == CHECKING:
if self.checkGameOver(playerWinState) or self.checkGameOver(dealerWinState):
gameState = FINISHED
elif playerStood:
gameState = ENDING
else:
gameState = PLAYING
elif gameState == FINISHED:
send("Players hand = " + str(getHandTotal(self.playerHand)) + ": " + handNumbersToCards(self.playerHand) +
"\n" + "Dealers hand = " + str(getHandTotal(self.dealerHand)) + ": " + handNumbersToCards(self.dealerHand))
if playerWinState == "w":
send("You won!")
win = (2*bet, 1, 0, ID)
self.ledger.update(ID, win)
elif playerWinState == "l":
send("You busted!")
loss = (-bet, 0, 1, ID)
self.ledger.update(ID, loss)
elif dealerWinState == "w":
send("The Dealer reached 21 before you!")
loss = (-bet, 0, 1, ID)
self.ledger.update(ID, loss)
elif dealerWinState == "l":
send("The Dealer busted before you!")
win = (2*bet, 1, 0, ID)
self.ledger.update(ID, win)
self.returnCards()
if len(self.deck) < 0.25 * 52:
send("Shuffling Deck")
self.shuffle()
gameState = OVER
self.gameInSession = False
def send(str):
return input(str)
def main():
bj = BlackJack()
bj.play_game(12, 100, send, print)
if __name__ == "__main__":
main()

Binary file not shown.

11
docker-compose.yml Normal file
View File

@@ -0,0 +1,11 @@
version: "3.3"
volumes:
networks:
services:
acronymbot:
build: ./src/py
volumes:
- "./src/py:/usr/app/src"

Binary file not shown.

65
list.txt Normal file
View File

@@ -0,0 +1,65 @@
Schemas -
GAMEINFO:
ID, NAME, GENRE, GAMEPASS
WHOOWNSIT (bitmap index):
ID, MARCUS, BENSON, ALEX, TIM
GAMEFACTORS:
ID, BRAINLEVEL, TIMETOPLAY, CAMPAIGN
Satisfactory MBA
Factorio MBA
Magicka 2 MBAT
Phasmo MBA
RS6 MBAT
VCD MBA
DRG MBAT
Star Dew MBA
Minecraft MBAT
TTSim MBAT
BTD6 MBAT
ARMA3 MBA
Blood and Bacon MBAT
NMRIH MBAT
GMOD MBAT
INSIDE THE BACKROOMS MBAT
PZ MBAT
READY OR NOT MBAT
SCP MBAT
WITCH IT MBA
BAUROTRAUMA MA
BORDERLANDS 3 MBA
BORDERLANDS 2 MBA
BORDERLANDS THE PRE SEQUEL MBA
CSGO MBA
GTAV MBA
CREATIVERSE MBA
Dying Light MBA
The forest MBA
RDRO MBAT
Risk of Rain MBAT
ROTMG MBAT
L4D2 MBAT
Unturned MBAT
Due Process MBA
Valorant MBAT
Terraria MA
Modded Minecraft MBAT
Warframe MBAT
Ghost recon wildlands (if tim buys)
Ghost Recon Breakpoint MBA
Rocket League BM
OW2 MBAT
ROBLOX MBAT (Prison Royale)
Gamepass Game:
Aragami
Sea of theives
Astroneer
GWYF
No Mans Sky
Valheim
Power Wash Sim
B4B

5
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

145
src/py/Acronymbot.py Normal file
View File

@@ -0,0 +1,145 @@
import random
import discord
import sqlite3
from discord import app_commands
from BlackJack import BlackJack
from Calculator import Calculator
from Gamepicker import pick_game
botIntents = discord.Intents.all()
client = discord.Client(intents=botIntents)
tree = app_commands.CommandTree(client)
blackJack = BlackJack()
@client.event
async def on_ready():
await tree.sync()
print('Itsa me Mario!')
# @client.event
# async def on_message_delete(message: discord.Message):
# channel = client.get_channel(message.channel.id)
# await channel.send(f"{message.author} deleted a message! @everyone, get him!")
# dmessage = await channel.send(f"Here's the message they deleted! \"{message.content}\". What a sick fuck")
# await dmessage.delete()
"""
#### Test ####
"""
class Buttons(discord.ui.View):
def __init__(self, *, timeout=180):
super().__init__(timeout=timeout)
@discord.ui.button(label="Pay $5", style=discord.ButtonStyle.green)
async def green_button(self, interaction: discord.Interaction, button: discord.ui.Button):
print(f"{interaction.user} pressed the green button")
button.disabled = True
button.label = "No Refunds!"
for child in self.children:
child.disabled = True
await interaction.response.edit_message(content=f"Mario Moment Achieved", view=self)
@discord.ui.button(label="Punch AcryBot", style=discord.ButtonStyle.red)
async def red_button(self, interaction: discord.Interaction, button: discord.ui.Button):
print(f"{interaction.user} pressed the red button")
button.disabled = True
button.label = f"fuck you {interaction.user}"
for child in self.children:
child.disabled = True
await interaction.response.edit_message(content=f"Ouch!", view=self)
@tree.command(description="Lmao")
async def test(interaction:discord.Interaction):
print(f"{interaction.user} used command! Woohoo!")
try:
await interaction.response.send_message("Pay $5 for a Mario Moment", view=Buttons())
except discord.app_commands.errors.CommandInvokeError:
print("Uh oh! It failed!")
"""
#### Black Jack ####
"""
class HitOrStand(discord.ui.View):
def __init__(self, *, timeout=180):
super().__init__(timeout=timeout)
self.content = False
@discord.ui.button(label="Hit", style=discord.ButtonStyle.green)
async def hit(self, interaction: discord.Interaction, button: discord.ui.Button):
self.content = True
for child in self.children:
child.disabled = True
await interaction.response.edit_message(content="You Hit!", view=self)
self.stop()
@discord.ui.button(label="Stand", style=discord.ButtonStyle.red)
async def stand(self, interaction: discord.Interaction, button: discord.ui.Button):
self.content = False
for child in self.children:
child.disabled = True
await interaction.response.edit_message(content="You stood!", view=self)
self.stop()
@tree.command(description="Play Black Jack!")
async def bj(interaction: discord.Interaction):
discinput = lambda m: discordInput(interaction, m)
discoutput = lambda m: discordOutput(interaction, m)
await interaction.response.send_message("Let's play Black Jack!")
await blackJack.play_game(interaction.user.id, 100, discinput, discoutput)
async def discordInput(interaction: discord.Interaction, message:str):
response = HitOrStand()
await interaction.followup.send(message, view=response)
await response.wait()
return response.content
async def discordOutput(interaction: discord.Interaction, message):
await interaction.followup.send(message)
@tree.command(description="Find your Balance")
async def bal(interaction: discord.Interaction):
ID = interaction.user.id
data = blackJack.ledger.read(ID)
data = list(data)
await interaction.response.send_message(f"Wins:{data[2]}, Losses:{data[3]}. ${data[1]}")
"""
#### Calculator ####
"""
@tree.command(description="Do Meth")
async def calculator(interaction: discord.Interaction):
await interaction.response.defer()
calculator = Calculator()
await interaction.followup.send(content="`" + " " * calculator.MAXIMUMBARSIZE + "0`", view=calculator)
"""
#### Game Picker ####
"""
@tree.command(description="Pick a game")
async def gg(interaction: discord.Interaction):
game = pick_game()
await interaction.response.send_message("Barotrauma")
@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}")
"""
#### Fin ####
"""
client.run('NzgwNzg4NDIwMjkzMDM0MDA0.GEKkUB.Bbl09D3lWMGea_mcIESPMLUyGlkW-6N53BPFjI')

350
src/py/BlackJack.py Normal file
View File

@@ -0,0 +1,350 @@
import random
from Ledger import Ledger
#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 Make each game session more distinct (Embeds?)
# Game States
INIT = 0
PLAYERTURN = 1
DEALERTURN = 2
FINISHED = 3
OVER = 5
"""
Class which describes playing cards
"""
class Card():
"""
A joker card has value 0 and suit 0
"""
HEARTS = 1
DIAMONDS = 2
SPADES = 3
CLUBS = 4
def __init__(self, value, suit) -> None:
self.value = value
self.suit = suit
self.hidden = False
def hide_card(self):
self.hidden = True
def show_card(self):
self.hidden = False
def get_value(self):
return self.value
def get_suit(self):
return self.suit
def __str__(self) -> str:
suits = ["J", "", "", "", ""]
special_cards = {1: "A", 11: "J", 12: "Q", 13: "K"}
strValue = ""
if self.value in special_cards.keys():
strValue = special_cards[self.value]
else:
strValue = str(self.value)
string = ""
string = f"{suits[self.suit]}{strValue}"
if self.hidden:
string = "??"
return string
def __repr__(self) -> str:
return str(self)
"""
Class for interacting with a deck of cards
"""
class Deck():
def __init__(self, joker = False) -> None:
self.deck = []
self.discard = []
self.joker = joker
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, 14)])
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, 14)])
print(len(self.deck))
if joker:
self.deck.append(Card(0, 0))
def shuffle(self):
random.shuffle(self.deck)
def sort(self):
self.deck.sort()
def take_from_deck(self):
card = self.deck.pop()
return card
def return_to_deck_top(self, card):
self.deck.insert(0, card)
def returnToDeckBottom(self, card):
self.deck.append(card)
def addToDiscard(self, card):
self.discard.insert(0, card)
def returnFromDiscard(self):
self.returnToDeckTop(self.discard.pop())
def return_all_from_discard(self):
self.deck.extend(self.discard)
self.discard = []
def __str__(self) -> str:
string = ""
for card in self.deck:
string += str(card)
return string
def __len__(self):
return len(self.deck)
class Hand():
def __init__(self) -> None:
self.hand = []
self.hidden_cards = []
def sortHand(self):
self.hand.sort()
def add_to_hand(self, card, index = None):
if index is None:
self.hand.append(card)
else:
self.hand.insert(index, card)
def remove_from_hand(self, index):
return self.hand.pop(index)
def peek_card(self, index):
return self.hand[index]
def hide_card(self, index):
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):
for card in self.hidden_cards:
card.show_card()
self.hidden_cards.remove(card)
def __len__(self):
return len(self.hand)
def __str__(self) -> str:
string = ""
for card in self.hand:
string += str(card)
string += " "
return string
def __repr__(self) -> str:
value = 0
aces = 0
# Add static values
for card in self.hand:
if card.value == 1:
aces += 1
continue
if card.value > 10:
value += 10
continue
value += card.value
# Dynamically add ace value based on ideal rules
maxAceValue = aces * 11
tempValue = value + maxAceValue
if tempValue < 21:
return str(tempValue)
while (tempValue > 21) and aces > 0:
tempValue = tempValue - 10
aces = aces - 1
value = tempValue
return str(value)
def __iter__(self):
self.iter = iter(self.hand)
return self.iter
def __next__(self):
return next(self.iter)
class BlackJack:
def __init__(self) -> None:
self.deck = Deck()
self.playerHand = Hand()
self.dealerHand = Hand()
self.ledger = Ledger()
self.playing = False
def deal_card(self, hand):
hand.add_to_hand(self.deck.take_from_deck())
def game_setup(self):
# Deal cards in alternate order
self.deck.shuffle()
for _ in range(2):
self.deal_card(self.playerHand)
self.deal_card(self.dealerHand)
# Hide one of the dealers cards
self.dealerHand.hide_card(1)
def discard_hand(self, hand):
hand.show_hand()
for _ in range(len(hand)):
card = hand.remove_from_hand(0)
self.deck.addToDiscard(card)
async def show_cards(self, send, displayDealerScore=False):
# Show Cards to player
string = f"Player Hand = {repr(self.playerHand)}: {self.playerHand}\nDealer Hand = ??: {self.dealerHand}"
if displayDealerScore:
string = f"Player Hand = {repr(self.playerHand)}: {self.playerHand}\nDealer Hand = {repr(self.dealerHand)}: {self.dealerHand}"
await send(string)
async def play_game(self, ID, bet, recv, send):
if self.playing:
await send("Game in Progress")
return
else:
self.playing = True
gameState = INIT
while gameState != OVER:
if gameState == INIT:
playerStats = self.ledger.read(ID)
if playerStats is None:
self.ledger.write(ID)
playerStats = self.ledger.read(ID)
self.game_setup()
gameState = PLAYERTURN
if int(repr(self.playerHand)) >= 21:
gameState = FINISHED
if gameState == PLAYERTURN:
await self.show_cards(send)
playerHit = await recv("Hit or Stand?")
if playerHit:
self.deal_card(self.playerHand)
else:
gameState = DEALERTURN
if int(repr(self.playerHand)) >= 21:
gameState = FINISHED
if gameState == DEALERTURN:
if int(repr(self.dealerHand)) > int(repr(self.playerHand)):
gameState = FINISHED
continue
self.deal_card(self.dealerHand)
if int(repr(self.dealerHand)) >= 17:
gameState = FINISHED
if gameState == FINISHED:
self.dealerHand.show_hand()
playerBlackJack = False
dealerBlackJack = False
playerBust = False
dealerBust = False
playerHigher = False
dealerHigher = False
tie = False
playerScore = int(repr(self.playerHand))
dealerScore = int(repr(self.dealerHand))
await self.show_cards(send, True)
if playerScore == 21:
playerBlackJack = True
if dealerScore == 21:
dealerBlackJack = True
if playerScore > 21:
playerBust = True
if dealerScore > 21:
dealerBust = True
if dealerScore > playerScore:
dealerHigher = True
elif playerScore > dealerScore:
playerHigher = True
else:
tie = True
self.discard_hand(self.playerHand)
self.discard_hand(self.dealerHand)
if tie:
await send("You tied")
elif playerBlackJack:
await send("You reached BlackJack!")
win = (2*bet, 1, 0, ID)
self.ledger.update(ID, win)
elif dealerBlackJack:
await send("The dealer reached BlackJack!")
loss = (-bet, 0, 1, ID)
self.ledger.update(ID, loss)
elif playerBust:
await send("You busted!")
loss = (-bet, 0, 1, ID)
self.ledger.update(ID, loss)
elif dealerBust:
await send("The dealer busted!")
win = (2*bet, 1, 0, ID)
self.ledger.update(ID, win)
elif playerHigher:
await send("You won!")
win = (2*bet, 1, 0, ID)
self.ledger.update(ID, win)
elif dealerHigher:
await send("You lost!")
loss = (-bet, 0, 1, ID)
self.ledger.update(ID, loss)
else:
await send("Report this game to my creator!")
if len(self.deck) < 0.25 * 51:
self.deck.return_all_from_discard()
self.deck.shuffle()
await send("Everyday I'm shuffling")
gameState = OVER
self.playing = False
def main():
game = BlackJack()
trueFalseInput = lambda x: input(x) == "h"
game.play_game(recv=trueFalseInput, send=print)
pass
if __name__ == "__main__":
main()

151
src/py/Calculator.py Normal file
View File

@@ -0,0 +1,151 @@
import discord
addition = lambda x, y: x + y
subtraction = lambda x, y: x - y
multiplication = lambda x, y: x * y
division = lambda x, y: x / y
exponent = lambda x, y: x ** y
funckyDict = {
addition: "+",
subtraction: "-",
multiplication: "*",
division: "/",
exponent: "^"
}
async def number(self, interaction: discord.Interaction, number):
if self.output is not None:
self.inputOne = 0
self.output = None
self.inputOne = self.inputOne * 10 + number
self.numDigs = self.numDigs + 1
await interaction.response.edit_message(
content=self.display(),
view=self)
async def operator(self, interaction: discord.Interaction, operation):
self.output = None
self.inputTwo = self.inputOne
self.inputOne = 0
self.expression = operation
await interaction.response.edit_message(
content=self.display(),
view=self)
class NumberButton(discord.ui.Button):
def __init__(self, number: int, row) -> None:
super().__init__()
self.number = number
self.row = row
self.style = discord.ButtonStyle.blurple
self.label = str(number)
async def callback(self, interaction: discord.Interaction):
await number(self.view, interaction, self.number)
class OperatorButton(discord.ui.Button):
def __init__(self, function, row) -> None:
super().__init__()
self.function = function
self.row = row
self.style = discord.ButtonStyle.red
self.label = funckyDict[function]
async def callback(self, interaction: discord.Interaction):
await operator(self.view, interaction, self.function)
class Calculator(discord.ui.View):
def __init__(self, *, timeout=180):
super().__init__(timeout=timeout)
self.numDigs = 0
self.MAXIMUMBARSIZE = 30
m = 0
self.inputOne = 0
self.inputTwo = None
self.expression = None
self.output = None
self.digit = 1
self.clearRequirement = 0
numRows = 4
numColumns = 4
buttonFunctions = [
[1, 2, 3, addition],
[4, 5, 6, multiplication],
[7, 8, 9, subtraction],
[exponent, 0, None, division]
]
for i in range(0, numRows):
for j in range(0, numColumns):
item = buttonFunctions[i][j]
if item is None:
continue
if isinstance(item, int):
button = NumberButton(item, i)
else:
button = OperatorButton(item, i)
self.add_item(button)
def numDigits(self, integer):
numDigits = 0
while(integer):
numDigits += 1
integer = integer // 10
return numDigits
def clear(self):
self.inputOne = 0
self.inputTwo = None
self.output = None
self.clearRequirement = 0
def display(self):
inputOneLength = self.numDigits(self.inputOne)
inputTwoLength = self.numDigits(self.inputTwo)
outputLength = self.numDigits(self.output)
if (self.inputTwo is None) and (self.output is None):
padding = self.MAXIMUMBARSIZE - inputOneLength - 1
displayOutput = " ".join(['`', ' ' * padding, f"{self.inputOne}", "`"])
elif (self.output is None):
padding = self.MAXIMUMBARSIZE - inputOneLength - inputTwoLength - 3
displayOutput = " ".join(['`', ' ' * padding, f"{self.inputTwo}", f"{funckyDict[self.expression]}", f"{self.inputOne}", "`"])
else:
padding = self.MAXIMUMBARSIZE - inputOneLength - inputTwoLength - outputLength - 4
displayOutput = " ".join(['`', ' ' * padding, f"{self.inputTwo}", f"{funckyDict[self.expression]}", f"{self.inputOne}", "=", f"{self.output}", "`"])
return displayOutput
@discord.ui.button(label="=", style=discord.ButtonStyle.green, row=3)
async def equals(self, interaction: discord.Interaction, button: discord.ui.Button):
if self.inputTwo is None:
await interaction.response.edit_message(
content="ERROR",
view=self)
if self.clearRequirement:
self.clearRequirement = 0
self.clear()
else:
self.clearRequirement += 1
self.output = self.expression(self.inputTwo, self.inputOne)
if (self.inputTwo == 9) and (self.inputOne == 10) and (self.expression == addition):
self.output = 21
await interaction.response.edit_message(
content=self.display(),
view=self)
self.inputOne = self.output
self.inputTwo = None

View File

@@ -4,8 +4,7 @@ RUN pip install discord
WORKDIR /usr/app/src
COPY Acronymbot.py ./
COPY BlackJack.py ./
COPY Ledger.py ./
VOLUME /usr/app/src
# -v flag to mount to this volume. -v [from]:/usr/app/src
CMD [ "python", "./Acronymbot.py" ]

35
src/py/Gamepicker.py Normal file
View File

@@ -0,0 +1,35 @@
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"
# ]
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

@@ -14,9 +14,12 @@ class Database():
self.data.execute(insertQuery, (ID,))
self.db.commit()
def update(self, data, newData, updateQuery):
def update(self, ID, data, newData, updateQuery):
data = [data[i] + newData[i] for i in range(len(data))]
data.append(ID)
self.data.execute(updateQuery, data)
self.db.commit()
class Ledger(Database):
def __init__(self) -> None:
@@ -37,15 +40,16 @@ class Ledger(Database):
def write(self, ID):
insertQuery = """ INSERT INTO ledger(USERID)
VALUES(?) """
super().read(ID, insertQuery)
super().write(ID, insertQuery)
def update(self, data, newData):
def update(self, ID, newData):
query = """ UPDATE ledger
SET MONEY = ?,
WINS = ?,
LOSSES = ?,
LOSSES = ?
WHERE USERID = ?"""
super().update(data, newData, query)
data = list(self.read(ID))[1:]
super().update(ID, data, newData, query)
def main():
pass

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.