Better credentials

This commit is contained in:
NikolajDanger
2020-08-09 13:02:04 +02:00
parent 9f683034c5
commit 84e332fa68
8 changed files with 56 additions and 49 deletions

View File

@ -3,16 +3,15 @@ import json, urllib, random, datetime, string
from . import hangmanDraw, money
from funcs import getName, logThis
def hangmanStart(channel,user):
apiUrl = "https://api.wordnik.com/v4/words.json/randomWords?hasDictionaryDef=true&minCorpusCount=10000&maxCorpusCount=-1&minDictionaryCount=1&maxDictionaryCount=-1&minLength=3&maxLength=11&limit=1&api_key="
def hangmanStart(channel,user,apiKey):
with open("resources/games/hangmanGames.json", "r") as f:
data = json.load(f)
if channel not in data:
with urllib.request.urlopen("https://random-word-api.herokuapp.com/word?number=20") as p:
words = json.load(p)
word = "disestablishmentarianism"
while len(word) > 11:
word = list(random.choice(words).upper())
with urllib.request.urlopen(apiUrl+apiKey) as p:
word = list(json.load(p)[0]["word"].upper())
logThis("Found the word \""+"".join(word)+"\"")
guessed = [False] * len(word)
gameID = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
@ -97,10 +96,10 @@ def hangmanGuess(channel,user,guess):
else:
return "There's no Hangman game going on in this channel", False, False, []
def parseHangman(channel,user,command):
def parseHangman(channel,user,command,apiKey):
if command == "start":
try:
return hangmanStart(channel,user)
return hangmanStart(channel,user,apiKey)
except:
logThis("Error starting game (error code 1730)")
elif command == "stop":