💰 Added money-based commands

This commit is contained in:
Nikolaj Danger
2020-07-27 18:19:14 +02:00
parent 95d5fa685a
commit b971c0d522
6 changed files with 85 additions and 14 deletions

View File

@ -268,7 +268,7 @@ async def on_message(message):
elif message.content.lower().startswith("!trivia "):
command = message.content.lower().replace("!trivia ","")
response = funcs.triviaOtherThing(message.author.name,str(message.channel),command)
response = funcs.triviaOtherThing(message.author.name.lower(),str(message.channel),command)
if response.startswith("Locked in "):
await message.add_reaction("👍")
else:
@ -277,6 +277,29 @@ async def on_message(message):
funcs.logThis("I didn't understand that")
await message.channel.send("I didn't understand that")
#Checks your point balance
elif message.content.lower().startswith("!balance"):
funcs.logThis(message.author.name+" ran \""+message.content+"\"")
response = funcs.checkBalance(message.author.name.lower())
await message.channel.send(message.author.name + " has " + str(response) + " points")
#gives money to other player
elif message.content.lower().startswith("!give "):
funcs.logThis(message.author.name+" ran \""+message.content+"\"")
commands = message.content.lower().split(" ")
if len(commands) >= 3:
try:
amount = int(commands[2])
response = funcs.giveMoney(message.author.name.lower(),commands[1],amount)
await message.channel.send(response)
except:
funcs.logThis("I didn't quite understand that")
await message.channel.send("I didn't quite understand that")
else:
funcs.logThis("I didn't understand that")
await message.channel.send("I didn't understand that")
# Is a bit sassy sometimes
meanWords = ["stupid", "bitch", "fuck", "dumb", "idiot"]

View File

@ -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

View File

@ -1 +1,2 @@
from .money import checkBalance, giveMoney
from .trivia import triviaCountPoints, triviaStart, triviaOtherThing

40
funcs/games/money.py Normal file
View 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"

View File

@ -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")

View File

@ -18,6 +18,10 @@
**!trivia** - Lader dig spille et spil trivia.
**!balance** - Viser dig hvor mange point du har.
**!give** - Lader dig give point til andre.
**!swchar** - Lader dig lave en Star Wars karakter.
**!swroll** - Lader dig rulle Star Wars terninger.