Fix IRC message pretty-printer
This commit is contained in:
parent
020759fdab
commit
981025610e
@ -22,7 +22,6 @@ import re
|
|||||||
import time
|
import time
|
||||||
import shlex
|
import shlex
|
||||||
|
|
||||||
import bot
|
|
||||||
from channel import Channel
|
from channel import Channel
|
||||||
from message import Message
|
from message import Message
|
||||||
import server
|
import server
|
||||||
@ -83,6 +82,8 @@ class IRCServer(SocketServer):
|
|||||||
self.logger.error("DCC: unable to connect to %s:%d", ip, port)
|
self.logger.error("DCC: unable to connect to %s:%d", ip, port)
|
||||||
return _ctcp_response("ERRMSG unable to connect to %s:%d" % (ip, port))
|
return _ctcp_response("ERRMSG unable to connect to %s:%d" % (ip, port))
|
||||||
|
|
||||||
|
import bot
|
||||||
|
|
||||||
self.ctcp_capabilities["ACTION"] = lambda msg: print ("ACTION receive: %s" % msg.text)
|
self.ctcp_capabilities["ACTION"] = lambda msg: print ("ACTION receive: %s" % msg.text)
|
||||||
self.ctcp_capabilities["CLIENTINFO"] = _ctcp_clientinfo
|
self.ctcp_capabilities["CLIENTINFO"] = _ctcp_clientinfo
|
||||||
#self.ctcp_capabilities["DCC"] = _ctcp_dcc
|
#self.ctcp_capabilities["DCC"] = _ctcp_dcc
|
||||||
@ -316,7 +317,13 @@ class IRCMessage:
|
|||||||
return Message(self)
|
return Message(self)
|
||||||
|
|
||||||
def to_irc_string(self, client=True):
|
def to_irc_string(self, client=True):
|
||||||
res = ";".join(["@%s=%s" % (k,v) for k, v in self.tags.items()])
|
"""Pretty print the message to close to original input string
|
||||||
|
|
||||||
|
Keyword argument:
|
||||||
|
client -- export as a client-side string if true
|
||||||
|
"""
|
||||||
|
|
||||||
|
res = ";".join(["@%s=%s" % (k,v if not isinstance(v, datetime) else v.strftime("%Y-%m-%dT%H:%M:%S.%fZ")) for k, v in self.tags.items()])
|
||||||
|
|
||||||
if not client: res += " :%s!%s@%s" % (self.nick, self.user, self.host)
|
if not client: res += " :%s!%s@%s" % (self.nick, self.user, self.host)
|
||||||
|
|
||||||
@ -325,7 +332,7 @@ class IRCMessage:
|
|||||||
if len(self.params) > 0:
|
if len(self.params) > 0:
|
||||||
|
|
||||||
if len(self.params) > 1:
|
if len(self.params) > 1:
|
||||||
res += " " + " ".join(self.params[:-1])
|
res += " " + self.decode(b" ".join(self.params[:-1]))
|
||||||
res += " :" + self.params[-1]
|
res += " :" + self.decode(self.params[-1])
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
Loading…
x
Reference in New Issue
Block a user