diff options
author | Ben Kelly <bk@ancilla.ca> | 2017-04-15 08:43:37 -0400 |
---|---|---|
committer | Ben Kelly <btk@google.com> | 2017-04-15 08:44:28 -0400 |
commit | 56ae9127224662befbff55ef5240cb232775f050 (patch) | |
tree | f461d91f13e4fab04308010a3ce6f8debd73ccdd /wee_slack.py | |
parent | cc31591cdfa8b867ef4f42990b7191423ebccba6 (diff) | |
download | wee-slack-56ae9127224662befbff55ef5240cb232775f050.tar.gz |
Add italic support, and settings to switch between italic and underline
Signed-off-by: Ben Kelly <btk@google.com>
Signed-off-by: Ben Kelly <bk@ancilla.ca>
Diffstat (limited to 'wee_slack.py')
-rw-r--r-- | wee_slack.py | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/wee_slack.py b/wee_slack.py index 10e4882..f1f40bd 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -2231,9 +2231,13 @@ def render(message_json, team, channel, force=False): text = text.replace(">", ">") text = text.replace("&", "&") text = re.sub(r'(^| )\*([^*]+)\*([^a-zA-Z0-9_]|$)', - r'\1{}\2{}\3'.format(w.color('bold'), w.color('-bold')), text) + r'\1{}\2{}\3'.format(w.color(config.render_bold_as), + w.color('-' + config.render_bold_as)), + text) text = re.sub(r'(^| )_([^_]+)_([^a-zA-Z0-9_]|$)', - r'\1{}\2{}\3'.format(w.color('underline'), w.color('-underline')), text) + r'\1{}\2{}\3'.format(w.color(config.render_italic_as), + w.color('-' + config.render_italic_as)), + text) if type(text) is not unicode: text = text.decode('UTF-8', 'replace') @@ -2254,7 +2258,11 @@ def linkify_text(message, team, channel): # function is only called on message send.. usernames = team.get_username_map() channels = team.get_channel_map() - message = message.replace('\x02', '*').replace('\x1F', '_').split(' ') + message = (message + .replace('\x02', '*') + .replace('\x1D', '_') + .replace('\x1F', config.map_underline_to) + .split(' ')) for item in enumerate(message): targets = re.match('^\s*([@#])([\w.-]+[\w. -])(\W*)', item[1]) #print targets @@ -2923,6 +2931,9 @@ class PluginConfig(object): 'debug_mode': 'false', 'debug_level': '3', 'distracting_channels': '', + 'map_underline_to': '_', + 'render_bold_as': 'bold', + 'render_italic_as': 'italic', 'show_reaction_nicks': 'false', 'slack_api_token': 'INSERT VALID KEY HERE!', 'slack_timeout': '20000', @@ -2975,6 +2986,19 @@ class PluginConfig(object): def get_boolean(self, key): return w.config_string_to_boolean(w.config_get_plugin(key)) + def get_string(self, key): + return w.config_get_plugin(key) + + def get_int(self, key): + return int(w.config_get_plugin(key)) + + get_debug_level = get_int + get_map_underline_to = get_string + get_render_bold_as = get_string + get_render_italic_as = get_string + get_slack_timeout = get_int + get_thread_suffix_color = get_string + def get_distracting_channels(self, key): return [x.strip() for x in w.config_get_plugin(key).split(',')] @@ -2990,15 +3014,6 @@ class PluginConfig(object): else: return token - def get_thread_suffix_color(self, key): - return w.config_get_plugin("thread_suffix_color") - - def get_debug_level(self, key): - return int(w.config_get_plugin(key)) - - def get_slack_timeout(self, key): - return int(w.config_get_plugin(key)) - def migrate(self): """ This is to migrate the extension name from slack_extension to slack |