📝 Commenting and formatting

This commit is contained in:
NikolajDanger
2020-07-29 10:38:37 +02:00
parent 94c6289cc1
commit ef434ecee8
12 changed files with 260 additions and 220 deletions

View File

@ -1,11 +1,11 @@
from .gwendolynFuncs import helloFunc, cap, imageFunc, logThis, findWikiPage, makeFiles, replaceMultiple
from .miscFuncs import helloFunc, cap, imageFunc, logThis, findWikiPage, makeFiles, replaceMultiple
from .swfuncs import parseChar, parseRoll, parseDestiny, critRoll
from .swfuncs import *
from .lookup import spellFunc, monsterFunc
from .lookup import *
from .other import nameGen, tavernGen, movieFunc
from .other import *
from .games import triviaStart, triviaOtherThing, triviaCountPoints, checkBalance, addMoney, giveMoney, shuffle, blackjackStart, blackjackPlayerDrawHand, blackjackContinue, blackjackFinish, blackjackStand, blackjackHit,blackjackDouble,blackjackSplit, decipherCommand
from .games import *
from .roll import roll_dice
from .roll import *

View File

@ -1,4 +1,4 @@
from .money import checkBalance, giveMoney, addMoney
from .trivia import triviaCountPoints, triviaStart, triviaOtherThing
from .blackjack import shuffle, blackjackStart, blackjackPlayerDrawHand, blackjackContinue, blackjackFinish, blackjackHit, blackjackStand, blackjackDouble, blackjackSplit
from .fourInARow import decipherCommand
from .trivia import triviaCountPoints, triviaStart, triviaAnswer
from .blackjack import blackjackShuffle, blackjackStart, blackjackPlayerDrawHand, blackjackContinue, blackjackFinish, blackjackHit, blackjackStand, blackjackDouble, blackjackSplit
from .fourInARow import parseFourInARow

View File

