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 <alekratz@gmail.com>
This commit is contained in:
@@ -11,6 +11,61 @@ from . import plugin
|
|||||||
|
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
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:
|
class Bot:
|
||||||
@@ -62,6 +117,10 @@ class Bot:
|
|||||||
self.connection.register("PART", self.on_part)
|
self.connection.register("PART", self.on_part)
|
||||||
self.connection.register("KICK", self.on_kick)
|
self.connection.register("KICK", self.on_kick)
|
||||||
self.connection.register("*", self.on_message)
|
self.connection.register("*", self.on_message)
|
||||||
|
# Add errors
|
||||||
|
for code, _message in ERRORS.items():
|
||||||
|
self.connection.register(code, self.on_error)
|
||||||
|
|
||||||
# Connect
|
# Connect
|
||||||
log.info("Connecting to %s", self.server_config.server)
|
log.info("Connecting to %s", self.server_config.server)
|
||||||
await self.connection.connect()
|
await self.connection.connect()
|
||||||
@@ -128,11 +187,11 @@ class Bot:
|
|||||||
|
|
||||||
async def on_message(self, conn: IrcProtocol, message: Message):
|
async def on_message(self, conn: IrcProtocol, message: Message):
|
||||||
# Pass the message to the plugins
|
# Pass the message to the plugins
|
||||||
log.debug("%s", message)
|
log.trace("%s", message)
|
||||||
channel = message.parameters[0]
|
channel = message.parameters[0]
|
||||||
who = message.prefix
|
who = message.prefix
|
||||||
if who.nick == self.server_config.nick:
|
if who.nick == self.server_config.nick:
|
||||||
# Don't raise on_message events for ourselves.
|
# Don't raise on_message events for ourselves
|
||||||
return
|
return
|
||||||
line = message.parameters[1]
|
line = message.parameters[1]
|
||||||
|
|
||||||
@@ -163,6 +222,9 @@ class Bot:
|
|||||||
*[plugin.on_message(conn, channel, who, line) for plugin in plugins]
|
*[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):
|
async def keepalive(self):
|
||||||
await self.__quitting.wait()
|
await self.__quitting.wait()
|
||||||
log.info("Shutting down gracefully")
|
log.info("Shutting down gracefully")
|
||||||
|
|||||||
Reference in New Issue
Block a user