99
1010log = logging .getLogger (__name__ )
1111
12+ # The maximum length of a message on IRC. This is different per network,
13+ # but 400 seems like a safe value for most modern IRC networks.
14+ IRC_MAX_LINE_LENGTH = 400
15+
1216
1317class RelayDiscord (discord .Client ):
1418 def __init__ (self , channel_id ):
@@ -123,8 +127,13 @@ def find_emojis(content):
123127 content = content .replace ("\r \n " , "\n " ).replace ("\r " , "\n " ).strip ()
124128
125129 # On Discord text between _ and _ is what IRC calls an action.
126- # IRC allows messages of ~470 characters, so if the action is longer, make it a multi-line message instead.
127- if content .startswith ("_" ) and content .endswith ("_" ) and "\n " not in content and len (content ) < 470 :
130+ # IRC has a limit on message size; if reached, make the action multi-line too.
131+ if (
132+ content .startswith ("_" )
133+ and content .endswith ("_" )
134+ and "\n " not in content
135+ and len (content ) < IRC_MAX_LINE_LENGTH
136+ ):
128137 relay .IRC .send_action (message .author .id , message .author .name , content [1 :- 1 ])
129138 else :
130139 for full_line in content .split ("\n " ):
@@ -133,8 +142,8 @@ def find_emojis(content):
133142 if full_line == "```" :
134143 continue
135144
136- # Split the message in lines of at most 470 characters, breaking on words.
137- for line in textwrap .wrap (full_line .strip (), 470 ):
145+ # Split the message in lines of at most IRC_MAX_LINE_LENGTH characters, breaking on words.
146+ for line in textwrap .wrap (full_line .strip (), IRC_MAX_LINE_LENGTH ):
138147 relay .IRC .send_message (message .author .id , message .author .name , line )
139148
140149 async def on_presence_update (self , before , after ):
0 commit comments