From 2d113011ede449c36148a8622c82f912758a8870 Mon Sep 17 00:00:00 2001 From: jesopo Date: Sat, 26 Jan 2019 10:49:31 +0000 Subject: Add a setting to insert zero width characters in to highlights (github) --- modules/github/module.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'modules/github') diff --git a/modules/github/module.py b/modules/github/module.py index 4b80a152..9de3b144 100644 --- a/modules/github/module.py +++ b/modules/github/module.py @@ -69,6 +69,9 @@ COMMENT_ACTIONS = { "validate": utils.bool_or_none}) @utils.export("channelset", {"setting": "github-default-repo", "help": "Set the default github repo for the current channel"}) +@utils.export("channelset", {"setting": "github-prevent-highlight", + "help": "Enable/disable preventing highlights", + "validate": utils.bool_or_none}) class Module(ModuleManager.BaseModule): def _parse_ref(self, channel, ref): repo, _, number = ref.rpartition("#") @@ -327,6 +330,9 @@ class Module(ModuleManager.BaseModule): for output in outputs: source = full_name or organisation output = "(%s) %s" % (source, output) + if channel.get_setting("github-prevent-highlight", False): + self._prevent_highlight(channel, output) + self.events.on("send.stdout").call(target=channel, module_name="Github", server=server, message=output, hide_prefix=channel.get_setting( @@ -334,6 +340,18 @@ class Module(ModuleManager.BaseModule): return "" + def _prevent_highlight(self, channel, s): + for user in channel.users: + while user.nickname_lower in s.lower(): + index = s.lower().index(user.nickname_lower) + length = len(user.nickname_lower) + + original = s[index:index+length] + original = utils.prevent_highlight(original) + + s = s[:index] + original + s[index+length:] + return s + def _short_url(self, url): try: page = utils.http.request("https://git.io", method="POST", -- cgit v1.3.1-10-gc9f91