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