I’m using the irc library for my bot. During testing to make sure non-priviledged members cannot abuse the commands I encountered this case:
> !gline 2rqy1KLL5D2MMNVDf9WdKXxZLKxOr0SwGvnMV3DAxJTd3DrJkt519I8ps8nIvko2rqy1KLL5D2MMNVDf9WdKXxZLKxOr0SwGvnMV3DAxJTd3DrJkt519I8ps8nIvko2rqy1KLL5D2MMNVDf9WdKXxZLKxOr0SwGvnMV3DAxJTd3DrJkt519I8ps8nIvko2rqy1KLL5D2MMNVDf9WdKXxZLKxOr0SwGvnMV3DAxJTd3DrJkt519I8ps8nIvko2rqy1KLL5D2MMNVDf9WdKXxZLKxOr0SwGvnMV3DAxJTd3DrJkt519I8ps8nIvko
Running this command kills the bot with irc.client.MessageTooLong: Messages limited to 512 bytes including CR/LF
However this message is only 322 characters long:
msg = "!gline 2rqy1KLL5D2MMNVDf9WdKXxZLKxOr0SwGvnMV3DAxJTd3DrJkt519I8ps8nIvko2rqy1KLL5D2MMNVDf9WdKXxZLKxOr0SwGvnMV3DAxJTd3DrJkt519I8ps8nIvko2rqy1KLL5D2MMNVDf9WdKXxZLKxOr0SwGvnMV3DAxJTd3DrJkt519I8ps8nIvko2rqy1KLL5D2MMNVDf9WdKXxZLKxOr0SwGvnMV3DAxJTd3DrJkt519I8ps8nIvko2rqy1KLL5D2MMNVDf9WdKXxZLKxOr0SwGvnMV3DAxJTd3DrJkt519I8ps8nIvko"
print(len(msg))
# 322
def on_pubmsg(self, server: ServerConnection, event: Event) -> None:
"""
Public command handler
"""
# The person who invoked the command
invoker = event.source.nick
# Name of the channel where the command was invoked by the invoker
channel_name = event.target
# Channel object corresponding to the channel above channel name
channel_obj = self.channels[channel_name]
# The command (along with it's arguments)
message = event.arguments[0]
# This check doesn't actually protect me in this case, because the offending command is only 322 characters long
if len(message) >= 512:
server.notice(invoker, "Commands cannot be longer than 512 characters.")
return