From 0d440ead76ed839dd108d0da991f3b29d65de4e6 Mon Sep 17 00:00:00 2001 From: Alek Ratzloff Date: Thu, 18 Jul 2024 11:05:12 -0700 Subject: [PATCH] Add error logging For specific error messages that come in, we should give back an error-level log instead of logging to debug or trace. Signed-off-by: Alek Ratzloff --- omnibot/bot.py | 66 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 2 deletions(-) diff --git a/omnibot/bot.py b/omnibot/bot.py index 09da8d4..e27c0b5 100644 --- a/omnibot/bot.py +++ b/omnibot/bot.py @@ -11,6 +11,61 @@ from . import plugin log = logging.getLogger(__name__) +ERRORS = { + "401": "ERR_NOSUCHNICK", + "402": "ERR_NOSUCHSERVER", + "403": "ERR_NOSUCHCHANNEL", + "404": "ERR_CANNOTSENDTOCHAN", + "405": "ERR_TOOMANYCHANNELS", + "406": "ERR_WASNOSUCHNICK", + "407": "ERR_TOOMANYTARGETS", + "408": "ERR_NOSUCHSERVICE", + "409": "ERR_NOORIGIN", + "411": "ERR_NORECIPIENT", + "412": "ERR_NOTEXTTOSEND", + "413": "ERR_NOTOPLEVEL", + "414": "ERR_WILDTOPLEVEL", + "415": "ERR_BADMASK", + "421": "ERR_UNKNOWNCOMMAND", + "422": "ERR_NOMOTD", + "423": "ERR_NOADMININFO", + "424": "ERR_FILEERROR", + "431": "ERR_NONICKNAMEGIVEN", + "432": "ERR_ERRONEUSNICKNAME", + "433": "ERR_NICKNAMEINUSE", + "436": "ERR_NICKCOLLISION", + "437": "ERR_UNAVAILRESOURCE", + "441": "ERR_USERNOTINCHANNEL", + "442": "ERR_NOTONCHANNEL", + "443": "ERR_USERONCHANNEL", + "444": "ERR_NOLOGIN", + "445": "ERR_SUMMONDISABLED", + "446": "ERR_USERSDISABLED", + "451": "ERR_NOTREGISTERED", + "461": "ERR_NEEDMOREPARAMS", + "462": "ERR_ALREADYREGISTRED", + "463": "ERR_NOPERMFORHOST", + "464": "ERR_PASSWDMISMATCH", + "465": "ERR_YOUREBANNEDCREEP", + "466": "ERR_YOUWILLBEBANNED", + "467": "ERR_KEYSET", + "471": "ERR_CHANNELISFULL", + "472": "ERR_UNKNOWNMODE", + "473": "ERR_INVITEONLYCHAN", + "474": "ERR_BANNEDFROMCHAN", + "475": "ERR_BADCHANNELKEY", + "476": "ERR_BADCHANMASK", + "477": "ERR_NOCHANMODES", + "478": "ERR_BANLISTFULL", + "481": "ERR_NOPRIVILEGES", + "482": "ERR_CHANOPRIVSNEEDED", + "483": "ERR_CANTKILLSERVER", + "484": "ERR_RESTRICTED", + "485": "ERR_UNIQOPPRIVSNEEDED", + "491": "ERR_NOOPERHOST", + "501": "ERR_UMODEUNKNOWNFLAG", + "502": "ERR_USERSDONTMATCH", +} class Bot: @@ -62,6 +117,10 @@ class Bot: self.connection.register("PART", self.on_part) self.connection.register("KICK", self.on_kick) self.connection.register("*", self.on_message) + # Add errors + for code, _message in ERRORS.items(): + self.connection.register(code, self.on_error) + # Connect log.info("Connecting to %s", self.server_config.server) await self.connection.connect() @@ -128,11 +187,11 @@ class Bot: async def on_message(self, conn: IrcProtocol, message: Message): # Pass the message to the plugins - log.debug("%s", message) + log.trace("%s", message) channel = message.parameters[0] who = message.prefix if who.nick == self.server_config.nick: - # Don't raise on_message events for ourselves. + # Don't raise on_message events for ourselves return line = message.parameters[1] @@ -163,6 +222,9 @@ class Bot: *[plugin.on_message(conn, channel, who, line) for plugin in plugins] ) + async def on_error(self, _conn: IrcProtocol, message: Message): + log.error("%s", message) + async def keepalive(self): await self.__quitting.wait() log.info("Shutting down gracefully")