Split IRC message if they are long.
IRC has a 512 byte maximum message size that includes the privmsg and destination data. Use textwrap at 400 characters to approximate proper splitting of long IRC messages to avoid exceptions that occur when sending more than 512 bytes. Change-Id: I575ce3694f4b399a3adf5432f6f6971307d9e202
This commit is contained in:
parent
e4d9b16339
commit
8aedf19c83
@ -43,6 +43,7 @@ import daemon
|
|||||||
import logging
|
import logging
|
||||||
import logging.config
|
import logging.config
|
||||||
import os
|
import os
|
||||||
|
import textwrap
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
import yaml
|
import yaml
|
||||||
@ -94,7 +95,10 @@ class RecheckWatchBot(irc.bot.SingleServerIRCBot):
|
|||||||
|
|
||||||
def send(self, channel, msg):
|
def send(self, channel, msg):
|
||||||
self.log.info('Sending "%s" to %s' % (msg, channel))
|
self.log.info('Sending "%s" to %s' % (msg, channel))
|
||||||
self.connection.privmsg(channel, msg)
|
# Cheap way to attempt to send fewer than 512 bytes at a time.
|
||||||
|
# TODO(clarkb) calculate actual irc overhead and split properly.
|
||||||
|
for chunk in textwrap.wrap(msg, 400):
|
||||||
|
self.connection.privmsg(channel, chunk)
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user