💰 Added money-based commands
This commit is contained in:
25
Gwendolyn.py
25
Gwendolyn.py
@ -268,7 +268,7 @@ async def on_message(message):
|
|||||||
|
|
||||||
elif message.content.lower().startswith("!trivia "):
|
elif message.content.lower().startswith("!trivia "):
|
||||||
command = message.content.lower().replace("!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 "):
|
if response.startswith("Locked in "):
|
||||||
await message.add_reaction("👍")
|
await message.add_reaction("👍")
|
||||||
else:
|
else:
|
||||||
@ -277,6 +277,29 @@ async def on_message(message):
|
|||||||
funcs.logThis("I didn't understand that")
|
funcs.logThis("I didn't understand that")
|
||||||
await message.channel.send("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
|
# Is a bit sassy sometimes
|
||||||
meanWords = ["stupid", "bitch", "fuck", "dumb", "idiot"]
|
meanWords = ["stupid", "bitch", "fuck", "dumb", "idiot"]
|
||||||
|
@ -6,6 +6,6 @@ from .lookup import spellFunc, monsterFunc
|
|||||||
|
|
||||||
from .other import nameGen, tavernGen, movieFunc
|
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
|
from .roll import roll_dice
|
@ -1 +1,2 @@
|
|||||||
|
from .money import checkBalance, giveMoney
|
||||||
from .trivia import triviaCountPoints, triviaStart, triviaOtherThing
|
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 urllib
|
||||||
import random
|
import random
|
||||||
|
|
||||||
|
from . import money
|
||||||
from funcs import logThis
|
from funcs import logThis
|
||||||
|
|
||||||
def triviaStart(channel : str):
|
def triviaStart(channel : str):
|
||||||
@ -24,7 +25,19 @@ def triviaStart(channel : str):
|
|||||||
with open("resources/games.json", "w") as f:
|
with open("resources/games.json", "w") as f:
|
||||||
json.dump(triviaFile,f,indent=4)
|
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
|
return question, answers, correctAnswer
|
||||||
else:
|
else:
|
||||||
@ -50,10 +63,6 @@ def triviaOtherThing(user : str, channel : str, command : str):
|
|||||||
return user+" has already answered this question"
|
return user+" has already answered this question"
|
||||||
else:
|
else:
|
||||||
return "There's no question right now"
|
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:
|
else:
|
||||||
return "I didn't quite understand that"
|
return "I didn't quite understand that"
|
||||||
|
|
||||||
@ -66,14 +75,8 @@ def triviaCountPoints(channel : str):
|
|||||||
if channel in data["trivia questions"]:
|
if channel in data["trivia questions"]:
|
||||||
for player, answer in data["trivia questions"][channel]["players"].items():
|
for player, answer in data["trivia questions"][channel]["players"].items():
|
||||||
if answer == data["trivia questions"][channel]["answer"]:
|
if answer == data["trivia questions"][channel]["answer"]:
|
||||||
if player in data["users"]:
|
money.addMoney(player,1)
|
||||||
points = data["users"][player]
|
|
||||||
data["users"][player] = points + 1
|
|
||||||
else:
|
|
||||||
data["users"][player] = 1
|
|
||||||
|
|
||||||
with open("resources/games.json", "w") as f:
|
|
||||||
json.dump(data,f,indent=4)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
logThis("Couldn't find the question")
|
logThis("Couldn't find the question")
|
||||||
|
@ -18,6 +18,10 @@
|
|||||||
|
|
||||||
**!trivia** - Lader dig spille et spil trivia.
|
**!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.
|
**!swchar** - Lader dig lave en Star Wars karakter.
|
||||||
|
|
||||||
**!swroll** - Lader dig rulle Star Wars terninger.
|
**!swroll** - Lader dig rulle Star Wars terninger.
|
||||||
|
Reference in New Issue
Block a user