insert real commit message here
parent
bf0529e19d
commit
a59fcf0adb
32
main.py
32
main.py
|
@ -17,7 +17,7 @@ llama_headers = {
|
|||
"Authorization": config["llama_key"]
|
||||
}
|
||||
|
||||
channel_re = re.compile(r"PRIVMSG (#\w+)")
|
||||
channel_re = re.compile(r"PRIVMSG (#*\w+)")
|
||||
name_re = re.compile(r"^:([^!]*)!")
|
||||
llm_answer_re = re.compile(r"^(true|false)")
|
||||
|
||||
|
@ -28,12 +28,10 @@ realname = "a bot by ~nebula"
|
|||
helptext = "!trivia, !trscores, !aitrivia, !aiscores for trivia game. contact ~nebula for help, feedback or problem reports."
|
||||
channels = config["channels"]
|
||||
|
||||
url = "https://opentdb.com/api.php?amount=50&type=boolean&encode=base64"
|
||||
questions_file = "trivia.questions"
|
||||
state_file = "trivia.state"
|
||||
score_file = "trivia.scores"
|
||||
unselected_file = "trivia.unselected"
|
||||
|
||||
ai_state_file = "trivia.aistate"
|
||||
ai_score_file = "trivia.aiscores"
|
||||
|
||||
|
@ -85,7 +83,6 @@ def write_state():
|
|||
with open(ai_state_file, "w") as f:
|
||||
dump(ai_state, f)
|
||||
|
||||
|
||||
def get_question(ai_enabled=False):
|
||||
global questions
|
||||
global unselected
|
||||
|
@ -138,10 +135,10 @@ def ai_answer(choice, channel, name):
|
|||
llm_answer = llm_answer.group(1)
|
||||
if llm_answer.lower() == answer:
|
||||
line = "The AI was (at least kind of) right! "
|
||||
user_correct = choice == "correct"
|
||||
user_correct = choice == "right"
|
||||
else:
|
||||
line = "The AI was wrong! "
|
||||
user_correct = choice == "incorrect"
|
||||
user_correct = choice == "wrong"
|
||||
else:
|
||||
return [
|
||||
f"Cannot automatically determine if AI is right or wrong.",
|
||||
|
@ -172,7 +169,6 @@ def ai_answer(choice, channel, name):
|
|||
f"The right answer is {answer}!"
|
||||
]
|
||||
|
||||
|
||||
def answer(choice, channel, name):
|
||||
global state
|
||||
if channel not in state.keys():
|
||||
|
@ -230,12 +226,11 @@ def answer_true(channel, name):
|
|||
def answer_false(channel, name):
|
||||
return answer("false", channel, name)
|
||||
|
||||
def answer_correct(channel, name):
|
||||
return ai_answer("correct", channel, name)
|
||||
|
||||
def answer_incorrect(channel, name):
|
||||
return ai_answer("incorrect", channel, name)
|
||||
def answer_right(channel, name):
|
||||
return ai_answer("right", channel, name)
|
||||
|
||||
def answer_wrong(channel, name):
|
||||
return ai_answer("wrong", channel, name)
|
||||
|
||||
def make_no_ping_username(name):
|
||||
return name[0] + "\u200b" + name[1:]
|
||||
|
@ -291,8 +286,7 @@ class IRCBot():
|
|||
sleep(2)
|
||||
response = self.s.recv(8192).decode("UTF-8")
|
||||
if not response:
|
||||
print(f"{self.nick}: no response from IRC server")
|
||||
continue
|
||||
exit(f"{self.nick}: no response from IRC server")
|
||||
split = response.split("\r\n")
|
||||
for line in split:
|
||||
line = line.strip()
|
||||
|
@ -324,8 +318,7 @@ class IRCBot():
|
|||
self.send(channel, result)
|
||||
if message_body:
|
||||
for callback in self.searchers:
|
||||
callback(message_body)
|
||||
|
||||
callback(message_body)
|
||||
|
||||
def run():
|
||||
bot = IRCBot(
|
||||
|
@ -339,8 +332,8 @@ def run():
|
|||
("!aiscores", post_top_ai_scores),
|
||||
("true", answer_true),
|
||||
("false", answer_false),
|
||||
("right", answer_correct),
|
||||
("wrong", answer_incorrect)
|
||||
("right", answer_right),
|
||||
("wrong", answer_wrong)
|
||||
],
|
||||
[ # message searchers
|
||||
# empty
|
||||
|
@ -352,4 +345,5 @@ def run():
|
|||
sleep(2)
|
||||
bot.ping_pong()
|
||||
|
||||
print("run with -i flag, run()")
|
||||
if __name__ == "__main__":
|
||||
run()
|
||||
|
|
Loading…
Reference in New Issue