Bug fixes for ping timeout and missing commands in busy channels
This commit is contained in:
parent
f32dce7faf
commit
5246008861
7
app.py
7
app.py
@ -78,6 +78,10 @@ def handle_message(name, source, response):
|
||||
if response == "!debug":
|
||||
bot.logger.debug(":: {}".format(bot.memories))
|
||||
|
||||
def handle_raw(message):
|
||||
with open("/tmp/babs", "a") as babs:
|
||||
babs.write(repr(message) + "\n")
|
||||
|
||||
def handle_crashed():
|
||||
bot.logger.debug("Rebooting")
|
||||
bot.crashed = True
|
||||
@ -104,5 +108,6 @@ if __name__ == "__main__":
|
||||
"invite": handle_invite,
|
||||
"kick": handle_kick,
|
||||
"crashed": handle_crashed,
|
||||
"message": handle_message
|
||||
"message": handle_message,
|
||||
"raw": handle_raw
|
||||
})
|
||||
|
103
bot/core.py
103
bot/core.py
@ -194,6 +194,7 @@ class Bot:
|
||||
|
||||
def stop(self):
|
||||
self.send("QUIT :Overheating, powering down")
|
||||
self.ircsock.close()
|
||||
self.running = False
|
||||
|
||||
def start(self, config, location, callback):
|
||||
@ -254,56 +255,58 @@ class Bot:
|
||||
self.tasks.run()
|
||||
|
||||
while self.running:
|
||||
message = ""
|
||||
while self.splitter not in message:
|
||||
message = self.ircsock.recv(self.recv_size).decode()
|
||||
|
||||
message = message.strip(self.splitter)
|
||||
self.logger.debug("{}".format(message))
|
||||
_message = ""
|
||||
while self.splitter not in _message:
|
||||
_message = self.ircsock.recv(self.recv_size).decode()
|
||||
|
||||
if "raw" in callback:
|
||||
callback["raw"](message)
|
||||
callback["raw"](_message)
|
||||
|
||||
if "PRIVMSG " in message:
|
||||
name, source, response = self.parse(message)
|
||||
if source == self.botnick and "pm" in callback:
|
||||
callback["pm"](name, response)
|
||||
elif "message" in callback:
|
||||
callback["message"](name, source, response)
|
||||
elif "PING :" in message:
|
||||
self.ping(message)
|
||||
if "ping" in callback:
|
||||
callback["ping"]()
|
||||
elif "MODE " in message:
|
||||
channel, mode = self.handle_mode(message)
|
||||
if "mode" in callback:
|
||||
callback["mode"](channel, mode)
|
||||
elif "NICK " in message:
|
||||
old_name, new_name = self.handle_rename(message)
|
||||
if "nick" in callback:
|
||||
callback["nick"](old_name, new_name)
|
||||
elif "KICK " in message:
|
||||
kicker = self.handle_kick(message)
|
||||
if "kick" in callback:
|
||||
callback["kick"](kicker)
|
||||
elif "JOIN " in message:
|
||||
user = self.handle_join(message)
|
||||
if "join" in callback:
|
||||
callback["join"](user)
|
||||
elif "PART " in message:
|
||||
user = self.handle_part(message)
|
||||
if "part" in callback:
|
||||
callback["part"](user)
|
||||
elif "INVITE " in message:
|
||||
channel, name = self.handle_invite(message)
|
||||
if "invite" in callback:
|
||||
callback["invite"](channel, name)
|
||||
elif "unhandled" in callback:
|
||||
if "unhandled" in callback:
|
||||
callback["unhandled"](message)
|
||||
elif ":Closing link:" in message:
|
||||
self.logger.warning(message)
|
||||
self.stop()
|
||||
if "crashed" in callback:
|
||||
callback["crashed"]()
|
||||
break
|
||||
_message = _message.strip(self.splitter)
|
||||
messages = [msg for msg in _message.split(self.splitter) if msg]
|
||||
|
||||
for message in messages:
|
||||
self.logger.debug("{}".format(message))
|
||||
|
||||
if message[:4] == "PING":
|
||||
self.ping(message)
|
||||
if "ping" in callback:
|
||||
callback["ping"]()
|
||||
elif "PRIVMSG " in message:
|
||||
name, source, response = self.parse(message)
|
||||
if source == self.botnick and "pm" in callback:
|
||||
callback["pm"](name, response)
|
||||
elif "message" in callback:
|
||||
callback["message"](name, source, response)
|
||||
elif "MODE " in message:
|
||||
channel, mode = self.handle_mode(message)
|
||||
if "mode" in callback:
|
||||
callback["mode"](channel, mode)
|
||||
elif "NICK " in message:
|
||||
old_name, new_name = self.handle_rename(message)
|
||||
if "nick" in callback:
|
||||
callback["nick"](old_name, new_name)
|
||||
elif "KICK " in message:
|
||||
kicker = self.handle_kick(message)
|
||||
if "kick" in callback:
|
||||
callback["kick"](kicker)
|
||||
elif "JOIN " in message:
|
||||
user = self.handle_join(message)
|
||||
if "join" in callback:
|
||||
callback["join"](user)
|
||||
elif "PART " in message:
|
||||
user = self.handle_part(message)
|
||||
if "part" in callback:
|
||||
callback["part"](user)
|
||||
elif "INVITE " in message:
|
||||
channel, name = self.handle_invite(message)
|
||||
if "invite" in callback:
|
||||
callback["invite"](channel, name)
|
||||
elif "unhandled" in callback:
|
||||
if "unhandled" in callback:
|
||||
callback["unhandled"](message)
|
||||
elif ":Closing link:" in message:
|
||||
self.logger.warning(message)
|
||||
if "crashed" in callback:
|
||||
callback["crashed"]()
|
||||
break
|
||||
|
@ -21,7 +21,6 @@ class Tasks:
|
||||
))
|
||||
|
||||
def worker(self, tasks):
|
||||
print(tasks.coroutines)
|
||||
for c, coro in enumerate(tasks.coroutines):
|
||||
interval = coro["interval"]
|
||||
worker = coro["worker"]
|
||||
|
Loading…
Reference in New Issue
Block a user