@ -7,15 +7,14 @@ from shutil import copyfile
from funcs import logThis, replaceMultiple
from . import money, blackjackDraw
deckAmount = 4
def shuffle():
# Shuffles the blackjack cards
def blackjackShuffle(decks):
logThis("Shuffling the blackjack deck")
with open("resources/games/deckofCards.txt","r") as f:
deck = f.read()
allDecks = deck.split("\n") * 4
allDecks = deck.split("\n") * decks
random.shuffle(allDecks)
data = "\n".join(allDecks)
@ -24,6 +23,7 @@ def shuffle():
return
# Calculates the value of a blackjack hand
def calcHandValue(hand : list):
logThis("Calculating hand value")
values = [0]
@ -51,13 +51,13 @@ def calcHandValue(hand : list):
return handValue
# Draws a card from the deck
def drawCard():
logThis("drawing a card")
with open("resources/games/blackjackCards.txt","r") as f:
cards = f.read().split("\n")
drawnCard = cards[0]
cards = cards[1:]
drawnCard = cards.pop(0)
data = "\n".join(cards)
with open("resources/games/blackjackCards.txt","w") as f:
@ -65,6 +65,7 @@ def drawCard():
return drawnCard
# Dealer draws a card and checks if they should draw another one
def dealerDraw(channel):
with open("resources/games/games.json", "r") as f:
data = json.load(f)
@ -85,6 +86,7 @@ def dealerDraw(channel):
return done
# Goes to the next round and calculates some stuff
def blackjackContinue(channel):
logThis("Continuing blackjack game")
with open("resources/games/games.json", "r") as f:
@ -163,6 +165,7 @@ def blackjackContinue(channel):
firstRoundMessage = ""
return "You have 30 seconds 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
# When players try to hit
def blackjackHit(channel,user,handNumber = 0):
with open("resources/games/games.json", "r") as f:
data = json.load(f)
@ -216,6 +219,7 @@ def blackjackHit(channel,user,handNumber = 0):
return "You can't hit before you see your cards"
# When players try to double down
def blackjackDouble(channel,user,handNumber = 0):
with open("resources/games/games.json", "r") as f:
data = json.load(f)
@ -287,6 +291,7 @@ def blackjackDouble(channel,user,handNumber = 0):
logThis(user+" tried to double on the 0th round")
return "You can't double down before you see your cards"
# When players try to stand
def blackjackStand(channel,user,handNumber = 0):
with open("resources/games/games.json", "r") as f:
data = json.load(f)
@ -310,6 +315,7 @@ def blackjackStand(channel,user,handNumber = 0):
logThis(user+" tried to stand on the first round")
return "You can't stand before you see your cards"
# When players try to split
def blackjackSplit(channel,user):
with open("resources/games/games.json", "r") as f:
data = json.load(f)
@ -374,6 +380,7 @@ def blackjackSplit(channel,user):
logThis(user+" tried to split on the 0th round")
return "You can't split before you see your cards"
# Player enters the game and draws a hand
def blackjackPlayerDrawHand(channel,user,bet):
with open("resources/games/games.json", "r") as f:
data = json.load(f)
@ -431,6 +438,7 @@ def blackjackPlayerDrawHand(channel,user,bet):
logThis("There is no game going on in "+channel)
return "There is no game going on in this channel"
# Starts a game of blackjack
def blackjackStart(channel:str):
with open("resources/games/games.json", "r") as f:
data = json.load(f)
@ -456,6 +464,7 @@ def blackjackStart(channel:str):
logThis("There is already a blackjack game going on in "+channel)
return "There's already a blackjack game going on. Try again in a few minutes."
# Ends the game and calculates winnings
def blackjackFinish(channel):
finalWinnings = "*Final Winnings:*\n"
@ -480,6 +489,7 @@ def blackjackFinish(channel):
winnings += 2 * data["blackjack games"][channel]["user hands"][user]["bet"]
elif calcHandValue(data["blackjack games"][channel]["user hands"][user]["hand"]) > dealerValue:
winnings += 2 * data["blackjack games"][channel]["user hands"][user]["bet"]
reason = "(highest value)"
elif calcHandValue(data["blackjack games"][channel]["user hands"][user]["hand"]) == dealerValue:
reason = "(pushed)"
winnings += data["blackjack games"][channel]["user hands"][user]["bet"]

View File

@ -4,6 +4,7 @@ import math
from PIL import Image, ImageDraw, ImageFont
from funcs import logThis
# Draws the whole thing
def drawImage(channel):
logThis("Drawing four in a row board")
with open("resources/games/games.json", "r") as f:
@ -29,13 +30,16 @@ def drawImage(channel):
background = Image.new("RGBA", (w,h),backgroundColor)
d = ImageDraw.Draw(background)
# This whole part was the easiest way to make a rectangle with rounded corners and an outline
# - Corners:
d.ellipse([(border,border),(border+cornerSize,border+cornerSize)],fill=boardColor,outline=(0,0,0),width=outlineSize)
d.ellipse([(w-(border+cornerSize),h-(border+cornerSize)),(w-border,h-border)],fill=boardColor,outline=(0,0,0),width=outlineSize)
d.ellipse([(border,h-(border+cornerSize)),(border+cornerSize,h-border)],fill=boardColor,outline=(0,0,0),width=outlineSize)
d.ellipse([(w-(border+cornerSize),border),(w-border,border+cornerSize)],fill=boardColor,outline=(0,0,0),width=outlineSize)
# - Rectangle:
d.rectangle([(border+math.floor(cornerSize/2),border),(w-(border+math.floor(cornerSize/2)),h-border)],fill=boardColor,outline=(0,0,0),width=outlineSize)
d.rectangle([(border,border+math.floor(cornerSize/2)),(w-border,h-(border+math.floor(cornerSize/2)))],fill=boardColor,outline=(0,0,0),width=outlineSize)
# - Removing outline on the inside:
d.rectangle([(border+math.floor(cornerSize/2),border+math.floor(cornerSize/2)),(w-(border+math.floor(cornerSize/2)),h-(border+math.floor(cornerSize/2)))],fill=boardColor)
d.ellipse([(border+outlineSize,border+outlineSize),(border+cornerSize-outlineSize,border+cornerSize-outlineSize)],fill=boardColor)
d.ellipse([(w-(border+cornerSize)+outlineSize,h-(border+cornerSize)+outlineSize),(w-border-outlineSize,h-border-outlineSize)],fill=boardColor)

