change socket reading method
parent
20f97a4e8a
commit
98efc6a871
20
main.py
20
main.py
|
@ -286,12 +286,16 @@ class IRCBot():
|
|||
|
||||
def ping_pong(self):
|
||||
while True:
|
||||
sleep(2)
|
||||
response = self.s.recv(8192).decode("UTF-8")
|
||||
if not response:
|
||||
char = self.s.recv(1).decode("UTF-8")
|
||||
if not char:
|
||||
exit(f"{self.nick}: no response from IRC server")
|
||||
split = response.split("\r\n")
|
||||
for line in split:
|
||||
line = ""
|
||||
while char:
|
||||
if char == "\n":
|
||||
break
|
||||
elif char != "\r":
|
||||
line += char
|
||||
char = self.s.recv(1).decode("UTF-8")
|
||||
line = line.strip()
|
||||
if line.startswith("PING"):
|
||||
pong = "PONG " + line[5:]
|
||||
|
@ -300,8 +304,8 @@ class IRCBot():
|
|||
channel_search = channel_re.search(line)
|
||||
if not channel_search:
|
||||
continue
|
||||
name_search = name_re.search(line)
|
||||
channel = channel_search.group(1)
|
||||
name_search = name_re.search(line)
|
||||
if name_search:
|
||||
name = name_search.group(1)
|
||||
else:
|
||||
|
@ -329,7 +333,7 @@ def run():
|
|||
helptext,
|
||||
[ # endswith commands
|
||||
("!help", post_help),
|
||||
("!rollcall", post_help)
|
||||
("!rollcall", post_help),
|
||||
("!trivia", post_question),
|
||||
("!aitrivia", post_ai_question),
|
||||
("!trscores", post_top_scores),
|
||||
|
@ -346,7 +350,7 @@ def run():
|
|||
)
|
||||
|
||||
while True:
|
||||
sleep(2)
|
||||
sleep(0.5)
|
||||
bot.ping_pong()
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Reference in New Issue