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