do splitting in DrBotServerConnection.privmsg
This commit is contained in:
parent
cfc2923356
commit
e1fe0eb4ca
1
TODO
1
TODO
|
@ -18,5 +18,4 @@ dr.botzo --- TODO
|
|||
* any interesting web service stuff?
|
||||
* obligatory info command
|
||||
* similar to FactFile module, a generic Trigger module
|
||||
* do splitting in DrBotServerConnection.privmsg
|
||||
* settle on docstrings: http://www.python.org/dev/peps/pep-0257/
|
||||
|
|
22
dr.botzo.py
22
dr.botzo.py
|
@ -17,6 +17,7 @@
|
|||
from ConfigParser import ConfigParser, NoSectionError, NoOptionError
|
||||
import os
|
||||
import re
|
||||
import socket
|
||||
import sys
|
||||
import inspect
|
||||
|
||||
|
@ -34,8 +35,25 @@ class DrBotServerConnection(irclib.ServerConnection):
|
|||
|
||||
def privmsg(self, target, text):
|
||||
# Send a PRIVMSG command.
|
||||
# TODO: length limiting or splitting
|
||||
self.send_raw("PRIVMSG %s :%s" % (target, text))
|
||||
splitter = "..."
|
||||
|
||||
# split messages that are too long. Max length is 512.
|
||||
# TODO: this does not properly handle when the hostname has been
|
||||
# masked by the ircd
|
||||
space = 512 - len('\r\n') - len('PRIVMSG ') - len(' :') - len(target) - len(self.nickname) - len('!') - len(self.username) - len('@') - len(socket.getfqdn())
|
||||
splitspace = space - (len(splitter) + 1)
|
||||
|
||||
if len(text) > space:
|
||||
while len(text) > splitspace:
|
||||
splitpos = text.rfind(' ', 0, splitspace)
|
||||
splittext = text[0:splitpos] + ' ' + splitter
|
||||
text = splitter + ' ' + text[splitpos+1:]
|
||||
self.send_raw("PRIVMSG %s :%s" % (target, splittext))
|
||||
|
||||
# done splitting
|
||||
self.send_raw("PRIVMSG %s :%s" % (target, text))
|
||||
else:
|
||||
self.send_raw("PRIVMSG %s :%s" % (target, text))
|
||||
|
||||
# DrBotIRC subclasses irclib's IRC, in order to create a DrBotServerConnection.
|
||||
|
||||
|
|
Loading…
Reference in New Issue