🐛 games.json isn't written in await funcs

This commit is contained in:
NikolajDanger
2020-08-02 22:20:00 +02:00
parent b8628d2eb5
commit 3070213562
3 changed files with 24 additions and 23 deletions

View File

@ -87,16 +87,11 @@ async def fiar(channel,command,user):
winner = data["4 in a row games"][str(channel)]["winner"] winner = data["4 in a row games"][str(channel)]["winner"]
if winner != 0: if winner != 0:
with open("resources/games/games.json","w") as f:
json.dump(data,f,indent=4)
addMoney(data["4 in a row games"][str(channel)]["players"][winner-1].lower(),20) addMoney(data["4 in a row games"][str(channel)]["players"][winner-1].lower(),20)
with open("resources/games/games.json", "r") as f: with open("resources/games/games.json", "r") as f:
data = json.load(f) data = json.load(f)
del data["4 in a row games"][str(channel)] deleteGame("4 in a row games",str(channel))
with open("resources/games/games.json","w") as f:
json.dump(data,f,indent=4)
# Deletes a message # Deletes a message
async def deleteMessage(imageLocation,channel): async def deleteMessage(imageLocation,channel):
@ -189,15 +184,7 @@ async def parseCommands(message,content):
if message.author.display_name == "Nikolaj": if message.author.display_name == "Nikolaj":
await message.channel.send("Logging out...") await message.channel.send("Logging out...")
with open("resources/games/games.json","r") as f: stopServer()
data = json.load(f)
data["trivia questions"] = {}
data["blackjack games"] = {}
data["4 in a row games"] = {}
with open("resources/games/games.json","w") as f:
json.dump(data,f,indent=4)
await client.logout() await client.logout()
else: else:
@ -441,12 +428,7 @@ async def parseCommands(message,content):
triviaCountPoints(str(message.channel)) triviaCountPoints(str(message.channel))
with open("resources/games/games.json", "r") as f: deleteGame("trivia questions",str(message.channel))
data = json.load(f)
del data["trivia questions"][str(message.channel)]
with open("resources/games/games.json", "w") as f:
json.dump(data,f,indent=4)
logThis("Time's up for the trivia question",str(message.channel)) logThis("Time's up for the trivia question",str(message.channel))
await message.channel.send("Time's up The answer was \""+chr(correctAnswer)+") "+answers[correctAnswer-97]+"\". Anyone who answered that has gotten 1 GwendoBuck") await message.channel.send("Time's up The answer was \""+chr(correctAnswer)+") "+answers[correctAnswer-97]+"\". Anyone who answered that has gotten 1 GwendoBuck")

View File

@ -1,4 +1,4 @@
from .miscFuncs import helloFunc, cap, imageFunc, logThis, findWikiPage, makeFiles, replaceMultiple, emojiToNumber, fiarReactionTest from .miscFuncs import helloFunc, cap, imageFunc, logThis, findWikiPage, makeFiles, replaceMultiple, emojiToNumber, fiarReactionTest, deleteGame, stopServer
from .swfuncs import * from .swfuncs import *

View File

@ -255,3 +255,22 @@ def fiarReactionTest(channel,message,user):
return False, 0 return False, 0
else: else:
return False, 0 return False, 0
def stopServer():
with open("resources/games/games.json","r") as f:
data = json.load(f)
data["trivia questions"] = {}
data["blackjack games"] = {}
data["4 in a row games"] = {}
with open("resources/games/games.json","w") as f:
json.dump(data,f,indent=4)
def deleteGame(gameType,channel):
with open("resources/games/games.json", "r") as f:
data = json.load(f)
del data[gameType][channel]
with open("resources/games/games.json", "w") as f:
json.dump(data,f,indent=4)