🗃️ Better modules and init files

This commit is contained in:
Nikolaj Danger
2020-08-03 16:58:37 +02:00
parent 6ca2c80432
commit d7f58305ac
11 changed files with 162 additions and 152 deletions

View File

@ -1,3 +1,5 @@
__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"]
from .miscFuncs import helloFunc, cap, imageFunc, logThis, findWikiPage, makeFiles, replaceMultiple, emojiToNumber, fiarReactionTest, deleteGame, stopServer
from .swfuncs import *
@ -8,4 +10,4 @@ from .other import *
from .games import *
from .roll import *
from .roll import *

View File

@ -1,3 +1,5 @@
__all__ = ["checkBalance", "giveMoney", "addMoney","triviaCountPoints", "triviaStart", "triviaAnswer", "blackjackShuffle", "blackjackStart", "blackjackPlayerDrawHand", "blackjackContinue", "blackjackFinish", "blackjackHit", "blackjackStand", "blackjackDouble", "blackjackSplit", "parseFourInARow", "fourInARowAI"]
from .money import checkBalance, giveMoney, addMoney
from .trivia import triviaCountPoints, triviaStart, triviaAnswer
from .blackjack import blackjackShuffle, blackjackStart, blackjackPlayerDrawHand, blackjackContinue, blackjackFinish, blackjackHit, blackjackStand, blackjackDouble, blackjackSplit

View File

@ -677,113 +677,32 @@ def blackjackFinish(channel):
data = json.load(f)
dealerValue = calcHandValue(data["blackjack games"][channel]["dealer hand"])
reason = ""
dealerBlackjack = data["blackjack games"][channel]["dealer blackjack"]
dealerBusted = data["blackjack games"][channel]["dealer busted"]
for user in data["blackjack games"][channel]["user hands"]:
winnings = -1 * data["blackjack games"][channel]["user hands"][user]["bet"]
if data["blackjack games"][channel]["user hands"][user]["blackjack"] and data["blackjack games"][channel]["dealer blackjack"] == False:
reason = "(blackjack)"
winnings += math.floor(2.5 * data["blackjack games"][channel]["user hands"][user]["bet"])
elif data["blackjack games"][channel]["dealer blackjack"]:
reason += "(dealer blackjack)"
elif data["blackjack games"][channel]["user hands"][user]["busted"]:
reason = "(busted)"
else:
if data["blackjack games"][channel]["dealer busted"]:
reason = "(dealer busted)"
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"]
else:
reason = "(highest value)"
try:
for user in data["blackjack games"][channel]["user hands"]:
if data["blackjack games"][channel]["user hands"][user]["split"] > 0:
winnings -= data["blackjack games"][channel]["user hands"][user]["other hand"]["bet"]
if data["blackjack games"][channel]["user hands"][user]["other hand"]["blackjack"] and data["blackjack games"][channel]["dealer blackjack"] == False:
reason += "(blackjack)"
winnings += math.floor(2.5 * data["blackjack games"][channel]["user hands"][user]["other hand"]["bet"])
elif data["blackjack games"][channel]["dealer blackjack"]:
reason += "(dealer blackjack)"
elif data["blackjack games"][channel]["user hands"][user]["other hand"]["busted"]:
reason += "(busted)"
else:
if data["blackjack games"][channel]["dealer busted"]:
reason += "(dealer busted)"
winnings += 2 * data["blackjack games"][channel]["user hands"][user]["other hand"]["bet"]
elif calcHandValue(data["blackjack games"][channel]["user hands"][user]["other hand"]["hand"]) > dealerValue:
reason += "(highest value)"
winnings += 2 * data["blackjack games"][channel]["user hands"][user]["other hand"]["bet"]
elif calcHandValue(data["blackjack games"][channel]["user hands"][user]["other hand"]["hand"]) == dealerValue:
reason += "(pushed)"
winnings += data["blackjack games"][channel]["user hands"][user]["other hand"]["bet"]
try:
winnings, netWinnings, reason = calcWinnings(data["blackjack games"][channel]["user hands"][user],dealerValue,True,dealerBlackjack,dealerBusted)
except:
logThis("Error calculating winnings for "+str(user)+" (error code 1312)")
if winnings < 0:
if winnings == -1:
finalWinnings += user+" lost "+str(-1 * winnings)+" GwendoBuck "+reason+"\n"
else:
reason += "(highest value)"
if data["blackjack games"][channel]["user hands"][user]["split"] > 1:
winnings -= data["blackjack games"][channel]["user hands"][user]["third hand"]["bet"]
if data["blackjack games"][channel]["user hands"][user]["third hand"]["blackjack"] and data["blackjack games"][channel]["dealer blackjack"] == False:
reason += "(blackjack)"
winnings += math.floor(2.5 * data["blackjack games"][channel]["user hands"][user]["third hand"]["bet"])
elif data["blackjack games"][channel]["dealer blackjack"]:
reason += "(dealer blackjack)"
elif data["blackjack games"][channel]["user hands"][user]["third hand"]["busted"]:
reason += "(busted)"
else:
if data["blackjack games"][channel]["dealer busted"]:
reason += "(dealer busted)"
winnings += 2 * data["blackjack games"][channel]["user hands"][user]["third hand"]["bet"]
elif calcHandValue(data["blackjack games"][channel]["user hands"][user]["third hand"]["hand"]) > dealerValue:
reason += "(highest value)"
winnings += 2 * data["blackjack games"][channel]["user hands"][user]["third hand"]["bet"]
elif calcHandValue(data["blackjack games"][channel]["user hands"][user]["third hand"]["hand"]) == dealerValue:
reason += "(pushed)"
winnings += data["blackjack games"][channel]["user hands"][user]["third hand"]["bet"]
else:
reason += "(highest value)"
if data["blackjack games"][channel]["user hands"][user]["split"] > 2:
winnings -= data["blackjack games"][channel]["user hands"][user]["fourth hand"]["bet"]
if data["blackjack games"][channel]["user hands"][user]["fourth hand"]["blackjack"] and data["blackjack games"][channel]["dealer blackjack"] == False:
reason += "(blackjack)"
winnings += math.floor(2.5 * data["blackjack games"][channel]["user hands"][user]["fourth hand"]["bet"])
elif data["blackjack games"][channel]["dealer blackjack"]:
reason += "(dealer blackjack)"
elif data["blackjack games"][channel]["user hands"][user]["fourth hand"]["busted"]:
reason += "(busted)"
else:
if data["blackjack games"][channel]["dealer busted"]:
reason += "(dealer busted)"
winnings += 2 * data["blackjack games"][channel]["user hands"][user]["fourth hand"]["bet"]
elif calcHandValue(data["blackjack games"][channel]["user hands"][user]["fourth hand"]["hand"]) > dealerValue:
reason += "(highest value)"
winnings += 2 * data["blackjack games"][channel]["user hands"][user]["fourth hand"]["bet"]
elif calcHandValue(data["blackjack games"][channel]["user hands"][user]["fourth hand"]["hand"]) == dealerValue:
reason += "(pushed)"
winnings += data["blackjack games"][channel]["user hands"][user]["fourth hand"]["bet"]
else:
reason += "(highest value)"
if winnings < 0:
if winnings == -1:
finalWinnings += user+" lost "+str(-1 * winnings)+" GwendoBuck "+reason+"\n"
finalWinnings += user+" lost "+str(-1 * winnings)+" GwendoBucks "+reason+"\n"
else:
finalWinnings += user+" lost "+str(-1 * winnings)+" GwendoBucks "+reason+"\n"
else:
if winnings == 1:
finalWinnings += user+" won "+str(winnings)+" GwendoBuck "+reason+"\n"
else:
finalWinnings += user+" won "+str(winnings)+" GwendoBucks "+reason+"\n"
netWinnings = winnings + data["blackjack games"][channel]["user hands"][user]["bet"] + data["blackjack games"][channel]["user hands"][user]["other hand"]["bet"]
if winnings == 1:
finalWinnings += user+" won "+str(winnings)+" GwendoBuck "+reason+"\n"
else:
finalWinnings += user+" won "+str(winnings)+" GwendoBucks "+reason+"\n"
money.addMoney(user,netWinnings)
money.addMoney(user,netWinnings)
except:
logThis("Error calculating winnings (error code 1311)")
with open("resources/games/games.json", "r") as f:
data = json.load(f)
@ -794,3 +713,56 @@ def blackjackFinish(channel):
json.dump(data,f,indent=4)
return finalWinnings
def calcWinnings(hand, dealerValue, topLevel, dealerBlackjack, dealerBusted):
logThis("Calculating winnings")
reason = ""
bet = hand["bet"]
winnings = -1 * bet
netWinnings = 0
handValue = calcHandValue(hand["hand"])
if hand["blackjack"] and dealerBlackjack == False:
reason += "(blackjack)"
winnings += math.floor(2.5 * bet)
netWinnings += math.floor(2.5 * bet)
elif dealerBlackjack:
reason += "(dealer blackjack)"
elif hand["busted"]:
reason += "(busted)"
else:
if dealerBusted:
reason = "(dealer busted)"
winnings += 2 * bet
netWinnings += 2 * bet
elif handValue > dealerValue:
winnings += 2 * bet
netWinnings += 2 * bet
reason = "(highest value)"
elif handValue == dealerValue:
reason = "(pushed)"
winnings += bet
netWinnings += bet
else:
reason = "(highest value)"
if topLevel:
if hand["split"] >= 1:
winningsTemp, netWinningsTemp, reasonTemp = calcWinnings(hand["other hand"],dealerValue,False,dealerBlackjack,dealerBusted)
winnings += winningsTemp
netWinnings += netWinningsTemp
reason += reasonTemp
if hand["split"] >= 2:
winningsTemp, netWinningsTemp, reasonTemp = calcWinnings(hand["third hand"],dealerValue,False,dealerBlackjack,dealerBusted)
winnings += winningsTemp
netWinnings += netWinningsTemp
reason += reasonTemp
if hand["split"] >= 3:
winningsTemp, netWinningsTemp, reasonTemp = calcWinnings(hand["fourth hand"],dealerValue,False,dealerBlackjack,dealerBusted)
winnings += winningsTemp
netWinnings += netWinningsTemp
reason += reasonTemp
return winnings, netWinnings, reason

