Files
Gwendolyn/funcs/swfuncs/swdestiny.py
2020-08-13 16:31:28 +02:00

69 lines
2.7 KiB
Python

from funcs import logThis
class SwDestiny():
def __init__(self, bot):
self.bot = bot
def destinyNew(self, num : int):
logThis("Creating a new destiny pool with "+str(num)+" players")
roll, diceResults = self.bot.swroll.roll(0,0,0,0,0,0,num)
roll = "".join(sorted(roll))
with open("resources/starWars/destinyPoints.txt","wt") as f:
f.write(roll)
return "Rolled for Destiny Points and got:\n"+self.bot.swroll.diceResultToEmoji(diceResults)+"\n"+self.bot.swroll.resultToEmoji(roll)
def destinyUse(self, user : str):
with open("resources/starWars/destinyPoints.txt","rt") as f:
points = f.read()
if user == "Nikolaj":
logThis("Trying to use a dark side destiny point")
if 'B' in points:
points = points.replace("B","L",1)
points = "".join(sorted(points))
with open("resources/starWars/destinyPoints.txt","wt") as f:
f.write(points)
logThis("Did it")
return "Used a dark side destiny point. Destiny pool is now:\n"+self.bot.swroll.resultToEmoji(points)
else:
logThis("There were no dark side destiny points")
return "No dark side destiny points"
else:
logThis("Trying to use a light side destiny point")
if 'L' in points:
points = points.replace("L","B",1)
points = "".join(sorted(points))
with open("resources/starWars/destinyPoints.txt","wt") as f:
f.write(points)
logThis("Did it")
return "Used a light side destiny point. Destiny pool is now:\n"+self.bot.swroll.resultToEmoji(points)
else:
logThis("There were no dark side destiny points")
return "No light side destiny points"
def parseDestiny(self, user : str, cmd : str):
if cmd != "":
while cmd[0] == ' ':
cmd = cmd[1:]
if cmd == "":
break
if cmd == "":
logThis("Retrieving destiny pool info")
with open("resources/starWars/destinyPoints.txt","rt") as f:
return self.bot.swroll.resultToEmoji(f.read())
else:
commands = cmd.upper().split(" ")
if commands[0] == "N":
if len(commands) > 1:
return self.destinyNew(int(commands[1]))
else:
return "You need to give an amount of players (error code 921)"
elif commands[0] == "U":
return self.destinyUse(user)
else:
return "I didn't quite understand that (error code 922)"