💰 Added money-based commands
This commit is contained in:
@ -6,6 +6,6 @@ from .lookup import spellFunc, monsterFunc
|
||||
|
||||
from .other import nameGen, tavernGen, movieFunc
|
||||
|
||||
from .games import triviaStart, triviaOtherThing, triviaCountPoints
|
||||
from .games import triviaStart, triviaOtherThing, triviaCountPoints, checkBalance, giveMoney
|
||||
|
||||
from .roll import roll_dice
|
@ -1 +1,2 @@
|
||||
from .money import checkBalance, giveMoney
|
||||
from .trivia import triviaCountPoints, triviaStart, triviaOtherThing
|
40
funcs/games/money.py
Normal file
40
funcs/games/money.py
Normal file
@ -0,0 +1,40 @@
|
||||
import json
|
||||
|
||||
from funcs import logThis
|
||||
|
||||
def checkBalance(user):
|
||||
with open("resources/games.json", "r") as f:
|
||||
data = json.load(f)
|
||||
|
||||
if user in data["users"]:
|
||||
return data["users"][user]
|
||||
else: return 0
|
||||
|
||||
def addMoney(user,amount):
|
||||
with open("resources/games.json", "r") as f:
|
||||
data = json.load(f)
|
||||
|
||||
if user in data["users"]:
|
||||
points = data["users"][user]
|
||||
data["users"][user] = points + amount
|
||||
else:
|
||||
data["users"][user] = amount
|
||||
|
||||
with open("resources/games.json", "w") as f:
|
||||
json.dump(data,f,indent=4)
|
||||
|
||||
def giveMoney(user,targetUser,amount):
|
||||
with open("resources/games.json", "r") as f:
|
||||
data = json.load(f)
|
||||
|
||||
if user in data["users"]:
|
||||
if data["users"][user] >= amount:
|
||||
addMoney(user,-1 * amount)
|
||||
addMoney(targetUser,amount)
|
||||
return "Transferred the points"
|
||||
else:
|
||||
logThis("They didn't have enough points")
|
||||
return "You don't have that many points"
|
||||
else:
|
||||
logThis("They didn't have enough points")
|
||||
return "You don't have that many points"
|
@ -2,6 +2,7 @@ import json
|
||||
import urllib
|
||||
import random
|
||||
|
||||
from . import money
|
||||
from funcs import logThis
|
||||
|
||||
def triviaStart(channel : str):
|
||||
@ -24,7 +25,19 @@ def triviaStart(channel : str):
|
||||
with open("resources/games.json", "w") as f:
|
||||
json.dump(triviaFile,f,indent=4)
|
||||
|
||||
question = data["results"][0]["question"].replace("'","\'").replace(""","\"")
|
||||
replacements = {"'": "\'",
|
||||
""": "\"",
|
||||
"“": "\"",
|
||||
"”": "\"",
|
||||
"é": "é"}
|
||||
question = data["results"][0]["question"]
|
||||
|
||||
for key, value in replacements.items():
|
||||
question = question.replace(key,value)
|
||||
|
||||
for answer in answers:
|
||||
for key, value in replacements.items():
|
||||
answer = answer.replace(key,value)
|
||||
|
||||
return question, answers, correctAnswer
|
||||
else:
|
||||
@ -50,10 +63,6 @@ def triviaOtherThing(user : str, channel : str, command : str):
|
||||
return user+" has already answered this question"
|
||||
else:
|
||||
return "There's no question right now"
|
||||
elif command == "p":
|
||||
items = {k: v for k, v in sorted(data["users"].items(), key=lambda item: item[1])}
|
||||
|
||||
return "\n".join(['%s: %s' % (key, value) for (key, value) in items.items()])
|
||||
else:
|
||||
return "I didn't quite understand that"
|
||||
|
||||
@ -66,14 +75,8 @@ def triviaCountPoints(channel : str):
|
||||
if channel in data["trivia questions"]:
|
||||
for player, answer in data["trivia questions"][channel]["players"].items():
|
||||
if answer == data["trivia questions"][channel]["answer"]:
|
||||
if player in data["users"]:
|
||||
points = data["users"][player]
|
||||
data["users"][player] = points + 1
|
||||
else:
|
||||
data["users"][player] = 1
|
||||
money.addMoney(player,1)
|
||||
|
||||
with open("resources/games.json", "w") as f:
|
||||
json.dump(data,f,indent=4)
|
||||
|
||||
else:
|
||||
logThis("Couldn't find the question")
|
||||
|
Reference in New Issue
Block a user