Made sure no messages longer than 512 bytes every leave the bot.

This commit is contained in:
Jeremy Fincher 2003-10-23 05:53:49 +00:00
parent 7bf41499cb
commit 10c7b7c0c0
2 changed files with 13 additions and 0 deletions

View File

@ -488,6 +488,9 @@ class Irc(IrcCommandDispatcher):
s = '%s.outFilter returned None' % callback.name() s = '%s.outFilter returned None' % callback.name()
debug.msg(s) debug.msg(s)
return None return None
if len(str(msg)) > 512:
msg._str = msg._str[:500] + '\r\n'
msg._len = len(str(msg))
self.state.addMsg(self, msg) self.state.addMsg(self, msg)
s = '%s %s' % (time.strftime(conf.logTimestampFormat), msg) s = '%s %s' % (time.strftime(conf.logTimestampFormat), msg)
debug.msg(s, 'low') debug.msg(s, 'low')
@ -524,6 +527,11 @@ class Irc(IrcCommandDispatcher):
if hasattr(self.driver, 'scheduleReconnect'): if hasattr(self.driver, 'scheduleReconnect'):
self.driver.scheduleReconnect() self.driver.scheduleReconnect()
self.driver.die() self.driver.die()
elif 'too fast' in msg.args[0]:
if hasattr(self.driver, 'reconnectWaitsIndex'):
newIndex = len(self.driver.reconnectWaits)-1
self.driver.reconnectWaitsIndex = newIndex
self.driver.die()
def doNick(self, msg): def doNick(self, msg):
"""Handles NICK messages.""" """Handles NICK messages."""

View File

@ -301,6 +301,11 @@ class IrcTestCase(unittest.TestCase):
msg = self.irc.takeMsg() msg = self.irc.takeMsg()
self.failUnless(msg.command == 'NOTICE') self.failUnless(msg.command == 'NOTICE')
def testNoMsgLongerThan512(self):
self.irc.queueMsg(ircmsgs.privmsg('whocares', 'x'*1000))
msg = self.irc.takeMsg()
self.failUnless(len(msg) <= 512, 'len(msg) was %s' % len(msg))
def testReset(self): def testReset(self):
for msg in msgs: for msg in msgs:
try: try: