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?
|
* any interesting web service stuff?
|
||||||
* obligatory info command
|
* obligatory info command
|
||||||
* similar to FactFile module, a generic Trigger module
|
* similar to FactFile module, a generic Trigger module
|
||||||
* do splitting in DrBotServerConnection.privmsg
|
|
||||||
* settle on docstrings: http://www.python.org/dev/peps/pep-0257/
|
* 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
|
from ConfigParser import ConfigParser, NoSectionError, NoOptionError
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import socket
|
||||||
import sys
|
import sys
|
||||||
import inspect
|
import inspect
|
||||||
|
|
||||||
@ -34,8 +35,25 @@ class DrBotServerConnection(irclib.ServerConnection):
|
|||||||
|
|
||||||
def privmsg(self, target, text):
|
def privmsg(self, target, text):
|
||||||
# Send a PRIVMSG command.
|
# Send a PRIVMSG command.
|
||||||
# TODO: length limiting or splitting
|
splitter = "..."
|
||||||
self.send_raw("PRIVMSG %s :%s" % (target, text))
|
|
||||||
|
# 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.
|
# DrBotIRC subclasses irclib's IRC, in order to create a DrBotServerConnection.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user