🏗️ Built framework for games
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@ -151,6 +151,6 @@ static
|
|||||||
.vscode/
|
.vscode/
|
||||||
token.txt
|
token.txt
|
||||||
resources/swcharacters.json
|
resources/swcharacters.json
|
||||||
resources/trivia.json
|
resources/games.json
|
||||||
resources/destinyPoints.txt
|
resources/destinyPoints.txt
|
||||||
gwendolynTest.py
|
gwendolynTest.py
|
||||||
|
12
Gwendolyn.py
12
Gwendolyn.py
@ -53,12 +53,12 @@ async def on_message(message):
|
|||||||
funcs.logThis(message.author.name+" ran \""+message.content+"\"")
|
funcs.logThis(message.author.name+" ran \""+message.content+"\"")
|
||||||
await message.channel.send("Logging out...")
|
await message.channel.send("Logging out...")
|
||||||
|
|
||||||
with open("resources/trivia.json","r") as f:
|
with open("resources/games.json","r") as f:
|
||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
|
|
||||||
data["questions"] = {}
|
data["trivia questions"] = {}
|
||||||
|
|
||||||
with open("resources/trivia.json","w") as f:
|
with open("resources/games.json","w") as f:
|
||||||
json.dump(data,f,indent=4)
|
json.dump(data,f,indent=4)
|
||||||
|
|
||||||
await client.logout()
|
await client.logout()
|
||||||
@ -254,11 +254,11 @@ async def on_message(message):
|
|||||||
|
|
||||||
funcs.triviaCountPoints(str(message.channel))
|
funcs.triviaCountPoints(str(message.channel))
|
||||||
|
|
||||||
with open("resources/trivia.json", "r") as f:
|
with open("resources/games.json", "r") as f:
|
||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
|
|
||||||
del data["questions"][str(message.channel)]
|
del data["trivia questions"][str(message.channel)]
|
||||||
with open("resources/trivia.json", "w") as f:
|
with open("resources/games.json", "w") as f:
|
||||||
json.dump(data,f,indent=4)
|
json.dump(data,f,indent=4)
|
||||||
|
|
||||||
funcs.logThis("Time's up for the trivia question in "+str(message.channel))
|
funcs.logThis("Time's up for the trivia question in "+str(message.channel))
|
||||||
|
@ -4,6 +4,8 @@ from .swfuncs import parseChar, parseRoll, parseDestiny, critRoll
|
|||||||
|
|
||||||
from .lookup import spellFunc, monsterFunc
|
from .lookup import spellFunc, monsterFunc
|
||||||
|
|
||||||
from .other import nameGen, tavernGen, movieFunc, triviaStart, triviaOtherThing, triviaCountPoints
|
from .other import nameGen, tavernGen, movieFunc
|
||||||
|
|
||||||
|
from .games import triviaStart, triviaOtherThing, triviaCountPoints
|
||||||
|
|
||||||
from .roll import roll_dice
|
from .roll import roll_dice
|
1
funcs/games/__init__.py
Normal file
1
funcs/games/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
from .trivia import triviaCountPoints, triviaStart, triviaOtherThing
|
@ -5,12 +5,12 @@ import random
|
|||||||
from funcs import logThis
|
from funcs import logThis
|
||||||
|
|
||||||
def triviaStart(channel : str):
|
def triviaStart(channel : str):
|
||||||
with open("resources/trivia.json", "r") as f:
|
with open("resources/games.json", "r") as f:
|
||||||
triviaFile = json.load(f)
|
triviaFile = json.load(f)
|
||||||
|
|
||||||
logThis("Trying to find a trivia question for "+channel)
|
logThis("Trying to find a trivia question for "+channel)
|
||||||
|
|
||||||
if channel not in triviaFile["questions"]:
|
if channel not in triviaFile["trivia questions"]:
|
||||||
with urllib.request.urlopen("https://opentdb.com/api.php?amount=10&type=multiple") as response:
|
with urllib.request.urlopen("https://opentdb.com/api.php?amount=10&type=multiple") as response:
|
||||||
data = json.loads(response.read())
|
data = json.loads(response.read())
|
||||||
|
|
||||||
@ -20,8 +20,8 @@ def triviaStart(channel : str):
|
|||||||
random.shuffle(answers)
|
random.shuffle(answers)
|
||||||
correctAnswer = answers.index(data["results"][0]["correct_answer"]) + 97
|
correctAnswer = answers.index(data["results"][0]["correct_answer"]) + 97
|
||||||
|
|
||||||
triviaFile["questions"][channel] = {"answer" : str(chr(correctAnswer)),"players" : {}}
|
triviaFile["trivia questions"][channel] = {"answer" : str(chr(correctAnswer)),"players" : {}}
|
||||||
with open("resources/trivia.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(""","\"")
|
question = data["results"][0]["question"].replace("'","\'").replace(""","\"")
|
||||||
@ -32,17 +32,17 @@ def triviaStart(channel : str):
|
|||||||
return "There's already a trivia question going on. Try again in like, a minute", "", ""
|
return "There's already a trivia question going on. Try again in like, a minute", "", ""
|
||||||
|
|
||||||
def triviaOtherThing(user : str, channel : str, command : str):
|
def triviaOtherThing(user : str, channel : str, command : str):
|
||||||
with open("resources/trivia.json", "r") as f:
|
with open("resources/games.json", "r") as f:
|
||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
|
|
||||||
if command in ["a","b","c","d"]:
|
if command in ["a","b","c","d"]:
|
||||||
if channel in data["questions"]:
|
if channel in data["trivia questions"]:
|
||||||
if user not in data["questions"][channel]["players"]:
|
if user not in data["trivia questions"][channel]["players"]:
|
||||||
logThis(user+" answered the question in "+channel)
|
logThis(user+" answered the question in "+channel)
|
||||||
|
|
||||||
data["questions"][channel]["players"][user] = command
|
data["trivia questions"][channel]["players"][user] = command
|
||||||
|
|
||||||
with open("resources/trivia.json", "w") as f:
|
with open("resources/games.json", "w") as f:
|
||||||
json.dump(data,f,indent=4)
|
json.dump(data,f,indent=4)
|
||||||
|
|
||||||
return "Locked in "+user+"'s answer"
|
return "Locked in "+user+"'s answer"
|
||||||
@ -58,21 +58,21 @@ def triviaOtherThing(user : str, channel : str, command : str):
|
|||||||
return "I didn't quite understand that"
|
return "I didn't quite understand that"
|
||||||
|
|
||||||
def triviaCountPoints(channel : str):
|
def triviaCountPoints(channel : str):
|
||||||
with open("resources/trivia.json", "r") as f:
|
with open("resources/games.json", "r") as f:
|
||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
|
|
||||||
logThis("Counting points for question in "+channel)
|
logThis("Counting points for question in "+channel)
|
||||||
|
|
||||||
if channel in data["questions"]:
|
if channel in data["trivia questions"]:
|
||||||
for player, answer in data["questions"][channel]["players"].items():
|
for player, answer in data["trivia questions"][channel]["players"].items():
|
||||||
if answer == data["questions"][channel]["answer"]:
|
if answer == data["trivia questions"][channel]["answer"]:
|
||||||
if player in data["users"]:
|
if player in data["users"]:
|
||||||
points = data["users"][player]
|
points = data["users"][player]
|
||||||
data["users"][player] = points + 1
|
data["users"][player] = points + 1
|
||||||
else:
|
else:
|
||||||
data["users"][player] = 1
|
data["users"][player] = 1
|
||||||
|
|
||||||
with open("resources/trivia.json", "w") as f:
|
with open("resources/games.json", "w") as f:
|
||||||
json.dump(data,f,indent=4)
|
json.dump(data,f,indent=4)
|
||||||
|
|
||||||
else:
|
else:
|
@ -137,13 +137,13 @@ def makeFiles():
|
|||||||
finally:
|
finally:
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
# Creates trivia.json if it doesn't exist
|
# Creates games.json if it doesn't exist
|
||||||
try:
|
try:
|
||||||
f = open("resources/trivia.json","r")
|
f = open("resources/games.json","r")
|
||||||
except:
|
except:
|
||||||
logThis("trivia.json didn't exist. Making it now.")
|
logThis("games.json didn't exist. Making it now.")
|
||||||
data = {"questions":{},"users":{}}
|
data = {"trivia questions":{},"users":{}}
|
||||||
with open("resources/trivia.json","w") as f:
|
with open("resources/games.json","w") as f:
|
||||||
json.dump(data,f,indent = 4)
|
json.dump(data,f,indent = 4)
|
||||||
finally:
|
finally:
|
||||||
f.close()
|
f.close()
|
||||||
|
@ -1,3 +1,2 @@
|
|||||||
from .generators import nameGen, tavernGen
|
from .generators import nameGen, tavernGen
|
||||||
from .movie import movieFunc
|
from .movie import movieFunc
|
||||||
from .trivia import triviaCountPoints, triviaStart, triviaOtherThing
|
|
Reference in New Issue
Block a user