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