From c8c40f168216cd5820361d192db60807700d1807 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Wed, 16 Nov 2016 10:34:37 -0500 Subject: [PATCH] Parse channel tags to make them easier to read Signed-off-by: Anna Schumaker --- slack/chat.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/slack/chat.py b/slack/chat.py index 26cb528..ecb14da 100644 --- a/slack/chat.py +++ b/slack/chat.py @@ -18,6 +18,18 @@ def _text_parse_uid(text): res = re.sub("<@%s(.*?)>" % uid, "@%s" % user.user(), res) return res +def _text_parse_channel(text): + res = text + for channel in re.findall("<#(.*?)>", text): + (chid, name) = channel.split("|") + res = re.sub("<#%s(.*?)>" % chid, "#%s" % name, res) + return res + +def _text_parse_tags(text): + text = _text_parse_uid(text) + text = _text_parse_channel(text) + return text + class Message: @@ -33,7 +45,7 @@ class Message: def __str__(self): lines = [] for line in self.__text: - line = _text_parse_uid(line) + line = _text_parse_tags(line) lines += [ "" ] + textwrap.wrap(line) text = "\n ".join(lines) time = self.__time.strftime("%I:%M:%S %p")