View File

@ -2,6 +2,7 @@ import json
from . import draw4InARow
# Starts the game
def fourInARowStart(channel):
with open("resources/games/games.json", "r") as f:
data = json.load(f)
@ -21,7 +22,7 @@ def fourInARowStart(channel):
else:
return "There's already a 4 in a row game going on in this channel", False
# Places a piece at the lowest available point in a specific column
def placePiece(channel : str,player : int,column : int):
with open("resources/games/games.json", "r") as f:
data = json.load(f)
@ -51,8 +52,8 @@ def placePiece(channel : str,player : int,column : int):
return "There's no game in this channel", False
def decipherCommand(command, channel, user):
# Parses command
def parseFourInARow(command, channel, user):
if command == "" or command == " ":
return fourInARowStart(channel)
elif command.startswith(" place"):

View File

@ -2,6 +2,7 @@ import json
from funcs import logThis
# Returns the account balance for a user
def checkBalance(user):
user = user.lower()
logThis("checking "+user+"'s account balance")
@ -12,6 +13,7 @@ def checkBalance(user):
return data["users"][user]
else: return 0
# Adds money to the account of a user
def addMoney(user,amount):
user = user.lower()
logThis("adding "+str(amount)+" to "+user+"'s account")
@ -27,6 +29,7 @@ def addMoney(user,amount):
with open("resources/games/games.json", "w") as f:
json.dump(data,f,indent=4)
# Transfers money from one user to another
def giveMoney(user,targetUser,amount):
with open("resources/games/games.json", "r") as f:
data = json.load(f)
@ -35,7 +38,7 @@ def giveMoney(user,targetUser,amount):
if data["users"][user] >= amount:
addMoney(user,-1 * amount)
addMoney(targetUser,amount)
return "Transferred the GwendoBucks"
return "Transferred "+str(amount)+" GwendoBucks to "+user
else:
logThis("They didn't have enough GwendoBucks")
return "You don't have that many GwendoBucks"

View File

@ -5,6 +5,8 @@ import random
from . import money
from funcs import logThis
# Starts a game of trivia. Downloads a question with answers, shuffles the wrong answers with the
# correct answer and returns the questions and answers. Also saves the question in the games.json file.
def triviaStart(channel : str):
with open("resources/games/games.json", "r") as f:
triviaFile = json.load(f)
@ -44,7 +46,8 @@ def triviaStart(channel : str):
logThis("There was already a trivia question for that channel")
return "There's already a trivia question going on. Try again in like, a minute", "", ""
def triviaOtherThing(user : str, channel : str, command : str):
# Lets players answer a trivia question
def triviaAnswer(user : str, channel : str, command : str):
with open("resources/games/games.json", "r") as f:
data = json.load(f)
@ -66,6 +69,8 @@ def triviaOtherThing(user : str, channel : str, command : str):
else:
return "I didn't quite understand that"
# Adds 1 GwendoBuck to each player that got the question right and deletes question from games.json.
def triviaCountPoints(channel : str):
with open("resources/games/games.json", "r") as f:
data = json.load(f)

View File

