:spakles: Database and OOP
This commit is contained in:
@@ -7,7 +7,6 @@ import time # Used for logging
|
||||
import logging # Used for... you know... logging
|
||||
import wikia # Used by findWikiPage
|
||||
import os # Used by makeFiles
|
||||
import git # Used by stopServer()
|
||||
import pymongo # Used by transferUsers
|
||||
|
||||
logging.basicConfig(filename="gwendolyn.log", level=logging.INFO)
|
||||
@@ -207,86 +206,6 @@ def emojiToCommand(emoji):
|
||||
return "roll"
|
||||
else: return ""
|
||||
|
||||
def fiarReactionTest(channel,message,user):
|
||||
with open("resources/games/games.json", "r") as f:
|
||||
data = json.load(f)
|
||||
|
||||
with open("resources/games/oldImages/fourInARow"+str(channel.id), "r") as f:
|
||||
oldImage = int(f.read())
|
||||
|
||||
if message.id == oldImage:
|
||||
logThis("They reacted to the fourinarow game")
|
||||
turn = data["4 in a row games"][str(channel.id)]["turn"]
|
||||
if user == data["4 in a row games"][str(channel.id)]["players"][turn]:
|
||||
return True, turn+1
|
||||
else:
|
||||
logThis("It wasn't their turn")
|
||||
return False, 0
|
||||
else:
|
||||
return False, 0
|
||||
|
||||
def monopolyReactionTest(channel,message):
|
||||
try:
|
||||
with open("resources/games/oldImages/monopoly"+str(channel.id), "r") as f:
|
||||
oldImage = int(f.read())
|
||||
except:
|
||||
return False
|
||||
|
||||
if message.id == oldImage:
|
||||
logThis("They reacted to the monopoly game")
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def hangmanReactionTest(channel,message):
|
||||
try:
|
||||
with open("resources/games/oldImages/hangman"+str(channel.id), "r") as f:
|
||||
oldMessages = f.read().splitlines()
|
||||
except:
|
||||
return False
|
||||
gameMessage = False
|
||||
|
||||
for oldMessage in oldMessages:
|
||||
oldMessageID = int(oldMessage)
|
||||
if message.id == oldMessageID:
|
||||
logThis("They reacted to the hangman game")
|
||||
gameMessage = True
|
||||
|
||||
return gameMessage
|
||||
|
||||
def stopServer():
|
||||
with open("resources/games/games.json","r") as f:
|
||||
games = json.load(f)
|
||||
|
||||
games["trivia questions"] = {}
|
||||
games["blackjack games"] = {}
|
||||
games["4 in a row games"] = {}
|
||||
|
||||
with open("resources/games/games.json","w") as f:
|
||||
json.dump(games,f,indent=4)
|
||||
|
||||
emptyDict = {}
|
||||
|
||||
with open("resources/games/monopolyGames.json", "w") as f:
|
||||
json.dump(emptyDict,f,indent=4)
|
||||
|
||||
with open("resources/games/hexGames.json", "w") as f:
|
||||
json.dump(emptyDict,f,indent=4)
|
||||
|
||||
with open("resources/games/hangmanGames.json", "w") as f:
|
||||
json.dump(emptyDict,f,indent=4)
|
||||
|
||||
g = git.cmd.Git("")
|
||||
g.pull()
|
||||
|
||||
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)
|
||||
|
||||
def addToDict(userID,userName):
|
||||
with open("resources/users.json", "r") as f:
|
||||
data = json.load(f)
|
||||
@@ -315,35 +234,6 @@ def addToDict(userID,userName):
|
||||
with open("resources/users.json", "w") as f:
|
||||
json.dump(data,f,indent=4)
|
||||
|
||||
def getName(userID):
|
||||
try:
|
||||
with open("resources/users.json", "r") as f:
|
||||
data = json.load(f)
|
||||
|
||||
if userID in data:
|
||||
return data[userID]["user name"]
|
||||
else:
|
||||
logThis("Couldn't find user "+userID)
|
||||
return userID
|
||||
except:
|
||||
logThis("Error getting name")
|
||||
|
||||
def getID(userName):
|
||||
try:
|
||||
with open("resources/users.json", "r") as f:
|
||||
data = json.load(f)
|
||||
|
||||
userID = None
|
||||
|
||||
for key, value in data.items():
|
||||
if userName.lower() == value["user name"].lower():
|
||||
userID = key
|
||||
break
|
||||
|
||||
return userID
|
||||
except:
|
||||
logThis("Error getting ID")
|
||||
|
||||
def transferUsers(database):
|
||||
collist = database.list_collection_names()
|
||||
if "users" not in collist and os.path.exists("resources/users.json"):
|
||||
@@ -354,7 +244,20 @@ def transferUsers(database):
|
||||
userList = []
|
||||
|
||||
for key, value in list(data.items()):
|
||||
user = {"_id":int(key[1:]),"user name":value["user name"],"money":value["money"]}
|
||||
user = {"_id":key,"user name":value["user name"],"money":value["money"]}
|
||||
userList.append(user)
|
||||
|
||||
database["users"].insert_many(userList)
|
||||
|
||||
if "investments" not in collist and os.path.exists("resources/games/investments.json"):
|
||||
logThis("Transfering investments")
|
||||
with open("resources/games/investments.json", "r") as f:
|
||||
data = json.load(f)
|
||||
|
||||
userList = []
|
||||
|
||||
for key, value in list(data.items()):
|
||||
user = {"_id":key,"investments":value}
|
||||
userList.append(user)
|
||||
|
||||
database["investments"].insert_many(userList)
|
||||
|
||||
Reference in New Issue
Block a user