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

@ -2,8 +2,6 @@ import json
import urllib
import random
from funcs import logThis
class Trivia():
def __init__(self, bot):
self.bot = bot
@ -13,13 +11,13 @@ class Trivia():
def triviaStart(self, channel : str):
question = self.bot.database["trivia questions"].find_one({"_id":channel})
logThis("Trying to find a trivia question for "+channel)
self.bot.log("Trying to find a trivia question for "+channel)
if question == None:
with urllib.request.urlopen("https://opentdb.com/api.php?amount=10&type=multiple") as response:
data = json.loads(response.read())
logThis("Found the question \""+data["results"][0]["question"]+"\"")
self.bot.log("Found the question \""+data["results"][0]["question"]+"\"")
answers = data["results"][0]["incorrect_answers"]
answers.append(data["results"][0]["correct_answer"])
random.shuffle(answers)
@ -43,7 +41,7 @@ class Trivia():
return question, answers, correctAnswer
else:
logThis("There was already a trivia question for that channel (error code 1106)")
self.bot.log("There was already a trivia question for that channel (error code 1106)")
return "There's already a trivia question going on. Try again in like, a minute (error code 1106)", "", ""
# Lets players answer a trivia question
@ -53,19 +51,19 @@ class Trivia():
if command in ["a","b","c","d"]:
if question != None:
if user not in question["players"]:
logThis(user+" answered the question in "+channel)
self.bot.log(user+" answered the question in "+channel)
self.bot.database["trivia questions"].update_one({"_id":channel},{"$set":{"players."+user : command}})
return "Locked in "+user+"'s answer"
else:
logThis(user+" has already answered this question (error code 1105)")
self.bot.log(user+" has already answered this question (error code 1105)")
return user+" has already answered this question (error code 1105)"
else:
logThis("There's no question right now (error code 1104)")
self.bot.log("There's no question right now (error code 1104)")
return "There's no question right now (error code 1104)"
else:
logThis("I didn't quite understand that (error code 1103)")
self.bot.log("I didn't quite understand that (error code 1103)")
return "I didn't quite understand that (error code 1103)"
@ -73,7 +71,7 @@ class Trivia():
def triviaCountPoints(self, channel : str):
question = self.bot.database["trivia questions"].find_one({"_id":channel})
logThis("Counting points for question in "+channel)
self.bot.log("Counting points for question in "+channel)
if question != None:
for player, answer in question["players"].items():
@ -82,6 +80,6 @@ class Trivia():
else:
logThis("Couldn't find the question (error code 1102)")
self.bot.log("Couldn't find the question (error code 1102)")
return None