summaryrefslogtreecommitdiff
path: root/bot.py
diff options
context:
space:
mode:
Diffstat (limited to 'bot.py')
-rw-r--r--bot.py39
1 files changed, 20 insertions, 19 deletions
diff --git a/bot.py b/bot.py
index cd95af3..365e36a 100644
--- a/bot.py
+++ b/bot.py
@@ -4,7 +4,7 @@ import sys
import miniirc
allowed_solutions = [
- w.strip().upper() for w in open("solutions.txt", "r").readlines()
+ w.strip().upper() for w in open("wow.dict", "r").readlines()
]
allowed_guesses = set(
[w.strip().upper() for w in open("guesses.txt", "r").readlines()]
@@ -21,7 +21,7 @@ wrg = lambda s: "\x0f" + s + "\x0f"
def check_guess(guess, answer):
res = []
for i, letter in enumerate(guess):
- if answer[i] == guess[i]:
+ if i < len(answer) and answer[i] == guess[i]:
res += ext(letter)
elif letter in answer:
res += ptl(letter)
@@ -35,7 +35,7 @@ ident = nick
realname = "git://git.andrewyu.org/wordle.git"
identity = None
debug = True
-channels = ["#LibreIRC", "#LibreSpeech"]
+channels = ["#LibreSpeech", "#libreirc"]
prefix = "%"
ip = "irc.andrewyu.org"
@@ -64,31 +64,32 @@ def handle_privmsg(irc, hostmask, args):
if cmd.startswith(prefix):
cmd = cmd[len(prefix) :]
if cmd == "start":
- state[hostmask[0]] = {"guessed": [], "accumulation": []}
- state[hostmask[0]]["solution"] = choice(allowed_solutions)
- print(state[hostmask[0]]["solution"])
- irc.msg(sendto, hostmask[0] + ": You have started a game. Your word has " + str(len(state[hostmask[0]]["solution"])) + " letters. You have " + str(ALLOWED_GUESSES) + " attempts. Use " + prefix + "guess to guess.")
+ state[sendto] = {"guessed": [], "accumulation": []}
+ state[sendto]["solution"] = choice(allowed_solutions)
+ print(state[sendto]["solution"])
+ irc.msg(sendto, hostmask[0] + ": You have started a game. Your word has " + str(len(state[sendto]["solution"])) + " letters. You have " + str(ALLOWED_GUESSES) + " attempts. Use " + prefix + "guess to guess.")
elif cmd == "guess":
- if hostmask[0] not in state.keys():
+ if sendto not in state.keys():
irc.msg(sendto, hostmask[0] + ": You aren't in a game. Use " + prefix + "start to use.")
+ return
guess = " ".join(text[1:]).strip().upper()
- if guess in state[hostmask[0]]["guessed"]:
+ if guess in state[sendto]["guessed"]:
irc.msg(sendto, hostmask[0] + ": %s has already been guessed." % guess)
return
elif guess not in allowed_guesses:
irc.msg(sendto, hostmask[0] + ": %s isn't in my dictionary." % guess)
return
- state[hostmask[0]]["guessed"].append(guess)
- res = check_guess(guess, state[hostmask[0]]["solution"])
- state[hostmask[0]]["accumulation"].append(res)
- irc.msg(sendto, hostmask[0] + ": " + str(' '.join(state[hostmask[0]]["accumulation"])))
- if guess == state[hostmask[0]]["solution"]:
- irc.msg(seneto, hostmask[0] + ": %s is indeed the solution." % guess)
- del state[hostmask[0]]
+ state[sendto]["guessed"].append(guess)
+ res = check_guess(guess, state[sendto]["solution"])
+ state[sendto]["accumulation"].append(res)
+ irc.msg(sendto, hostmask[0] + ": " + str(' '.join(state[sendto]["accumulation"])))
+ if guess == state[sendto]["solution"]:
+ irc.msg(sendto, hostmask[0] + ": %s is indeed the solution." % guess)
+ del state[sendto]
return
- elif len(state[hostmask[0]]["accumulation"]) >= ALLOWED_GUESSES:
- irc.msg(sendto, hostmask[0] + ": You used up your chances! It was %s." % state[hostmask[0]]["solution"])
- del state[hostmask[0]]
+ elif len(state[sendto]["accumulation"]) >= ALLOWED_GUESSES:
+ irc.msg(sendto, hostmask[0] + ": You used up your chances! It was %s." % state[sendto]["solution"])
+ del state[sendto]
return