aboutsummaryrefslogtreecommitdiffstats
path: root/wee_slack.py
diff options
context:
space:
mode:
Diffstat (limited to 'wee_slack.py')
-rw-r--r--wee_slack.py30
1 files changed, 16 insertions, 14 deletions
diff --git a/wee_slack.py b/wee_slack.py
index b5714f7..33a9c11 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -1615,11 +1615,12 @@ class SlackChannelCommon(object):
self.print_getting_history()
def send_message(self, message, subtype=None, request_dict_ext={}):
- message = linkify_text(message, self.team)
if subtype == 'me_message':
+ message = linkify_text(message, self.team, escape_characters=False)
s = SlackRequest(self.team, "chat.meMessage", {"channel": self.identifier, "text": message}, channel=self)
self.eventrouter.receive(s)
else:
+ message = linkify_text(message, self.team)
request = {"type": "message", "channel": self.identifier,
"text": message, "user": self.team.myidentifier}
request.update(request_dict_ext)
@@ -3643,23 +3644,24 @@ def render_formatting(text):
return text
-def linkify_text(message, team, only_users=False):
+def linkify_text(message, team, only_users=False, escape_characters=True):
# The get_username_map function is a bit heavy, but this whole
# function is only called on message send..
usernames = team.get_username_map()
channels = team.get_channel_map()
usergroups = team.generate_usergroup_map()
- message_escaped = (message
- # Replace IRC formatting chars with Slack formatting chars.
- .replace('\x02', '*')
- .replace('\x1D', '_')
- .replace('\x1F', config.map_underline_to)
- # Escape chars that have special meaning to Slack. Note that we do not
- # (and should not) perform full HTML entity-encoding here.
- # See https://api.slack.com/docs/message-formatting for details.
- .replace('&', '&')
- .replace('<', '&lt;')
- .replace('>', '&gt;'))
+ if escape_characters:
+ message = (message
+ # Replace IRC formatting chars with Slack formatting chars.
+ .replace('\x02', '*')
+ .replace('\x1D', '_')
+ .replace('\x1F', config.map_underline_to)
+ # Escape chars that have special meaning to Slack. Note that we do not
+ # (and should not) perform full HTML entity-encoding here.
+ # See https://api.slack.com/docs/message-formatting for details.
+ .replace('&', '&amp;')
+ .replace('<', '&lt;')
+ .replace('>', '&gt;'))
def linkify_word(match):
word = match.group(0)
@@ -3677,7 +3679,7 @@ def linkify_text(message, team, only_users=False):
return word
linkify_regex = r'(?:^|(?<=\s))([@#])([\w\(\)\'.-]+)'
- return re.sub(linkify_regex, linkify_word, message_escaped, flags=re.UNICODE)
+ return re.sub(linkify_regex, linkify_word, message, flags=re.UNICODE)
def unfurl_blocks(blocks):