View File

@ -1 +1,3 @@
__all__ = ["spellFunc", "monsterFunc"]
from .lookupFuncs import spellFunc, monsterFunc

View File

@ -2,7 +2,7 @@ import lxml.etree # Used by imageFunc
import re # Used by roll_dice
import datetime # Used by helloFunc
import json # Used by spellFunc
#import random # Used by imageFunc
import random # Used by imageFunc
import urllib # Used by imageFunc
import imdb # Used by movieFunc
import time # Used for logging
@ -54,29 +54,32 @@ def helloFunc(author):
# Finds a random picture online
def imageFunc():
# Picks a type of camera, which decides the naming scheme
cams = ("one","two","three","four")
cam = random.choice(cams)
logThis("Chose cam type "+cam)
if cam == "one":
a = str(random.randint(0 ,9))
b = str(random.randint(0,9))
c = str(random.randint(0,9))
d = str(random.randint(0,9))
search = ("img_"+a+b+c+d)
elif cam == "two":
a = str(random.randint(2012,2016))
b = str(random.randint(1,12)).zfill(2)
c = str(random.randint(1,29)).zfill(2)
search = ("IMG_"+a+b+c)
elif cam == "three":
a = str(random.randint(1,500)).zfill(4)
search = ("IMAG_"+a)
elif cam == "four":
a = str(random.randint(0,9))
b = str(random.randint(0,9))
c = str(random.randint(0,9))
d = str(random.randint(0,9))
search = ("DSC_"+a+b+c+d)
try:
cams = ("one","two","three","four")
cam = random.choice(cams)
logThis("Chose cam type "+cam)
if cam == "one":
a = str(random.randint(0 ,9))
b = str(random.randint(0,9))
c = str(random.randint(0,9))
d = str(random.randint(0,9))
search = ("img_"+a+b+c+d)
elif cam == "two":
a = str(random.randint(2012,2016))
b = str(random.randint(1,12)).zfill(2)
c = str(random.randint(1,29)).zfill(2)
search = ("IMG_"+a+b+c)
elif cam == "three":
a = str(random.randint(1,500)).zfill(4)
search = ("IMAG_"+a)
elif cam == "four":
a = str(random.randint(0,9))
b = str(random.randint(0,9))
c = str(random.randint(0,9))
d = str(random.randint(0,9))
search = ("DSC_"+a+b+c+d)
except:
logThis("error picking camera type (error code 702)")
logThis("Searching for "+search)

View File

@ -1,2 +1,4 @@
__all__ = ["nameGen", "tavernGen", "movieFunc"]
from .generators import nameGen, tavernGen
from .movie import movieFunc

View File

@ -17,7 +17,7 @@ def movieFunc():
movs.close()
except:
logThis("Problem picking the movie (error code 801)")
return("error","801","","")
return("error","804","","")
try:
logThis("Searching for "+mov)
@ -42,5 +42,5 @@ def movieFunc():
logThis("Successfully ran !movie")
return(movie['title'], movie['plot'][0].split("::")[0], movie['cover url'].replace("150","600").replace("101","404"), pcast[:-2])
except:
logThis("Something bad happened... (error code 800)")
return("error","800","","")
logThis("Something bad happened... (error code 801)")
return("error","801","","")

View File

@ -1 +1,3 @@
__all__ = ["roll_dice"]
from .dice import roll_dice

View File

@ -1,3 +1,5 @@
__all__ = ["parseChar", "parseRoll", "critRoll", "parseDestiny"]
from .swchar import parseChar
from .swroll import parseRoll, critRoll
from .swdestiny import parseDestiny