diff --git a/slack/chat.py b/slack/chat.py index ecb14da..6a1ec70 100644 --- a/slack/chat.py +++ b/slack/chat.py @@ -25,10 +25,20 @@ def _text_parse_channel(text): res = re.sub("<#%s(.*?)>" % chid, "#%s" % name, res) return res +def _text_parse_links(text): + res = text + links = [] + for link in re.findall("<(.*?)>", text): + split = link.split("|") + msg = split[1] + " " if len(split) > 1 else "" + res = re.sub("<(.*?)>", "%s[#####]" % msg, res) + links += [ split[0] ] + return (res, links) + def _text_parse_tags(text): text = _text_parse_uid(text) text = _text_parse_channel(text) - return text + return _text_parse_links(text) @@ -44,10 +54,23 @@ class Message: def __str__(self): lines = [] + links = [] + count = 0 for line in self.__text: - line = _text_parse_tags(line) + line, link = _text_parse_tags(line) + while line.count("[#####]") > 0: + line = line.replace("[#####]", "[%s]" % count, 1) + count += 1 + lines += [ "" ] + textwrap.wrap(line) + links += link + text = "\n ".join(lines) + if len(links) > 0: + text += "\n __________" + for link in enumerate(links): + text += "\n [%s] %s" % (link[0], link[1]) + time = self.__time.strftime("%I:%M:%S %p") return "\n%s | %s:\n%s\n" % (time, self.__user, text)