Merge branch 'master' of https://github.com/NikolajDanger/Gwendolyn
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -162,4 +162,5 @@ resources/lookup/monsters.json
|
|||||||
resources/lookup/spells.json
|
resources/lookup/spells.json
|
||||||
resources/movies.txt
|
resources/movies.txt
|
||||||
resources/names.txt
|
resources/names.txt
|
||||||
|
resources/users.json
|
||||||
gwendolynTest.py
|
gwendolynTest.py
|
||||||
|
67
Gwendolyn.py
67
Gwendolyn.py
@ -10,7 +10,7 @@ import random
|
|||||||
#import math
|
#import math
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from funcs import helloFunc, cap, imageFunc, logThis, findWikiPage, makeFiles, emojiToNumber, fiarReactionTest, deleteGame, stopServer, checkBalance, giveMoney, triviaCountPoints, triviaStart, triviaAnswer, blackjackShuffle, blackjackStart, blackjackPlayerDrawHand, blackjackContinue, blackjackFinish, blackjackHit, blackjackStand, blackjackDouble, blackjackSplit, parseFourInARow, fourInARowAI, spellFunc, monsterFunc, nameGen, tavernGen, movieFunc, roll_dice, parseChar, parseRoll, critRoll, parseDestiny, parseHex
|
from funcs import helloFunc, cap, imageFunc, logThis, findWikiPage, makeFiles, emojiToNumber, fiarReactionTest, deleteGame, stopServer, checkBalance, giveMoney, triviaCountPoints, triviaStart, triviaAnswer, blackjackShuffle, blackjackStart, blackjackPlayerDrawHand, blackjackContinue, blackjackFinish, blackjackHit, blackjackStand, blackjackDouble, blackjackSplit, parseFourInARow, fourInARowAI, spellFunc, monsterFunc, nameGen, tavernGen, movieFunc, roll_dice, parseChar, parseRoll, critRoll, parseDestiny, parseHex, addToDict
|
||||||
|
|
||||||
from gameLoops import fiar, blackjackLoop, runhex
|
from gameLoops import fiar, blackjackLoop, runhex
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ async def parseCommands(message,content):
|
|||||||
# Stops the bot
|
# Stops the bot
|
||||||
elif content.startswith("stop"):
|
elif content.startswith("stop"):
|
||||||
try:
|
try:
|
||||||
if message.author.display_name == "Nikolaj":
|
if "#"+str(message.author.id) == "#266269899859427329":
|
||||||
await message.channel.send("Logging out...")
|
await message.channel.send("Logging out...")
|
||||||
|
|
||||||
stopServer()
|
stopServer()
|
||||||
@ -220,7 +220,7 @@ async def parseCommands(message,content):
|
|||||||
elif content.startswith("swroll"):
|
elif content.startswith("swroll"):
|
||||||
try:
|
try:
|
||||||
command = cap(content.replace("swroll",""))
|
command = cap(content.replace("swroll",""))
|
||||||
newMessage = parseRoll(message.author.display_name,command)
|
newMessage = parseRoll("#"+str(message.author.id),command)
|
||||||
messageList = newMessage.split("\n")
|
messageList = newMessage.split("\n")
|
||||||
for messageItem in messageList:
|
for messageItem in messageList:
|
||||||
await message.channel.send(messageItem)
|
await message.channel.send(messageItem)
|
||||||
@ -232,7 +232,7 @@ async def parseCommands(message,content):
|
|||||||
elif content.startswith("swd"):
|
elif content.startswith("swd"):
|
||||||
try:
|
try:
|
||||||
command = content.replace("swd","")
|
command = content.replace("swd","")
|
||||||
newMessage = parseDestiny(message.author.display_name,command)
|
newMessage = parseDestiny("#"+str(message.author.id),command)
|
||||||
messageList = newMessage.split("\n")
|
messageList = newMessage.split("\n")
|
||||||
for messageItem in messageList:
|
for messageItem in messageList:
|
||||||
await message.channel.send(messageItem)
|
await message.channel.send(messageItem)
|
||||||
@ -266,7 +266,7 @@ async def parseCommands(message,content):
|
|||||||
elif content.startswith("swchar") or content.startswith("sw"):
|
elif content.startswith("swchar") or content.startswith("sw"):
|
||||||
try:
|
try:
|
||||||
command = string.capwords(content.replace("swchar","").replace("sw","").replace("+","+ ").replace("-","- ").replace(",",", "))
|
command = string.capwords(content.replace("swchar","").replace("sw","").replace("+","+ ").replace("-","- ").replace(",",", "))
|
||||||
title, desc = parseChar(message.author.display_name,command)
|
title, desc = parseChar("#"+str(message.author.id),command)
|
||||||
if title != "":
|
if title != "":
|
||||||
em1 = discord.Embed(title = title, description = desc, colour=0xDEADBF)
|
em1 = discord.Embed(title = title, description = desc, colour=0xDEADBF)
|
||||||
await message.channel.send(embed = em1)
|
await message.channel.send(embed = em1)
|
||||||
@ -323,7 +323,7 @@ async def parseCommands(message,content):
|
|||||||
|
|
||||||
elif content.startswith("trivia "):
|
elif content.startswith("trivia "):
|
||||||
command = content.replace("trivia ","")
|
command = content.replace("trivia ","")
|
||||||
response = triviaAnswer(message.author.display_name.lower(),str(message.channel),command)
|
response = triviaAnswer("#"+str(message.author.id),str(message.channel),command)
|
||||||
if response.startswith("Locked in "):
|
if response.startswith("Locked in "):
|
||||||
await message.add_reaction("👍")
|
await message.add_reaction("👍")
|
||||||
else:
|
else:
|
||||||
@ -339,7 +339,7 @@ async def parseCommands(message,content):
|
|||||||
# Checks your GwendoBucks balance
|
# Checks your GwendoBucks balance
|
||||||
elif content.startswith("balance"):
|
elif content.startswith("balance"):
|
||||||
try:
|
try:
|
||||||
response = checkBalance(message.author.display_name.lower())
|
response = checkBalance("#"+str(message.author.id))
|
||||||
if response == 1:
|
if response == 1:
|
||||||
new_message = message.author.display_name + " has " + str(response) + " GwendoBuck"
|
new_message = message.author.display_name + " has " + str(response) + " GwendoBuck"
|
||||||
else:
|
else:
|
||||||
@ -360,7 +360,7 @@ async def parseCommands(message,content):
|
|||||||
logThis("Conversion error (error code 1221)",str(message.channel))
|
logThis("Conversion error (error code 1221)",str(message.channel))
|
||||||
await message.channel.send("I didn't quite understand that (error code 1221)")
|
await message.channel.send("I didn't quite understand that (error code 1221)")
|
||||||
else:
|
else:
|
||||||
response = giveMoney(message.author.display_name.lower(),commands[1],amount)
|
response = giveMoney("#"+str(message.author.id),commands[1],amount)
|
||||||
await message.channel.send(response)
|
await message.channel.send(response)
|
||||||
else:
|
else:
|
||||||
logThis("I didn't understand that (error code 1222)",str(message.channel))
|
logThis("I didn't understand that (error code 1222)",str(message.channel))
|
||||||
@ -371,7 +371,7 @@ async def parseCommands(message,content):
|
|||||||
|
|
||||||
# Runs a game of Blackjack
|
# Runs a game of Blackjack
|
||||||
elif content.startswith("blackjack"):
|
elif content.startswith("blackjack"):
|
||||||
#try:
|
try:
|
||||||
# Starts the game
|
# Starts the game
|
||||||
if content == "blackjack" or content == "blackjack ":
|
if content == "blackjack" or content == "blackjack ":
|
||||||
cardsLeft = 0
|
cardsLeft = 0
|
||||||
@ -426,20 +426,20 @@ async def parseCommands(message,content):
|
|||||||
logThis("I didn't understand that",str(message.channel))
|
logThis("I didn't understand that",str(message.channel))
|
||||||
response = "I didn't understand that"
|
response = "I didn't understand that"
|
||||||
else:
|
else:
|
||||||
response = blackjackPlayerDrawHand(str(message.channel),message.author.display_name,amount)
|
response = blackjackPlayerDrawHand(str(message.channel),"#"+str(message.author.id),amount)
|
||||||
await message.channel.send(response)
|
await message.channel.send(response)
|
||||||
|
|
||||||
# Hitting
|
# Hitting
|
||||||
elif content.startswith("blackjack hit"):
|
elif content.startswith("blackjack hit"):
|
||||||
if content == "blackjack hit" or content == "blackjack hit ":
|
if content == "blackjack hit" or content == "blackjack hit ":
|
||||||
response = blackjackHit(str(message.channel),message.author.display_name)
|
response = blackjackHit(str(message.channel),"#"+str(message.author.id))
|
||||||
else:
|
else:
|
||||||
commands = content.split(" ")
|
commands = content.split(" ")
|
||||||
try:
|
try:
|
||||||
handNumber = int(commands[2])
|
handNumber = int(commands[2])
|
||||||
except:
|
except:
|
||||||
handNumber = 0
|
handNumber = 0
|
||||||
response = blackjackHit(str(message.channel),message.author.display_name,handNumber)
|
response = blackjackHit(str(message.channel),"#"+str(message.author.id),handNumber)
|
||||||
|
|
||||||
if response.startswith("accept"):
|
if response.startswith("accept"):
|
||||||
await message.add_reaction("👍")
|
await message.add_reaction("👍")
|
||||||
@ -450,7 +450,7 @@ async def parseCommands(message,content):
|
|||||||
logThis("Hit calling blackjackLoop()",str(message.channel))
|
logThis("Hit calling blackjackLoop()",str(message.channel))
|
||||||
await blackjackLoop(message.channel,int(response[7:])+1,gameID)
|
await blackjackLoop(message.channel,int(response[7:])+1,gameID)
|
||||||
except:
|
except:
|
||||||
logThis("Something fucked up",str(message.channel))
|
logThis("Something fucked up (error code 1320)",str(message.channel))
|
||||||
else:
|
else:
|
||||||
await message.channel.send(response)
|
await message.channel.send(response)
|
||||||
|
|
||||||
@ -458,14 +458,14 @@ async def parseCommands(message,content):
|
|||||||
# Standing
|
# Standing
|
||||||
elif content.startswith("blackjack stand"):
|
elif content.startswith("blackjack stand"):
|
||||||
if content == "blackjack hit" or content == "blackjack hit ":
|
if content == "blackjack hit" or content == "blackjack hit ":
|
||||||
response = blackjackStand(str(message.channel),message.author.display_name)
|
response = blackjackStand(str(message.channel),"#"+str(message.author.id))
|
||||||
else:
|
else:
|
||||||
commands = content.split(" ")
|
commands = content.split(" ")
|
||||||
try:
|
try:
|
||||||
handNumber = int(commands[2])
|
handNumber = int(commands[2])
|
||||||
except:
|
except:
|
||||||
handNumber = 0
|
handNumber = 0
|
||||||
response = blackjackStand(str(message.channel),message.author.display_name,handNumber)
|
response = blackjackStand(str(message.channel),"#"+str(message.author.id),handNumber)
|
||||||
|
|
||||||
if response.startswith("accept"):
|
if response.startswith("accept"):
|
||||||
await message.add_reaction("👍")
|
await message.add_reaction("👍")
|
||||||
@ -476,8 +476,7 @@ async def parseCommands(message,content):
|
|||||||
logThis("Stand calling blackjackLoop()",str(message.channel))
|
logThis("Stand calling blackjackLoop()",str(message.channel))
|
||||||
await blackjackLoop(message.channel,int(response[7:])+1,gameID)
|
await blackjackLoop(message.channel,int(response[7:])+1,gameID)
|
||||||
except:
|
except:
|
||||||
logThis("Something fucked up",str(message.channel))
|
logThis("Something fucked up (error code 1320)",str(message.channel))
|
||||||
await message.channel.send("something fucked up")
|
|
||||||
else:
|
else:
|
||||||
await message.channel.send(response)
|
await message.channel.send(response)
|
||||||
|
|
||||||
@ -488,7 +487,7 @@ async def parseCommands(message,content):
|
|||||||
handNumber = int(commands[2])
|
handNumber = int(commands[2])
|
||||||
except:
|
except:
|
||||||
handNumber = 0
|
handNumber = 0
|
||||||
response, roundDone = blackjackDouble(str(message.channel),message.author.display_name,handNumber)
|
response, roundDone = blackjackDouble(str(message.channel),"#"+str(message.author.id),handNumber)
|
||||||
|
|
||||||
await message.channel.send(response)
|
await message.channel.send(response)
|
||||||
|
|
||||||
@ -499,7 +498,7 @@ async def parseCommands(message,content):
|
|||||||
logThis("Double calling blackjackLoop()",str(message.channel))
|
logThis("Double calling blackjackLoop()",str(message.channel))
|
||||||
await blackjackLoop(message.channel,int(roundDone[1:])+1,gameID)
|
await blackjackLoop(message.channel,int(roundDone[1:])+1,gameID)
|
||||||
except:
|
except:
|
||||||
logThis("Something fucked up",str(message.channel))
|
logThis("Something fucked up (error code 1320)",str(message.channel))
|
||||||
|
|
||||||
# Splitting hand
|
# Splitting hand
|
||||||
elif content.startswith("blackjack split"):
|
elif content.startswith("blackjack split"):
|
||||||
@ -508,7 +507,7 @@ async def parseCommands(message,content):
|
|||||||
handNumber = int(commands[2])
|
handNumber = int(commands[2])
|
||||||
except:
|
except:
|
||||||
handNumber = 0
|
handNumber = 0
|
||||||
response, roundDone = blackjackSplit(str(message.channel),message.author.display_name,handNumber)
|
response, roundDone = blackjackSplit(str(message.channel),"#"+str(message.author.id),handNumber)
|
||||||
|
|
||||||
await message.channel.send(response)
|
await message.channel.send(response)
|
||||||
|
|
||||||
@ -519,10 +518,10 @@ async def parseCommands(message,content):
|
|||||||
logThis("Split calling blackjackLoop()",str(message.channel))
|
logThis("Split calling blackjackLoop()",str(message.channel))
|
||||||
await blackjackLoop(message.channel,int(roundDone[1:])+1,gameID)
|
await blackjackLoop(message.channel,int(roundDone[1:])+1,gameID)
|
||||||
except:
|
except:
|
||||||
logThis("Something fucked up")
|
logThis("Something fucked up (error code 1320)")
|
||||||
|
|
||||||
# Returning current hi-lo value
|
# Returning current hi-lo value
|
||||||
elif content.startswith("blackjack hilo") and message.author.display_name == "Nikolaj":
|
elif content.startswith("blackjack hilo") and "#"+str(message.author.id) == "#266269899859427329":
|
||||||
if os.path.exists("resources/games/blackjackCards/"+str(message.channel)+".txt"):
|
if os.path.exists("resources/games/blackjackCards/"+str(message.channel)+".txt"):
|
||||||
with open("resources/games/hilo/"+str(message.channel)+".txt", "r") as f:
|
with open("resources/games/hilo/"+str(message.channel)+".txt", "r") as f:
|
||||||
data = f.read()
|
data = f.read()
|
||||||
@ -551,14 +550,14 @@ async def parseCommands(message,content):
|
|||||||
else:
|
else:
|
||||||
logThis("Not a command (error code 1301)")
|
logThis("Not a command (error code 1301)")
|
||||||
await message.channel.send("I didn't quite understand that (error code 1301)")
|
await message.channel.send("I didn't quite understand that (error code 1301)")
|
||||||
#except:
|
except:
|
||||||
# logThis("Something went wrong (error code 1300)")
|
logThis("Something went wrong (error code 1300)")
|
||||||
|
|
||||||
# Runs a game of four in a row
|
# Runs a game of four in a row
|
||||||
elif content.startswith("fourinarow"):
|
elif content.startswith("fourinarow"):
|
||||||
try:
|
try:
|
||||||
command = content.replace("fourinarow","")
|
command = content.replace("fourinarow","")
|
||||||
await fiar(message.channel,command,message.author.display_name)
|
await fiar(message.channel,command,"#"+str(message.author.id))
|
||||||
except:
|
except:
|
||||||
logThis("Something went wrong (error code 1400)")
|
logThis("Something went wrong (error code 1400)")
|
||||||
|
|
||||||
@ -566,7 +565,7 @@ async def parseCommands(message,content):
|
|||||||
elif content.startswith("hex"):
|
elif content.startswith("hex"):
|
||||||
try:
|
try:
|
||||||
command = content.replace("hex","")
|
command = content.replace("hex","")
|
||||||
await runhex(message.channel,command,message.author.display_name)
|
await runhex(message.channel,command,"#"+str(message.author.id))
|
||||||
except:
|
except:
|
||||||
logThis("Something went wrong (error code 1500)")
|
logThis("Something went wrong (error code 1500)")
|
||||||
|
|
||||||
@ -575,7 +574,6 @@ async def parseCommands(message,content):
|
|||||||
logThis("That's not a command (error code 001)",str(message.channel))
|
logThis("That's not a command (error code 001)",str(message.channel))
|
||||||
await message.channel.send("That's not a command (error code 001)")
|
await message.channel.send("That's not a command (error code 001)")
|
||||||
|
|
||||||
|
|
||||||
# Makes files if they don't exist yet
|
# Makes files if they don't exist yet
|
||||||
makeFiles()
|
makeFiles()
|
||||||
|
|
||||||
@ -595,14 +593,15 @@ async def on_ready():
|
|||||||
# Reads messages and tests if they are Gwendolyn commands
|
# Reads messages and tests if they are Gwendolyn commands
|
||||||
@client.event
|
@client.event
|
||||||
async def on_message(message):
|
async def on_message(message):
|
||||||
#try:
|
try:
|
||||||
content = message.content
|
content = message.content
|
||||||
if content.startswith(commandPrefix):
|
if content.startswith(commandPrefix):
|
||||||
logThis(message.author.display_name+" ran \""+content+"\"",str(message.channel))
|
logThis(message.author.display_name+" ("+"#"+str(message.author.id)+") ran \""+content+"\"",str(message.channel))
|
||||||
|
addToDict("#"+str(message.author.id),message.author.display_name)
|
||||||
await parseCommands(message,content.lower()[1:])
|
await parseCommands(message,content.lower()[1:])
|
||||||
#except:
|
except:
|
||||||
# logThis("Something fucked up (error code 000)")
|
logThis("Something fucked up (error code 000)")
|
||||||
# await message.channel.send("Something fucked up (error code 000)")
|
await message.channel.send("Something fucked up (error code 000)")
|
||||||
|
|
||||||
# Is a bit sassy sometimes
|
# Is a bit sassy sometimes
|
||||||
if ("gwendolyn" in message.content.lower() or message.content.startswith(commandPrefix)) and any(x in message.content.lower() for x in meanWords) and "ikke" not in message.content.lower() and "not" not in message.content.lower():
|
if ("gwendolyn" in message.content.lower() or message.content.startswith(commandPrefix)) and any(x in message.content.lower() for x in meanWords) and "ikke" not in message.content.lower() and "not" not in message.content.lower():
|
||||||
@ -616,11 +615,11 @@ async def on_reaction_add(reaction,user):
|
|||||||
message = reaction.message
|
message = reaction.message
|
||||||
channel = message.channel
|
channel = message.channel
|
||||||
logThis(user.display_name+" reacted to a message",str(channel))
|
logThis(user.display_name+" reacted to a message",str(channel))
|
||||||
fourInARowTheirTurn, piece = fiarReactionTest(channel,message,user.display_name)
|
fourInARowTheirTurn, piece = fiarReactionTest(channel,message,"#"+str(user.id))
|
||||||
|
|
||||||
if fourInARowTheirTurn:
|
if fourInARowTheirTurn:
|
||||||
place = emojiToNumber(reaction.emoji)
|
place = emojiToNumber(reaction.emoji)
|
||||||
await fiar(channel," place "+str(piece)+" "+str(place),user.display_name)
|
await fiar(channel," place "+str(piece)+" "+str(place),user.id)
|
||||||
|
|
||||||
# Runs the whole shabang
|
# Runs the whole shabang
|
||||||
client.run(token)
|
client.run(token)
|
||||||
|
@ -19,4 +19,4 @@ And much more!!! (not really. That's pretty much all it can do. See help files i
|
|||||||
|
|
||||||
Running gwendolyn.py will help you set up. You will need a bot token on hand, which you should paste into your terminal when prompted.
|
Running gwendolyn.py will help you set up. You will need a bot token on hand, which you should paste into your terminal when prompted.
|
||||||
|
|
||||||
You will need to populate monsters.json and spells.json with monsters and spells. The files are created in the resources folder when running the program.
|
You will need to populate monsters.json, spells.json, movies.txt and names.txt with monsters, spells, movies and names. The files are created in the resources folder when running the program.
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
"""A collection of all Gwendolyn functions."""
|
"""A collection of all Gwendolyn functions."""
|
||||||
|
|
||||||
__all__ = ["helloFunc", "cap", "imageFunc", "logThis", "findWikiPage", "makeFiles", "emojiToNumber", "fiarReactionTest", "deleteGame", "stopServer", "checkBalance", "giveMoney", "addMoney", "triviaCountPoints", "triviaStart", "triviaAnswer", "blackjackShuffle", "blackjackStart", "blackjackPlayerDrawHand", "blackjackContinue", "blackjackFinish", "blackjackHit", "blackjackStand", "blackjackDouble", "blackjackSplit", "parseFourInARow", "fourInARowAI", "spellFunc", "monsterFunc", "nameGen", "tavernGen", "movieFunc", "roll_dice", "parseChar", "parseRoll", "critRoll", "parseDestiny","parseHex"]
|
__all__ = ["helloFunc", "cap", "imageFunc", "logThis", "findWikiPage", "makeFiles", "emojiToNumber", "fiarReactionTest", "deleteGame", "stopServer", "checkBalance", "giveMoney", "addMoney", "triviaCountPoints", "triviaStart", "triviaAnswer", "blackjackShuffle", "blackjackStart", "blackjackPlayerDrawHand", "blackjackContinue", "blackjackFinish", "blackjackHit", "blackjackStand", "blackjackDouble", "blackjackSplit", "parseFourInARow", "fourInARowAI", "spellFunc", "monsterFunc", "nameGen", "tavernGen", "movieFunc", "roll_dice", "parseChar", "parseRoll", "critRoll", "parseDestiny", "parseHex", "addToDict", "getName", "getID"]
|
||||||
|
|
||||||
from .miscFuncs import helloFunc, cap, imageFunc, logThis, findWikiPage, makeFiles, replaceMultiple, emojiToNumber, fiarReactionTest, deleteGame, stopServer
|
from .miscFuncs import helloFunc, cap, imageFunc, logThis, findWikiPage, makeFiles, replaceMultiple, emojiToNumber, fiarReactionTest, deleteGame, stopServer, addToDict, getName, getID
|
||||||
|
|
||||||
from .games import checkBalance, giveMoney, addMoney, triviaCountPoints, triviaStart, triviaAnswer, blackjackShuffle, blackjackStart, blackjackPlayerDrawHand, blackjackContinue, blackjackFinish, blackjackHit, blackjackStand, blackjackDouble, blackjackSplit, parseFourInARow, fourInARowAI, parseHex
|
from .games import checkBalance, giveMoney, addMoney, triviaCountPoints, triviaStart, triviaAnswer, blackjackShuffle, blackjackStart, blackjackPlayerDrawHand, blackjackContinue, blackjackFinish, blackjackHit, blackjackStand, blackjackDouble, blackjackSplit, parseFourInARow, fourInARowAI, parseHex
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ import datetime
|
|||||||
|
|
||||||
from shutil import copyfile
|
from shutil import copyfile
|
||||||
|
|
||||||
from funcs import logThis, replaceMultiple
|
from funcs import logThis, replaceMultiple, getName
|
||||||
from . import money, blackjackDraw
|
from . import money, blackjackDraw
|
||||||
|
|
||||||
# Shuffles the blackjack cards
|
# Shuffles the blackjack cards
|
||||||
@ -132,61 +132,12 @@ def blackjackContinue(channel):
|
|||||||
with open("resources/games/games.json", "r") as f:
|
with open("resources/games/games.json", "r") as f:
|
||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
|
|
||||||
|
logThis("Testing if all are standing")
|
||||||
for user in data["blackjack games"][channel]["user hands"]:
|
for user in data["blackjack games"][channel]["user hands"]:
|
||||||
if data["blackjack games"][channel]["user hands"][user]["hit"] == False:
|
try:
|
||||||
data["blackjack games"][channel]["user hands"][user]["standing"] = True
|
data["blackjack games"][channel]["user hands"][user], allStanding, preAllStanding = testIfStanding(data["blackjack games"][channel]["user hands"][user],allStanding,preAllStanding,True)
|
||||||
|
except:
|
||||||
if data["blackjack games"][channel]["user hands"][user]["standing"] == False:
|
logThis("Error in testing if all are standing (error code 1331)")
|
||||||
allStanding = False
|
|
||||||
|
|
||||||
if calcHandValue(data["blackjack games"][channel]["user hands"][user]["hand"]) >= 21 or data["blackjack games"][channel]["user hands"][user]["doubled"]:
|
|
||||||
data["blackjack games"][channel]["user hands"][user]["standing"] = True
|
|
||||||
else:
|
|
||||||
preAllStanding = False
|
|
||||||
|
|
||||||
data["blackjack games"][channel]["user hands"][user]["hit"] = False
|
|
||||||
|
|
||||||
if data["blackjack games"][channel]["user hands"][user]["split"] > 0:
|
|
||||||
if data["blackjack games"][channel]["user hands"][user]["other hand"]["hit"] == False:
|
|
||||||
data["blackjack games"][channel]["user hands"][user]["other hand"]["standing"] = True
|
|
||||||
|
|
||||||
if data["blackjack games"][channel]["user hands"][user]["other hand"]["standing"] == False:
|
|
||||||
allStanding = False
|
|
||||||
|
|
||||||
if calcHandValue(data["blackjack games"][channel]["user hands"][user]["other hand"]["hand"]) >= 21 or data["blackjack games"][channel]["user hands"][user]["other hand"]["doubled"]:
|
|
||||||
data["blackjack games"][channel]["user hands"][user]["other hand"]["standing"] = True
|
|
||||||
else:
|
|
||||||
preAllStanding = False
|
|
||||||
|
|
||||||
data["blackjack games"][channel]["user hands"][user]["other hand"]["hit"] = False
|
|
||||||
|
|
||||||
if data["blackjack games"][channel]["user hands"][user]["split"] > 1:
|
|
||||||
if data["blackjack games"][channel]["user hands"][user]["third hand"]["hit"] == False:
|
|
||||||
data["blackjack games"][channel]["user hands"][user]["third hand"]["standing"] = True
|
|
||||||
|
|
||||||
if data["blackjack games"][channel]["user hands"][user]["third hand"]["standing"] == False:
|
|
||||||
allStanding = False
|
|
||||||
|
|
||||||
if calcHandValue(data["blackjack games"][channel]["user hands"][user]["third hand"]["hand"]) >= 21 or data["blackjack games"][channel]["user hands"][user]["third hand"]["doubled"]:
|
|
||||||
data["blackjack games"][channel]["user hands"][user]["third hand"]["standing"] = True
|
|
||||||
else:
|
|
||||||
preAllStanding = False
|
|
||||||
|
|
||||||
data["blackjack games"][channel]["user hands"][user]["third hand"]["hit"] = False
|
|
||||||
|
|
||||||
if data["blackjack games"][channel]["user hands"][user]["split"] > 2:
|
|
||||||
if data["blackjack games"][channel]["user hands"][user]["fourth hand"]["hit"] == False:
|
|
||||||
data["blackjack games"][channel]["user hands"][user]["fourth hand"]["standing"] = True
|
|
||||||
|
|
||||||
if data["blackjack games"][channel]["user hands"][user]["fourth hand"]["standing"] == False:
|
|
||||||
allStanding = False
|
|
||||||
|
|
||||||
if calcHandValue(data["blackjack games"][channel]["user hands"][user]["fourth hand"]["hand"]) >= 21 or data["blackjack games"][channel]["user hands"][user]["fourth hand"]["doubled"]:
|
|
||||||
data["blackjack games"][channel]["user hands"][user]["fourth hand"]["standing"] = True
|
|
||||||
else:
|
|
||||||
preAllStanding = False
|
|
||||||
|
|
||||||
data["blackjack games"][channel]["user hands"][user]["fourth hand"]["hit"] = False
|
|
||||||
|
|
||||||
if allStanding:
|
if allStanding:
|
||||||
data["blackjack games"][channel]["all standing"] = True
|
data["blackjack games"][channel]["all standing"] = True
|
||||||
@ -196,7 +147,10 @@ def blackjackContinue(channel):
|
|||||||
with open("resources/games/games.json", "w") as f:
|
with open("resources/games/games.json", "w") as f:
|
||||||
json.dump(data,f,indent=4)
|
json.dump(data,f,indent=4)
|
||||||
|
|
||||||
|
try:
|
||||||
blackjackDraw.drawImage(channel)
|
blackjackDraw.drawImage(channel)
|
||||||
|
except:
|
||||||
|
logThis("Error drawing blackjack table (error code 1340)")
|
||||||
|
|
||||||
if allStanding:
|
if allStanding:
|
||||||
if done == False:
|
if done == False:
|
||||||
@ -212,6 +166,31 @@ def blackjackContinue(channel):
|
|||||||
firstRoundMessage = ""
|
firstRoundMessage = ""
|
||||||
return "You have 2 minutes to either hit or stand with \"!blackjack hit\" or \"!blackjack stand\""+firstRoundMessage+". It's assumed you're standing if you don't make a choice.", False, done
|
return "You have 2 minutes to either hit or stand with \"!blackjack hit\" or \"!blackjack stand\""+firstRoundMessage+". It's assumed you're standing if you don't make a choice.", False, done
|
||||||
|
|
||||||
|
def testIfStanding(hand,allStanding,preAllStanding,topLevel):
|
||||||
|
if hand["hit"] == False:
|
||||||
|
hand["standing"] = True
|
||||||
|
|
||||||
|
if hand["standing"] == False:
|
||||||
|
allStanding = False
|
||||||
|
|
||||||
|
if calcHandValue(hand["hand"]) >= 21 or hand["doubled"]:
|
||||||
|
hand["standing"] = True
|
||||||
|
else:
|
||||||
|
preAllStanding = False
|
||||||
|
|
||||||
|
hand["hit"] = False
|
||||||
|
|
||||||
|
if topLevel:
|
||||||
|
if hand["split"] >= 1:
|
||||||
|
hand["other hand"], allstanding, preAllStanding = testIfStanding(hand["other hand"],allStanding,preAllStanding,False)
|
||||||
|
if hand["split"] >= 2:
|
||||||
|
hand["third hand"], allstanding, preAllStanding = testIfStanding(hand["third hand"],allStanding,preAllStanding,False)
|
||||||
|
if hand["split"] >= 3:
|
||||||
|
hand["fourth hand"], allstanding, preAllStanding = testIfStanding(hand["fourth hand"],allStanding,preAllStanding,False)
|
||||||
|
|
||||||
|
return hand, allStanding, preAllStanding
|
||||||
|
|
||||||
|
|
||||||
# When players try to hit
|
# When players try to hit
|
||||||
def blackjackHit(channel,user,handNumber = 0):
|
def blackjackHit(channel,user,handNumber = 0):
|
||||||
with open("resources/games/games.json", "r") as f:
|
with open("resources/games/games.json", "r") as f:
|
||||||
@ -311,7 +290,7 @@ def blackjackDouble(channel,user,handNumber = 0):
|
|||||||
hand = data["blackjack games"][channel]["user hands"][user]["other hand"]
|
hand = data["blackjack games"][channel]["user hands"][user]["other hand"]
|
||||||
elif handNumber == 3:
|
elif handNumber == 3:
|
||||||
hand = data["blackjack games"][channel]["user hands"][user]["third hand"]
|
hand = data["blackjack games"][channel]["user hands"][user]["third hand"]
|
||||||
elif handNumber == 3:
|
elif handNumber == 4:
|
||||||
hand = data["blackjack games"][channel]["user hands"][user]["fourth hand"]
|
hand = data["blackjack games"][channel]["user hands"][user]["fourth hand"]
|
||||||
else:
|
else:
|
||||||
logThis(user+" tried to double without specifying which hand")
|
logThis(user+" tried to double without specifying which hand")
|
||||||
@ -373,7 +352,7 @@ def blackjackDouble(channel,user,handNumber = 0):
|
|||||||
roundDone = False
|
roundDone = False
|
||||||
|
|
||||||
|
|
||||||
return "Adding another "+str(bet)+" GwendoBucks to "+user+"'s bet and drawing another card.",str(roundDone)[0] + str(data["blackjack games"][channel]["round"])
|
return "Adding another "+str(bet)+" GwendoBucks to "+getName(user)+"'s bet and drawing another card.",str(roundDone)[0] + str(data["blackjack games"][channel]["round"])
|
||||||
else:
|
else:
|
||||||
logThis(user+" doesn't have enough GwendoBucks")
|
logThis(user+" doesn't have enough GwendoBucks")
|
||||||
return "You don't have enough GwendoBucks",""
|
return "You don't have enough GwendoBucks",""
|
||||||
@ -565,7 +544,7 @@ def blackjackSplit(channel,user,handNumber = 0):
|
|||||||
if person["fourth hand"]["hit"] == False and person["fourth hand"]["standing"] == False:
|
if person["fourth hand"]["hit"] == False and person["fourth hand"]["standing"] == False:
|
||||||
roundDone = False
|
roundDone = False
|
||||||
|
|
||||||
return "Splitting "+user+"'s hand into 2. Adding their original bet to the second hand. You can use \"!Blackjack hit/stand/double 1\" and \"!Blackjack hit/stand/double 2\" to play the different hands.",str(roundDone)[0] + str(data["blackjack games"][channel]["round"])
|
return "Splitting "+getName(user)+"'s hand into 2. Adding their original bet to the second hand. You can use \"!Blackjack hit/stand/double 1\" and \"!Blackjack hit/stand/double 2\" to play the different hands.",str(roundDone)[0] + str(data["blackjack games"][channel]["round"])
|
||||||
else:
|
else:
|
||||||
logThis(user+" doesn't have enough GwendoBucks")
|
logThis(user+" doesn't have enough GwendoBucks")
|
||||||
return "You don't have enough GwendoBucks",""
|
return "You don't have enough GwendoBucks",""
|
||||||
@ -593,7 +572,7 @@ def blackjackPlayerDrawHand(channel,user,bet):
|
|||||||
with open("resources/games/games.json", "r") as f:
|
with open("resources/games/games.json", "r") as f:
|
||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
|
|
||||||
logThis(user+" is trying to join the game in "+channel)
|
logThis(getName(user)+" is trying to join the game in "+channel)
|
||||||
|
|
||||||
if channel in data["blackjack games"]:
|
if channel in data["blackjack games"]:
|
||||||
if user not in data["blackjack games"][channel]["user hands"]:
|
if user not in data["blackjack games"][channel]["user hands"]:
|
||||||
@ -621,8 +600,8 @@ def blackjackPlayerDrawHand(channel,user,bet):
|
|||||||
with open("resources/games/games.json", "w") as f:
|
with open("resources/games/games.json", "w") as f:
|
||||||
json.dump(data,f,indent=4)
|
json.dump(data,f,indent=4)
|
||||||
|
|
||||||
logThis(user+" entered the game")
|
logThis(getName(user)+" entered the game")
|
||||||
return user+" entered the game"
|
return getName(user)+" entered the game"
|
||||||
else:
|
else:
|
||||||
logThis(user+" doesn't have enough GwendoBucks")
|
logThis(user+" doesn't have enough GwendoBucks")
|
||||||
return "You don't have enough GwendoBucks to place that bet"
|
return "You don't have enough GwendoBucks to place that bet"
|
||||||
@ -690,14 +669,14 @@ def blackjackFinish(channel):
|
|||||||
|
|
||||||
if winnings < 0:
|
if winnings < 0:
|
||||||
if winnings == -1:
|
if winnings == -1:
|
||||||
finalWinnings += user+" lost "+str(-1 * winnings)+" GwendoBuck "+reason+"\n"
|
finalWinnings += getName(user)+" lost "+str(-1 * winnings)+" GwendoBuck "+reason+"\n"
|
||||||
else:
|
else:
|
||||||
finalWinnings += user+" lost "+str(-1 * winnings)+" GwendoBucks "+reason+"\n"
|
finalWinnings += getName(user)+" lost "+str(-1 * winnings)+" GwendoBucks "+reason+"\n"
|
||||||
else:
|
else:
|
||||||
if winnings == 1:
|
if winnings == 1:
|
||||||
finalWinnings += user+" won "+str(winnings)+" GwendoBuck "+reason+"\n"
|
finalWinnings += getName(user)+" won "+str(winnings)+" GwendoBuck "+reason+"\n"
|
||||||
else:
|
else:
|
||||||
finalWinnings += user+" won "+str(winnings)+" GwendoBucks "+reason+"\n"
|
finalWinnings += getName(user)+" won "+str(winnings)+" GwendoBucks "+reason+"\n"
|
||||||
|
|
||||||
money.addMoney(user,netWinnings)
|
money.addMoney(user,netWinnings)
|
||||||
|
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
from PIL import Image, ImageDraw, ImageFont
|
from PIL import Image, ImageDraw, ImageFont
|
||||||
|
from funcs import logThis, getName
|
||||||
|
|
||||||
border = 100
|
border = 100
|
||||||
placement = [0,0]
|
placement = [0,0]
|
||||||
rotation = 0
|
rotation = 0
|
||||||
|
|
||||||
def drawImage(channel):
|
def drawImage(channel):
|
||||||
|
logThis("Drawing blackjack table",channel)
|
||||||
with open("resources/games/games.json", "r") as f:
|
with open("resources/games/games.json", "r") as f:
|
||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
|
|
||||||
@ -22,37 +23,44 @@ def drawImage(channel):
|
|||||||
dealerBusted = data["blackjack games"][channel]["dealer busted"]
|
dealerBusted = data["blackjack games"][channel]["dealer busted"]
|
||||||
dealerBlackjack = data["blackjack games"][channel]["dealer blackjack"]
|
dealerBlackjack = data["blackjack games"][channel]["dealer blackjack"]
|
||||||
|
|
||||||
|
try:
|
||||||
if data["blackjack games"][channel]["all standing"] == False:
|
if data["blackjack games"][channel]["all standing"] == False:
|
||||||
dealerHand = drawHand(data["blackjack games"][channel]["dealer hand"],True,False,False)
|
dealerHand = drawHand(data["blackjack games"][channel]["dealer hand"],True,False,False)
|
||||||
else:
|
else:
|
||||||
dealerHand = drawHand(data["blackjack games"][channel]["dealer hand"],False,dealerBusted,dealerBlackjack)
|
dealerHand = drawHand(data["blackjack games"][channel]["dealer hand"],False,dealerBusted,dealerBlackjack)
|
||||||
|
except:
|
||||||
|
logThis("Error drawing dealer hand (error code 1341a)")
|
||||||
|
|
||||||
table.paste(dealerHand,(800-borderSmol,20-borderSmol),dealerHand)
|
table.paste(dealerHand,(800-borderSmol,20-borderSmol),dealerHand)
|
||||||
|
|
||||||
for x in range(len(hands)):
|
for x in range(len(hands)):
|
||||||
key, value = list(hands.items())[x]
|
key, value = list(hands.items())[x]
|
||||||
|
key = getName(key)
|
||||||
|
logThis("drawing "+key+"'s hand")
|
||||||
userHand = drawHand(value["hand"],False,value["busted"],value["blackjack"])
|
userHand = drawHand(value["hand"],False,value["busted"],value["blackjack"])
|
||||||
|
try:
|
||||||
if value["split"] == 3:
|
if value["split"] == 3:
|
||||||
table.paste(userHand,(32-borderSmol+(384*placement[x]),280-borderSmol),userHand)
|
table.paste(userHand,(32-borderSmol+(384*placement[x]),280-borderSmol),userHand)
|
||||||
userOtherHand = drawHand(value["other hand"]["hand"],False,value["other hand"]["busted"],value["other hand"]["blackjack"])
|
userOtherHand = drawHand(value["other hand"]["hand"],False,value["other hand"]["busted"],value["other hand"]["blackjack"])
|
||||||
table.paste(userOtherHand,(32-borderSmol+(384*placement[x]),420-borderSmol),userOtherHand)
|
table.paste(userOtherHand,(32-borderSmol+(384*placement[x]),420-borderSmol),userOtherHand)
|
||||||
userThirdHand = drawHand(value["third hand"]["hand"],False,value["third hand"]["busted"],value["third hand"]["blackjack"])
|
userThirdHand = drawHand(value["third hand"]["hand"],False,value["third hand"]["busted"],value["third hand"]["blackjack"])
|
||||||
table.paste(userThirdHand,(32-borderSmol+(384*placement[x]),560-borderSmol),userOtherHand)
|
table.paste(userThirdHand,(32-borderSmol+(384*placement[x]),560-borderSmol),userThirdHand)
|
||||||
userFourthHand = drawHand(value["fourth hand"]["hand"],False,value["fourth hand"]["busted"],value["fourth hand"]["blackjack"])
|
userFourthHand = drawHand(value["fourth hand"]["hand"],False,value["fourth hand"]["busted"],value["fourth hand"]["blackjack"])
|
||||||
table.paste(userFourthHand,(32-borderSmol+(384*placement[x]),700-borderSmol),userOtherHand)
|
table.paste(userFourthHand,(32-borderSmol+(384*placement[x]),700-borderSmol),userFourthHand)
|
||||||
elif value["split"] == 2:
|
elif value["split"] == 2:
|
||||||
table.paste(userHand,(32-borderSmol+(384*placement[x]),420-borderSmol),userHand)
|
table.paste(userHand,(32-borderSmol+(384*placement[x]),420-borderSmol),userHand)
|
||||||
userOtherHand = drawHand(value["other hand"]["hand"],False,value["other hand"]["busted"],value["other hand"]["blackjack"])
|
userOtherHand = drawHand(value["other hand"]["hand"],False,value["other hand"]["busted"],value["other hand"]["blackjack"])
|
||||||
table.paste(userOtherHand,(32-borderSmol+(384*placement[x]),560-borderSmol),userOtherHand)
|
table.paste(userOtherHand,(32-borderSmol+(384*placement[x]),560-borderSmol),userOtherHand)
|
||||||
userThirdHand = drawHand(value["third hand"]["hand"],False,value["third hand"]["busted"],value["third hand"]["blackjack"])
|
userThirdHand = drawHand(value["third hand"]["hand"],False,value["third hand"]["busted"],value["third hand"]["blackjack"])
|
||||||
table.paste(userThirdHand,(32-borderSmol+(384*placement[x]),700-borderSmol),userOtherHand)
|
table.paste(userThirdHand,(32-borderSmol+(384*placement[x]),700-borderSmol),userThirdHand)
|
||||||
elif value["split"] == 1:
|
elif value["split"] == 1:
|
||||||
table.paste(userHand,(32-borderSmol+(384*placement[x]),560-borderSmol),userHand)
|
table.paste(userHand,(32-borderSmol+(384*placement[x]),560-borderSmol),userHand)
|
||||||
userOtherHand = drawHand(value["other hand"]["hand"],False,value["other hand"]["busted"],value["other hand"]["blackjack"])
|
userOtherHand = drawHand(value["other hand"]["hand"],False,value["other hand"]["busted"],value["other hand"]["blackjack"])
|
||||||
table.paste(userOtherHand,(32-borderSmol+(384*placement[x]),700-borderSmol),userOtherHand)
|
table.paste(userOtherHand,(32-borderSmol+(384*placement[x]),700-borderSmol),userOtherHand)
|
||||||
else:
|
else:
|
||||||
table.paste(userHand,(32-borderSmol+(384*placement[x]),680-borderSmol),userHand)
|
table.paste(userHand,(32-borderSmol+(384*placement[x]),680-borderSmol),userHand)
|
||||||
|
except:
|
||||||
|
logThis("Error drawing player hands (error code 1341b)")
|
||||||
|
|
||||||
textWidth = fnt.getsize(key)[0]
|
textWidth = fnt.getsize(key)[0]
|
||||||
if textWidth < 360:
|
if textWidth < 360:
|
||||||
@ -69,11 +77,13 @@ def drawImage(channel):
|
|||||||
textImage.text((32+(384*placement[x])+117-int(textWidth/2)+2,1020+2),key,fill=(0,0,0), font=fntSmol)
|
textImage.text((32+(384*placement[x])+117-int(textWidth/2)+2,1020+2),key,fill=(0,0,0), font=fntSmol)
|
||||||
textImage.text((32+(384*placement[x])+117-int(textWidth/2),1015),key,fill=(255,255,255), font=fntSmol)
|
textImage.text((32+(384*placement[x])+117-int(textWidth/2),1015),key,fill=(255,255,255), font=fntSmol)
|
||||||
|
|
||||||
|
logThis("Saving table image")
|
||||||
table.save("resources/games/blackjackTables/blackjackTable"+channel+".png")
|
table.save("resources/games/blackjackTables/blackjackTable"+channel+".png")
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def drawHand(hand, dealer, busted, blackjack):
|
def drawHand(hand, dealer, busted, blackjack):
|
||||||
|
logThis("Drawing hand "+str(hand))
|
||||||
fnt = ImageFont.truetype('resources/futura-bold.ttf', 200)
|
fnt = ImageFont.truetype('resources/futura-bold.ttf', 200)
|
||||||
fnt2 = ImageFont.truetype('resources/futura-bold.ttf', 120)
|
fnt2 = ImageFont.truetype('resources/futura-bold.ttf', 120)
|
||||||
length = len(hand)
|
length = len(hand)
|
||||||
@ -102,6 +112,7 @@ def drawHand(hand, dealer, busted, blackjack):
|
|||||||
w, h = background.size
|
w, h = background.size
|
||||||
textHeight = 290+border
|
textHeight = 290+border
|
||||||
|
|
||||||
|
#logThis("Drawing busted/blackjack")
|
||||||
if busted:
|
if busted:
|
||||||
textWidth = fnt.getsize("BUSTED")[0]
|
textWidth = fnt.getsize("BUSTED")[0]
|
||||||
textImage.text((int(w/2)-int(textWidth/2)-10,textHeight+20-10),"BUSTED",fill=(0,0,0), font=fnt)
|
textImage.text((int(w/2)-int(textWidth/2)-10,textHeight+20-10),"BUSTED",fill=(0,0,0), font=fnt)
|
||||||
@ -125,4 +136,5 @@ def drawHand(hand, dealer, busted, blackjack):
|
|||||||
textImage.text((int(w/2)-int(textWidth/2)+3,textHeight+3),"BLACKJACK",fill=(255,255,255), font=fnt2)
|
textImage.text((int(w/2)-int(textWidth/2)+3,textHeight+3),"BLACKJACK",fill=(255,255,255), font=fnt2)
|
||||||
textImage.text((int(w/2)-int(textWidth/2),textHeight),"BLACKJACK",fill=(155,123,0), font=fnt2)
|
textImage.text((int(w/2)-int(textWidth/2),textHeight),"BLACKJACK",fill=(155,123,0), font=fnt2)
|
||||||
|
|
||||||
|
#logThis("Returning resized image")
|
||||||
return background.resize((int(w/3.5),int(h/3.5)),resample=Image.BILINEAR)
|
return background.resize((int(w/3.5),int(h/3.5)),resample=Image.BILINEAR)
|
||||||
|
@ -4,7 +4,7 @@ import copy
|
|||||||
import math
|
import math
|
||||||
|
|
||||||
from . import fourInARowDraw
|
from . import fourInARowDraw
|
||||||
from funcs import logThis
|
from funcs import logThis, getName, getID
|
||||||
|
|
||||||
AIScores = {
|
AIScores = {
|
||||||
"middle": 3,
|
"middle": 3,
|
||||||
@ -26,7 +26,6 @@ def fourInARowStart(channel, user, opponent):
|
|||||||
with open("resources/games/games.json", "r") as f:
|
with open("resources/games/games.json", "r") as f:
|
||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
|
|
||||||
if user.lower() != opponent.lower():
|
|
||||||
if channel not in data["4 in a row games"]:
|
if channel not in data["4 in a row games"]:
|
||||||
|
|
||||||
if opponent in ["1","2","3","4","5"]:
|
if opponent in ["1","2","3","4","5"]:
|
||||||
@ -43,8 +42,15 @@ def fourInARowStart(channel, user, opponent):
|
|||||||
return "That difficulty doesn't exist", False, False, False, False
|
return "That difficulty doesn't exist", False, False, False, False
|
||||||
except:
|
except:
|
||||||
# Opponent is another player
|
# Opponent is another player
|
||||||
|
opponent = getID(opponent)
|
||||||
|
if opponent != None:
|
||||||
difficulty = 5
|
difficulty = 5
|
||||||
diffText = ""
|
diffText = ""
|
||||||
|
else:
|
||||||
|
return "I can't find that user", False, False, False, False
|
||||||
|
|
||||||
|
if user == opponent:
|
||||||
|
return "You can't play against yourself", False, False, False, False
|
||||||
|
|
||||||
board = [ [ 0 for i in range(columnCount) ] for j in range(rowCount) ]
|
board = [ [ 0 for i in range(columnCount) ] for j in range(rowCount) ]
|
||||||
players = [user,opponent]
|
players = [user,opponent]
|
||||||
@ -63,11 +69,9 @@ def fourInARowStart(channel, user, opponent):
|
|||||||
if players[0] == "Gwendolyn":
|
if players[0] == "Gwendolyn":
|
||||||
gwendoTurn = True
|
gwendoTurn = True
|
||||||
|
|
||||||
return "Started game against "+opponent+diffText+". It's "+players[0]+"'s turn", True, False, False, gwendoTurn
|
return "Started game against "+getName(opponent)+diffText+". It's "+getName(players[0])+"'s turn", True, False, False, gwendoTurn
|
||||||
else:
|
else:
|
||||||
return "There's already a 4 in a row game going on in this channel", False, False, False, False
|
return "There's already a 4 in a row game going on in this channel", False, False, False, False
|
||||||
else:
|
|
||||||
return "You can't play against yourself", False, False, False, False
|
|
||||||
|
|
||||||
# Places a piece at the lowest available point in a specific column
|
# Places a piece at the lowest available point in a specific column
|
||||||
def placePiece(channel : str,player : int,column : int):
|
def placePiece(channel : str,player : int,column : int):
|
||||||
@ -97,7 +101,7 @@ def placePiece(channel : str,player : int,column : int):
|
|||||||
data["4 in a row games"][channel]["win direction"] = winDirection
|
data["4 in a row games"][channel]["win direction"] = winDirection
|
||||||
data["4 in a row games"][channel]["win coordinates"] = winCoordinates
|
data["4 in a row games"][channel]["win coordinates"] = winCoordinates
|
||||||
|
|
||||||
message = data["4 in a row games"][channel]["players"][won-1]+" won."
|
message = getName(data["4 in a row games"][channel]["players"][won-1])+" won."
|
||||||
winAmount = int(data["4 in a row games"][channel]["difficulty"])^2+5
|
winAmount = int(data["4 in a row games"][channel]["difficulty"])^2+5
|
||||||
if data["4 in a row games"][channel]["players"][won-1] != "Gwendolyn":
|
if data["4 in a row games"][channel]["players"][won-1] != "Gwendolyn":
|
||||||
message += " Adding "+str(winAmount)+" GwendoBucks to their account."
|
message += " Adding "+str(winAmount)+" GwendoBucks to their account."
|
||||||
@ -106,7 +110,7 @@ def placePiece(channel : str,player : int,column : int):
|
|||||||
message = "It's a draw!"
|
message = "It's a draw!"
|
||||||
else:
|
else:
|
||||||
gameWon = False
|
gameWon = False
|
||||||
message = data["4 in a row games"][channel]["players"][player-1]+" placed a piece in column "+str(column+1)+". It's now "+data["4 in a row games"][channel]["players"][turn]+"'s turn."
|
message = getName(data["4 in a row games"][channel]["players"][player-1])+" placed a piece in column "+str(column+1)+". It's now "+getName(data["4 in a row games"][channel]["players"][turn])+"'s turn."
|
||||||
|
|
||||||
with open("resources/games/games.json", "w") as f:
|
with open("resources/games/games.json", "w") as f:
|
||||||
json.dump(data,f,indent=4)
|
json.dump(data,f,indent=4)
|
||||||
|
@ -2,7 +2,7 @@ import json
|
|||||||
import math
|
import math
|
||||||
|
|
||||||
from PIL import Image, ImageDraw, ImageFont
|
from PIL import Image, ImageDraw, ImageFont
|
||||||
from funcs import logThis
|
from funcs import logThis, getName
|
||||||
|
|
||||||
# Draws the whole thing
|
# Draws the whole thing
|
||||||
def drawImage(channel):
|
def drawImage(channel):
|
||||||
@ -32,6 +32,16 @@ def drawImage(channel):
|
|||||||
pieceStartx = (border+gridBorder)+math.floor(placeGridSize[0]/2)-math.floor(placeSize/2)
|
pieceStartx = (border+gridBorder)+math.floor(placeGridSize[0]/2)-math.floor(placeSize/2)
|
||||||
pieceStarty = (border+gridBorder)+math.floor(placeGridSize[1]/2)-math.floor(placeSize/2)
|
pieceStarty = (border+gridBorder)+math.floor(placeGridSize[1]/2)-math.floor(placeSize/2)
|
||||||
|
|
||||||
|
if data["4 in a row games"][channel]["players"][0] == "Gwendolyn":
|
||||||
|
player1 = "Gwendolyn"
|
||||||
|
else:
|
||||||
|
player1 = getName(data["4 in a row games"][channel]["players"][0])
|
||||||
|
|
||||||
|
if data["4 in a row games"][channel]["players"][1] == "Gwendolyn":
|
||||||
|
player2 = "Gwendolyn"
|
||||||
|
else:
|
||||||
|
player2 = getName(data["4 in a row games"][channel]["players"][1])
|
||||||
|
|
||||||
|
|
||||||
background = Image.new("RGB", (w,h+bottomBorder),backgroundColor)
|
background = Image.new("RGB", (w,h+bottomBorder),backgroundColor)
|
||||||
d = ImageDraw.Draw(background,"RGBA")
|
d = ImageDraw.Draw(background,"RGBA")
|
||||||
@ -124,11 +134,11 @@ def drawImage(channel):
|
|||||||
|
|
||||||
exampleHeight = h - border + int((bottomBorder+border)/2) - int(exampleCircles/2)
|
exampleHeight = h - border + int((bottomBorder+border)/2) - int(exampleCircles/2)
|
||||||
d.ellipse([(border,exampleHeight),(border+exampleCircles),(exampleHeight+exampleCircles)],fill=(255,255,0),outline=(0,0,0),width=3)
|
d.ellipse([(border,exampleHeight),(border+exampleCircles),(exampleHeight+exampleCircles)],fill=(255,255,0),outline=(0,0,0),width=3)
|
||||||
d.text((border+exampleCircles+textPadding,exampleHeight),data["4 in a row games"][channel]["players"][0],font=fnt,fill=(0,0,0))
|
d.text((border+exampleCircles+textPadding,exampleHeight),player1,font=fnt,fill=(0,0,0))
|
||||||
|
|
||||||
textWidth = fnt.getsize(data["4 in a row games"][channel]["players"][1])[0]
|
textWidth = fnt.getsize(player2)[0]
|
||||||
d.ellipse([(w-border-exampleCircles-textWidth-textPadding,exampleHeight),(w-border-textWidth-textPadding),(exampleHeight+exampleCircles)],fill=(255,0,0),outline=(0,0,0),width=3)
|
d.ellipse([(w-border-exampleCircles-textWidth-textPadding,exampleHeight),(w-border-textWidth-textPadding),(exampleHeight+exampleCircles)],fill=(255,0,0),outline=(0,0,0),width=3)
|
||||||
d.text((w-border-textWidth,exampleHeight),data["4 in a row games"][channel]["players"][1],font=fnt,fill=(0,0,0))
|
d.text((w-border-textWidth,exampleHeight),player2,font=fnt,fill=(0,0,0))
|
||||||
|
|
||||||
|
|
||||||
background.save("resources/games/4InARowBoards/board"+channel+".png")
|
background.save("resources/games/4InARowBoards/board"+channel+".png")
|
||||||
|
@ -1,47 +1,56 @@
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
from funcs import logThis
|
from funcs import logThis, getID, getName
|
||||||
|
|
||||||
# Returns the account balance for a user
|
# Returns the account balance for a user
|
||||||
def checkBalance(user):
|
def checkBalance(user):
|
||||||
user = user.lower()
|
user = user.lower()
|
||||||
logThis("checking "+user+"'s account balance")
|
logThis("checking "+user+"'s account balance")
|
||||||
with open("resources/games/games.json", "r") as f:
|
with open("resources/users.json", "r") as f:
|
||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
|
|
||||||
if user in data["users"]:
|
if user in data:
|
||||||
return data["users"][user]
|
return data[user]["money"]
|
||||||
else: return 0
|
else: return 0
|
||||||
|
|
||||||
# Adds money to the account of a user
|
# Adds money to the account of a user
|
||||||
def addMoney(user,amount):
|
def addMoney(user,amount):
|
||||||
user = user.lower()
|
|
||||||
logThis("adding "+str(amount)+" to "+user+"'s account")
|
logThis("adding "+str(amount)+" to "+user+"'s account")
|
||||||
with open("resources/games/games.json", "r") as f:
|
with open("resources/users.json", "r") as f:
|
||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
|
|
||||||
if user in data["users"]:
|
if user in data:
|
||||||
points = data["users"][user]
|
points = data[user]["money"]
|
||||||
data["users"][user] = points + amount
|
data[user]["money"] = points + amount
|
||||||
else:
|
else:
|
||||||
data["users"][user] = amount
|
logThis("Error adding money")
|
||||||
|
|
||||||
with open("resources/games/games.json", "w") as f:
|
with open("resources/users.json", "w") as f:
|
||||||
json.dump(data,f,indent=4)
|
json.dump(data,f,indent=4)
|
||||||
|
|
||||||
# Transfers money from one user to another
|
# Transfers money from one user to another
|
||||||
def giveMoney(user,targetUser,amount):
|
def giveMoney(user,targetUser,amount):
|
||||||
with open("resources/games/games.json", "r") as f:
|
with open("resources/users.json", "r") as f:
|
||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
|
|
||||||
if user in data["users"]:
|
targetUser = getID(targetUser)
|
||||||
if data["users"][user] >= amount:
|
|
||||||
|
if amount > 0:
|
||||||
|
if targetUser.startswith("#"):
|
||||||
|
if user in data:
|
||||||
|
if data[user]["money"] >= amount:
|
||||||
addMoney(user,-1 * amount)
|
addMoney(user,-1 * amount)
|
||||||
addMoney(targetUser,amount)
|
addMoney(targetUser,amount)
|
||||||
return "Transferred "+str(amount)+" GwendoBucks to "+targetUser
|
return "Transferred "+str(amount)+" GwendoBucks to "+getName(targetUser)
|
||||||
else:
|
else:
|
||||||
logThis("They didn't have enough GwendoBucks (error code 1223b)")
|
logThis("They didn't have enough GwendoBucks (error code 1223b)")
|
||||||
return "You don't have that many GwendoBucks (error code 1223b)"
|
return "You don't have that many GwendoBucks (error code 1223b)"
|
||||||
else:
|
else:
|
||||||
logThis("They didn't have enough GwendoBucks (error code 1223a)")
|
logThis("They didn't have enough GwendoBucks (error code 1223a)")
|
||||||
return "You don't have that many GwendoBucks (error code 1223a)"
|
return "You don't have that many GwendoBucks (error code 1223a)"
|
||||||
|
else:
|
||||||
|
logThis("They weren't in the system")
|
||||||
|
return "The target doesn't exist"
|
||||||
|
else:
|
||||||
|
logThis("They tried to steal")
|
||||||
|
return "Yeah, no. You can't do that"
|
||||||
|
@ -181,6 +181,17 @@ def makeFiles():
|
|||||||
finally:
|
finally:
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
# Creates users.json if it doesn't exist
|
||||||
|
try:
|
||||||
|
f = open("resources/users.json","r")
|
||||||
|
except:
|
||||||
|
logThis("users.json didn't exist. Making it now.")
|
||||||
|
data = {}
|
||||||
|
with open("resources/users.json","w") as f:
|
||||||
|
json.dump(data,f,indent = 4)
|
||||||
|
finally:
|
||||||
|
f.close()
|
||||||
|
|
||||||
# Creates destinyPoints.txt if it doesn't exist
|
# Creates destinyPoints.txt if it doesn't exist
|
||||||
try:
|
try:
|
||||||
f = open("resources/starWars/destinyPoints.txt","r")
|
f = open("resources/starWars/destinyPoints.txt","r")
|
||||||
@ -291,11 +302,9 @@ def fiarReactionTest(channel,message,user):
|
|||||||
if message.id == oldImage:
|
if message.id == oldImage:
|
||||||
logThis("They reacted to the fourinarow game")
|
logThis("They reacted to the fourinarow game")
|
||||||
turn = data["4 in a row games"][str(channel)]["turn"]
|
turn = data["4 in a row games"][str(channel)]["turn"]
|
||||||
if user.lower() == data["4 in a row games"][str(channel)]["players"][turn].lower():
|
print(user)
|
||||||
if user != data["4 in a row games"][str(channel)]["players"][turn]:
|
print(data["4 in a row games"][str(channel)]["players"][turn])
|
||||||
data["4 in a row games"][str(channel)]["players"][turn] = user
|
if user == data["4 in a row games"][str(channel)]["players"][turn]:
|
||||||
with open("resources/games/games.json","w") as f:
|
|
||||||
json.dump(data,f,indent=4)
|
|
||||||
return True, turn+1
|
return True, turn+1
|
||||||
else:
|
else:
|
||||||
logThis("It wasn't their turn")
|
logThis("It wasn't their turn")
|
||||||
@ -321,3 +330,61 @@ def deleteGame(gameType,channel):
|
|||||||
del data[gameType][channel]
|
del data[gameType][channel]
|
||||||
with open("resources/games/games.json", "w") as f:
|
with open("resources/games/games.json", "w") as f:
|
||||||
json.dump(data,f,indent=4)
|
json.dump(data,f,indent=4)
|
||||||
|
|
||||||
|
def addToDict(userID,userName):
|
||||||
|
with open("resources/users.json", "r") as f:
|
||||||
|
data = json.load(f)
|
||||||
|
|
||||||
|
if userID in data:
|
||||||
|
if data[userID]["user name"] != userName:
|
||||||
|
logThis("changing name for "+userName)
|
||||||
|
data[userID]["user name"] = userName
|
||||||
|
with open("resources/users.json", "w") as f:
|
||||||
|
json.dump(data,f,indent=4)
|
||||||
|
else:
|
||||||
|
logThis("creating "+userName+" in the system")
|
||||||
|
|
||||||
|
with open("resources/games/games.json","r") as f:
|
||||||
|
games = json.load(f)
|
||||||
|
|
||||||
|
if userName.lower() in games["users"]:
|
||||||
|
money = games["users"][userName.lower()]
|
||||||
|
del games["users"][userName.lower()]
|
||||||
|
with open("resources/games/games.json", "w") as f:
|
||||||
|
json.dump(games,f,indent=4)
|
||||||
|
else:
|
||||||
|
money = 0
|
||||||
|
|
||||||
|
data[userID] = {"user name" : userName, "money" : money}
|
||||||
|
with open("resources/users.json", "w") as f:
|
||||||
|
json.dump(data,f,indent=4)
|
||||||
|
|
||||||
|
def getName(userID):
|
||||||
|
try:
|
||||||
|
with open("resources/users.json", "r") as f:
|
||||||
|
data = json.load(f)
|
||||||
|
|
||||||
|
if userID in data:
|
||||||
|
logThis("yeet")
|
||||||
|
return data[userID]["user name"]
|
||||||
|
else:
|
||||||
|
logThis("Couldn't find user")
|
||||||
|
return userID
|
||||||
|
except:
|
||||||
|
logThis("Error getting name")
|
||||||
|
|
||||||
|
def getID(userName):
|
||||||
|
try:
|
||||||
|
with open("resources/users.json", "r") as f:
|
||||||
|
data = json.load(f)
|
||||||
|
|
||||||
|
userID = None
|
||||||
|
|
||||||
|
for key, value in data.items():
|
||||||
|
if userName.lower() == value["user name"].lower():
|
||||||
|
userID = key
|
||||||
|
break
|
||||||
|
|
||||||
|
return userID
|
||||||
|
except:
|
||||||
|
logThis("Error getting ID")
|
@ -1,10 +1,10 @@
|
|||||||
import json
|
import json
|
||||||
import string
|
import string
|
||||||
|
|
||||||
from funcs import logThis
|
from funcs import logThis, getName
|
||||||
|
|
||||||
def getName(user : str):
|
def getCharName(user : str):
|
||||||
logThis("Getting name for "+user+"'s character")
|
logThis("Getting name for "+getName(user)+"'s character")
|
||||||
with open("resources/starWars/swcharacters.json", "r") as f:
|
with open("resources/starWars/swcharacters.json", "r") as f:
|
||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
|
|
||||||
@ -12,8 +12,8 @@ def getName(user : str):
|
|||||||
logThis("Name is "+data[user]["Name"])
|
logThis("Name is "+data[user]["Name"])
|
||||||
return data[user]["Name"]
|
return data[user]["Name"]
|
||||||
else:
|
else:
|
||||||
logThis("Just using "+user)
|
logThis("Just using "+getName(user))
|
||||||
return user
|
return getName(user)
|
||||||
|
|
||||||
def setUpDict(cmd : dict):
|
def setUpDict(cmd : dict):
|
||||||
logThis("Setting up a dictionary in a nice way")
|
logThis("Setting up a dictionary in a nice way")
|
||||||
@ -251,7 +251,7 @@ def charData(user : str,cmd : str):
|
|||||||
if cmd == "":
|
if cmd == "":
|
||||||
break
|
break
|
||||||
|
|
||||||
logThis("Looking for "+user+"'s character")
|
logThis("Looking for "+getName(user)+"'s character")
|
||||||
if user in data:
|
if user in data:
|
||||||
logThis("Foundt it! Looking for "+key+" in the data")
|
logThis("Foundt it! Looking for "+key+" in the data")
|
||||||
if key in data[user]:
|
if key in data[user]:
|
||||||
@ -498,26 +498,28 @@ def parseChar(user : str, cmd : str):
|
|||||||
if cmd == "":
|
if cmd == "":
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
if cmd == "":
|
if cmd == "":
|
||||||
if user in data:
|
if user in data:
|
||||||
text1, text2 = characterSheet(data[user])
|
text1, text2 = characterSheet(data[user])
|
||||||
return text1, replaceWithSpaces(text2)
|
return text1, replaceWithSpaces(text2)
|
||||||
else:
|
else:
|
||||||
logThis("Makin' a character for "+user)
|
logThis("Makin' a character for "+getName(user))
|
||||||
with open("resources/starWars/swtemplates.json", "r") as f:
|
with open("resources/starWars/swtemplates.json", "r") as f:
|
||||||
templates = json.load(f)
|
templates = json.load(f)
|
||||||
newChar = templates["Character"]
|
newChar = templates["Character"]
|
||||||
data[user] = newChar
|
data[user] = newChar
|
||||||
with open("resources/starWars/swcharacters.json", "w") as f:
|
with open("resources/starWars/swcharacters.json", "w") as f:
|
||||||
json.dump(data,f,indent = 4)
|
json.dump(data,f,indent = 4)
|
||||||
return "", "Character for " + user + " created"
|
return "", "Character for " + getName(user) + " created"
|
||||||
else:
|
else:
|
||||||
if cmd == "Purge":
|
if cmd == "Purge":
|
||||||
logThis("Deleting "+user+"'s character")
|
logThis("Deleting "+getName(user)+"'s character")
|
||||||
del data[user]
|
del data[user]
|
||||||
with open("resources/starWars/swcharacters.json", "w") as f:
|
with open("resources/starWars/swcharacters.json", "w") as f:
|
||||||
json.dump(data,f,indent = 4)
|
json.dump(data,f,indent = 4)
|
||||||
return "", "Character for " + user + " deleted"
|
return "", "Character for " + getName(user) + " deleted"
|
||||||
|
else:
|
||||||
return "", replaceWithSpaces(str(charData(user,cmd)))
|
return "", replaceWithSpaces(str(charData(user,cmd)))
|
||||||
|
|
||||||
def lightsaberChar(user : str):
|
def lightsaberChar(user : str):
|
||||||
|
@ -367,7 +367,7 @@ def parseRoll(user : str,cmd : str = ""):
|
|||||||
|
|
||||||
simplified = simplify(rollResults)
|
simplified = simplify(rollResults)
|
||||||
|
|
||||||
name = swchar.getName(user)
|
name = swchar.getCharName(user)
|
||||||
|
|
||||||
logThis("Returns results and simplified results")
|
logThis("Returns results and simplified results")
|
||||||
|
|
||||||
|
@ -139,6 +139,7 @@ async def fiar(channel,command,user):
|
|||||||
reward = int(data["4 in a row games"][str(channel)]["difficulty"])
|
reward = int(data["4 in a row games"][str(channel)]["difficulty"])
|
||||||
reward = reward^2 + 5
|
reward = reward^2 + 5
|
||||||
if winner != 0:
|
if winner != 0:
|
||||||
|
if data["4 in a row games"][str(channel)]["players"][winner-1].lower() != "gwendolyn":
|
||||||
addMoney(data["4 in a row games"][str(channel)]["players"][winner-1].lower(),reward)
|
addMoney(data["4 in a row games"][str(channel)]["players"][winner-1].lower(),reward)
|
||||||
with open("resources/games/games.json", "r") as f:
|
with open("resources/games/games.json", "r") as f:
|
||||||
data = json.load(f) #why is this here?
|
data = json.load(f) #why is this here?
|
||||||
|
@ -93,6 +93,10 @@
|
|||||||
1312 - Error in calcWinnings function
|
1312 - Error in calcWinnings function
|
||||||
1320 - Unspecified loop error
|
1320 - Unspecified loop error
|
||||||
1321 - Loop interrupted while waiting
|
1321 - Loop interrupted while waiting
|
||||||
|
1330 - Unspecified continue error
|
||||||
|
1331 - Error in testIfStanding()
|
||||||
|
1340 - Error in drawing blackjack table
|
||||||
|
1341 - Error in drawHand()
|
||||||
|
|
||||||
14 - Four in a row
|
14 - Four in a row
|
||||||
1400 - Unspecified error
|
1400 - Unspecified error
|
||||||
|
Reference in New Issue
Block a user