:spakles: Database and OOP
This commit is contained in:
84
funcs/funcs.py
Normal file
84
funcs/funcs.py
Normal file
@@ -0,0 +1,84 @@
|
||||
from .miscFuncs import logThis
|
||||
import git # Used by stopServer()
|
||||
|
||||
class Funcs():
|
||||
def __init__(self,bot):
|
||||
self.bot = bot
|
||||
|
||||
def getName(self,userID):
|
||||
user = self.bot.database["users"].find_one({"_id":userID})
|
||||
|
||||
if user != None:
|
||||
return user["user name"]
|
||||
else:
|
||||
logThis("Couldn't find user "+userID)
|
||||
return userID
|
||||
|
||||
def getID(self,userName):
|
||||
user = self.bot.database["users"].find_one({"user name":userName})
|
||||
|
||||
if user != None:
|
||||
return user["_id"]
|
||||
else:
|
||||
logThis("Couldn't find user "+userName)
|
||||
return None
|
||||
|
||||
def deleteGame(self, gameType,channel):
|
||||
self.bot.database[gameType].delete_one({"_id":channel})
|
||||
|
||||
def stopServer(self):
|
||||
self.bot.database["trivia questions"].delete_many({})
|
||||
self.bot.database["blackjack games"].delete_many({})
|
||||
self.bot.database["4 in a row games"].delete_many({})
|
||||
self.bot.database["hangman games"].delete_many({})
|
||||
self.bot.database["hex games"].delete_many({})
|
||||
self.bot.database["monopoly games"].delete_many({})
|
||||
|
||||
g = git.cmd.Git("")
|
||||
g.pull()
|
||||
|
||||
def fiarReactionTest(self,channel,message,user):
|
||||
game = self.bot.database["4 in a row games"].find_one({"_id":str(channel.id)})
|
||||
|
||||
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 = game["turn"]
|
||||
if user == game["players"][turn]:
|
||||
return True, turn+1
|
||||
else:
|
||||
logThis("It wasn't their turn")
|
||||
return False, 0
|
||||
else:
|
||||
return False, 0
|
||||
|
||||
def monopolyReactionTest(self,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(self, 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
|
||||
Reference in New Issue
Block a user