@ -15,12 +15,11 @@ saves = ["strength_save","dexterity_save","constitution_save","intelligence_save
abilities = ["acrobatics","animal_handling","arcana","athletics","deception","history","insight","intimidation","investigation","medicine","nature","perception","performance","persuasion","religion","sleight_of_hand","stealth","survival"]
# Looks up a monster
def monsterFunc(content):
command = cap(content.lower().replace("!monster ",""))
def monsterFunc(command):
logThis("Looking up "+command)
# 1-letter monsters don't exist
if len(content.lower().split()) < 2:
if len(command) < 2:
logThis("Monster doesn't exist in database")
return("I don't know that monster...","","","","","")
else:
@ -122,8 +121,7 @@ def monsterFunc(content):
return("I don't know that monster...","","","","","")
# Looks up a spell
def spellFunc(content):
command = cap(content.lower().replace("!spell ",""))
def spellFunc(command):
logThis("Looking up "+command)
# Opens "spells.json"

View File

@ -183,10 +183,17 @@ def makeFiles():
finally:
f.close()
# Creates the blackjacktables foulder if it doesn't exist
if os.path.isdir("resources/games/blackjackTables") == False:
os.makedirs("resources/games/blackjackTables")
logThis("The tables directory didn't exist")
# Creates the 4InARowBoards foulder if it doesn't exist
if os.path.isdir("resources/games/4InARowBoards") == False:
os.makedirs("resources/games/4InARowBoards")
logThis("The tables directory didn't exist")
# Replaces multiple things with the same thing
def replaceMultiple(mainString, toBeReplaces, newString):
# Iterate over the strings to be replaced
for elem in toBeReplaces :

View File

@ -10,6 +10,7 @@ from funcs import logThis
with open("resources/swskills.json", "r") as f:
skillData = json.load(f)
# Rolls the specified dice
def roll(abi : int = 1, prof : int = 0, dif : int = 3, cha : int = 0, boo : int = 0, setb : int = 0, force : int = 0):
result = ""
diceResult = []
@ -50,6 +51,7 @@ def roll(abi : int = 1, prof : int = 0, dif : int = 3, cha : int = 0, boo : int
return result, diceResult
# Lets dice cancel each other out
def simplify(result : str):
logThis("Simplifying "+result)
simp = ""
@ -75,116 +77,119 @@ def simplify(result : str):
return simp
# Returns emoji that symbolize the dice results
def diceResultToEmoji(diceResults : list):
emoji = ""
for result in diceResults:
if result == "abiA":
emoji += "<:abil1a:695267684476125264> "
if result == "abiSA":
elif result == "abiSA":
emoji += "<:abil1a1s:695267684484513842> "
if result == "abiS":
elif result == "abiS":
emoji += "<:abil1s:695267684514005013> "
if result == "abiAA":
elif result == "abiAA":
emoji += "<:abil2a:695267684547428352> "
if result == "abiSS":
elif result == "abiSS":
emoji += "<:abil2s:695267684761206914> "
if result == "abi":
elif result == "abi":
emoji += "<:abilbla:695267684660674602> "
if result == "profA":
elif result == "profA":
emoji += "<:prof1a:695267685361123338> "
if result == "profSA":
elif result == "profSA":
emoji += "<:prof1a1s:695267685067653140> "
if result == "profR":
elif result == "profR":
emoji += "<:prof1r:695267685067522088> "
if result == "profS":
elif result == "profS":
emoji += "<:prof1s:695267684899881012> "
if result == "profAA":
elif result == "profAA":
emoji += "<:prof2a:695267684996218982> "
if result == "profSS":
elif result == "profSS":
emoji += "<:prof2s:695267684878647327> "
if result == "prof":
elif result == "prof":
emoji += "<:profbla:695267684698292235> "
if result == "difF":
elif result == "difF":
emoji += "<:dif1f:695267684924915804> "
if result == "difH":
elif result == "difH":
emoji += "<:dif1h:695267684908138506> "
if result == "difFH":
elif result == "difFH":
emoji += "<:dif1h1f:695267684908269678> "
if result == "difFF":
elif result == "difFF":
emoji += "<:dif2f:695267684924784680> "
if result == "difHH":
elif result == "difHH":
emoji += "<:dif2h:695267685071585340> "
if result == "dif":
elif result == "dif":
emoji += "<:difbla:695267685000544276> "
if result == "chaD":
elif result == "chaD":
emoji += "<:cha1d:695267684962533447> "
if result == "chaF":
elif result == "chaF":
emoji += "<:cha1f:695267684601954346> "
if result == "chaH":
elif result == "chaH":
emoji += "<:cha1h:695267685046681620> "
if result == "chaFH":
elif result == "chaFH":
emoji += "<:cha1h1f:695267685063327784> "
if result == "chaFF":
elif result == "chaFF":
emoji += "<:cha2f:695267684832641097> "
if result == "chaHH":
elif result == "chaHH":
emoji += "<:cha2h:695267684631183381> "
if result == "cha":
elif result == "cha":
emoji += "<:chabla:695267684895686787> "
if result == "booA":
elif result == "booA":
emoji += "<:boo1a:695267684975116329> "
if result == "booSA":
elif result == "booSA":
emoji += "<:boo1a1s:695267684970922024> "
if result == "booS":
elif result == "booS":
emoji += "<:boo1s:695267684979441714> "
if result == "booAA":
elif result == "booAA":
emoji += "<:boo2a:695267685100945488> "
if result == "boo":
elif result == "boo":
emoji += "<:boobla:695267684757012550> "
if result == "setbF":
elif result == "setbF":
emoji += "<:set1f:695267685054939197> "
if result == "setbH":
elif result == "setbH":
emoji += "<:set1h:695267685147082802> "
if result == "setb":
elif result == "setb":
emoji += "<:setbla:695267685151408169> "
if result == "forceB":
elif result == "forceB":
emoji += "<:for1b:695267684593434677> "
if result == "forceL":
elif result == "forceL":
emoji += "<:for1l:695267684606148640> "
if result == "forceBB":
elif result == "forceBB":
emoji += "<:for2b:695267684903944303> "
if result == "forceLL":
elif result == "forceLL":
emoji += "<:for2l:695267684992024626> "
return emoji
# Returns emoji that symbolize the results of the dice rolls
def resultToEmoji(result : str):
emoji = ""
for char in result:
if char == 'S':
emoji += "<:success:690971244971163718> "
if char == 'A':
elif char == 'A':
emoji += "<:advantage:690970761611051079> "
if char == 'R':
elif char == 'R':
emoji += "<:swtriumph:690971267486187643> "
if char == 'F':
elif char == 'F':
emoji += "<:failure:690970957786906664> "
if char == 'H':
elif char == 'H':
emoji += "<:threat:690971009469382656> "
if char == 'D':
elif char == 'D':
emoji += "<:despair:690971200163414238> "
if char == 'L':
elif char == 'L':
emoji += "<:light:691010089905029171>"
if char == 'B':
elif char == 'B':
emoji += "<:dark:691010101901000852>"
return emoji
# Converts emoji into letters
def emojiToResult(emoji : str):
result = ""
for char in emoji:
@ -195,6 +200,7 @@ def emojiToResult(emoji : str):
return result
# Returns emoji that symbolize the dice
def diceToEmoji(dice : list):
emoji = ""
@ -215,6 +221,7 @@ def diceToEmoji(dice : list):
return emoji
# Rolls for obligation
def obligationRoll():
logThis("Rolling for obligation")
with open("resources/swcharacters.json", "r") as f:
@ -232,6 +239,7 @@ def obligationRoll():
return random.choice(table)
# Rolls for critical injury
def critRoll(addington : int):
dd = "<:difficulty:690973992470708296>"
sd = "<:setback:690972157890658415>"
@ -283,6 +291,7 @@ def critRoll(addington : int):
return "Roll: "+str(roll)+"\nInjury:\n"+results
# Parses the command into something the other functions understand
def parseRoll(user : str,cmd : str = ""):
cmd = re.sub(' +',' ',cmd.upper()) + " "
if cmd[0] == " ":
@ -296,7 +305,7 @@ def parseRoll(user : str,cmd : str = ""):
if string.capwords(commands[0]) == "Obligations":
return obligationRoll()
elif string.capwords(commands[0]) in skillData:
logThis("Oh look! This guy has skills!")
if swchar.userHasChar: