i dont make real commit messages

main
nebula 2024-12-15 16:07:30 -06:00
parent df68318c7f
commit a3700d588c
1 changed files with 22 additions and 21 deletions

43
main.py
View File

@ -97,7 +97,7 @@ def get_question(ai_enabled=False):
else:
return False
def post_question(channel, username):
def post_question(channel, username, arguments):
global trivia_state
question = get_question()
if question:
@ -107,7 +107,7 @@ def post_question(channel, username):
else:
return "internal error"
def post_ai_question(channel, username):
def post_ai_question(channel, username, arguments):
global ai_state
question = get_question(ai_enabled=True)
if question:
@ -190,7 +190,7 @@ def answer(choice, channel, name):
line += " See top scores with !trscores"
return line
def post_top_scores(channel, name):
def post_top_scores(channel, name, arguments):
global trivia_scores
score_list = [(name, score) for name, score in trivia_scores.items()]
if not score_list:
@ -205,7 +205,7 @@ def post_top_scores(channel, name):
count += 1
return line[:-2]
def post_top_ai_scores(channel, name):
def post_top_ai_scores(channel, name, arguments):
global ai_scores
score_list = [(name, score) for name, score in ai_scores.items()]
if not score_list:
@ -220,19 +220,19 @@ def post_top_ai_scores(channel, name):
count += 1
return line[:-2]
def post_help(channel, name):
def post_help(channel, name, arguments):
return helptext
def answer_true(channel, name):
def answer_true(channel, name, arguments):
return answer("true", channel, name)
def answer_false(channel, name):
def answer_false(channel, name, arguments):
return answer("false", channel, name)
def answer_right(channel, name):
def answer_right(channel, name, arguments):
return ai_answer("right", channel, name)
def answer_wrong(channel, name):
def answer_wrong(channel, name, arguments):
return ai_answer("wrong", channel, name)
def make_no_ping_username(name):
@ -284,16 +284,14 @@ class IRCBot():
elif isinstance(content, str):
self.sendline(f"PRIVMSG {channel} :{content}")
def ping_pong(self):
def command_loop(self):
while True:
char = self.s.recv(1)
if not char:
exit(f"{self.nick}: no response from IRC server")
line = b""
while char:
if char == b"\n":
break
elif char != b"\r":
while char != b"\n":
if char != b"\r":
line += char
char = self.s.recv(1)
line = line.decode("UTF-8").strip()
@ -312,16 +310,19 @@ class IRCBot():
name = None
if name and not channel.startswith("#"):
channel = name
try:
message_body = line[line.index(" :") + 2:]
except Exception as e:
print(e)
message_body = ""
for command, callback in self.commands:
if line.lower().endswith(command):
result = callback(channel, name)
try:
arguments = line[line.index(command) + len(command) + 1:]
except (IndexError, ValueError):
arguments = None
result = callback(channel, name, arguments)
if result:
self.send(channel, result)
try:
message_body = line[line.index(" :") + 2:]
except (IndexError, ValueError):
message_body = ""
if message_body:
for callback in self.searchers:
callback(message_body)
@ -351,7 +352,7 @@ def run():
while True:
sleep(0.5)
bot.ping_pong()
bot.command_loop()
if __name__ == "__main__":
run()