Fully converted to slash commands

This commit is contained in:
NikolajDanger
2021-03-31 00:38:51 +02:00
parent a8a7e5eabd
commit b345720468
50 changed files with 1102 additions and 1111 deletions

View File

@ -1,3 +1,4 @@
import re, git, os, json
def sanitize(data : str, options : bool = False):
data = data.splitlines()
@ -19,7 +20,7 @@ def sanitize(data : str, options : bool = False):
lineValues[1] = (lineValues[1] == "true")
dct[lineValues[0]] = lineValues[1]
return dct
class Options():
@ -43,4 +44,89 @@ class Credentials():
self.mongoDBPassword = data["mongodb password"]
self.wolfKey = data["wolframalpha appid"]
self.radarrKey = data["radarr api key"]
self.sonarrKey = data["sonarr api key"]
self.sonarrKey = data["sonarr api key"]
class databaseFuncs():
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"]
elif userID == "Gwendolyn":
return userID
else:
self.bot.log("Couldn't find user "+userID)
return userID
def getID(self,userName):
user = self.bot.database["users"].find_one({"user name":re.compile(userName, re.IGNORECASE)})
if user != None:
return user["_id"]
else:
self.bot.log("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["connect 4 games"].delete_many({})
self.bot.database["hangman games"].delete_many({})
if not self.bot.options.testing:
g = git.cmd.Git("")
g.pull()
def connectFourReactionTest(self,channel,message,user):
game = self.bot.database["connect 4 games"].find_one({"_id":str(channel.id)})
with open("resources/games/oldImages/connectFour"+str(channel.id), "r") as f:
oldImage = int(f.read())
if message.id == oldImage:
self.bot.log("They reacted to the connectFour game", level = 10)
turn = game["turn"]
if user == game["players"][turn]:
return True, turn+1
else:
self.bot.log("It wasn't their turn")
return False, 0
else:
return False, 0
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:
self.bot.log("They reacted to the hangman game", level = 10)
gameMessage = True
return gameMessage
def bedreNetflixReactionTest(self, channel, message):
if os.path.isfile(f"resources/bedreNetflix/oldMessage{str(channel.id)}"):
with open("resources/bedreNetflix/oldMessage"+str(channel.id),"r") as f:
data = json.load(f)
else:
return False, None, None
if data["messageID"] == message.id:
if "imdbIds" in data:
return True, True, data["imdbIds"]
else:
return True, False, data["imdbNames"]
else:
return False, None, None