🏗️ Built framework for games
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@ -151,6 +151,6 @@ static
|
||||
.vscode/
|
||||
token.txt
|
||||
resources/swcharacters.json
|
||||
resources/trivia.json
|
||||
resources/games.json
|
||||
resources/destinyPoints.txt
|
||||
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+"\"")
|
||||
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["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)
|
||||
|
||||
await client.logout()
|
||||
@ -254,11 +254,11 @@ async def on_message(message):
|
||||
|
||||
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)
|
||||
|
||||
del data["questions"][str(message.channel)]
|
||||
with open("resources/trivia.json", "w") as f:
|
||||
del data["trivia questions"][str(message.channel)]
|
||||
with open("resources/games.json", "w") as f:
|
||||
json.dump(data,f,indent=4)
|
||||
|
||||
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 .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
|
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
|
||||
|
||||
def triviaStart(channel : str):
|
||||
with open("resources/trivia.json", "r") as f:
|
||||
with open("resources/games.json", "r") as f:
|
||||
triviaFile = json.load(f)
|
||||
|
||||
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:
|
||||
data = json.loads(response.read())
|
||||
|
||||
@ -20,8 +20,8 @@ def triviaStart(channel : str):
|
||||
random.shuffle(answers)
|
||||
correctAnswer = answers.index(data["results"][0]["correct_answer"]) + 97
|
||||
|
||||
triviaFile["questions"][channel] = {"answer" : str(chr(correctAnswer)),"players" : {}}
|
||||
with open("resources/trivia.json", "w") as f:
|
||||
triviaFile["trivia questions"][channel] = {"answer" : str(chr(correctAnswer)),"players" : {}}
|
||||
with open("resources/games.json", "w") as f:
|
||||
json.dump(triviaFile,f,indent=4)
|
||||
|
||||
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", "", ""
|
||||
|
||||
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)
|
||||
|
||||
if command in ["a","b","c","d"]:
|
||||
if channel in data["questions"]:
|
||||
if user not in data["questions"][channel]["players"]:
|
||||
if channel in data["trivia questions"]:
|
||||
if user not in data["trivia questions"][channel]["players"]:
|
||||
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)
|
||||
|
||||
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"
|
||||
|
||||
def triviaCountPoints(channel : str):
|
||||
with open("resources/trivia.json", "r") as f:
|
||||
with open("resources/games.json", "r") as f:
|
||||
data = json.load(f)
|
||||
|
||||
logThis("Counting points for question in "+channel)
|
||||
|
||||
if channel in data["questions"]:
|
||||
for player, answer in data["questions"][channel]["players"].items():
|
||||
if answer == data["questions"][channel]["answer"]:
|
||||
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
|
||||
|
||||
with open("resources/trivia.json", "w") as f:
|
||||
with open("resources/games.json", "w") as f:
|
||||
json.dump(data,f,indent=4)
|
||||
|
||||
else:
|
@ -137,13 +137,13 @@ def makeFiles():
|
||||
finally:
|
||||
f.close()
|
||||
|
||||
# Creates trivia.json if it doesn't exist
|
||||
# Creates games.json if it doesn't exist
|
||||
try:
|
||||
f = open("resources/trivia.json","r")
|
||||
f = open("resources/games.json","r")
|
||||
except:
|
||||
logThis("trivia.json didn't exist. Making it now.")
|
||||
data = {"questions":{},"users":{}}
|
||||
with open("resources/trivia.json","w") as f:
|
||||
logThis("games.json didn't exist. Making it now.")
|
||||
data = {"trivia questions":{},"users":{}}
|
||||
with open("resources/games.json","w") as f:
|
||||
json.dump(data,f,indent = 4)
|
||||
finally:
|
||||
f.close()
|
||||
|
@ -1,3 +1,2 @@
|
||||
from .generators import nameGen, tavernGen
|
||||
from .movie import movieFunc
|
||||
from .trivia import triviaCountPoints, triviaStart, triviaOtherThing
|
||||
from .movie import movieFunc
|
Reference in New Issue
Block a user