From cdbf7932e1f05e98f149aeeb81e8d2034d81e1e5 Mon Sep 17 00:00:00 2001 From: butterscotchstallion Date: Sat, 17 Oct 2015 20:41:33 -0400 Subject: [PATCH] Fixes #65 - Adds "ignoreActionLinks" configuration option, which allows users to specify whether links that appear within actions are ignored. False by default. --- README.md | 8 +++++--- __init__.py | 2 +- config.py | 5 +++-- plugin.py | 23 ++++++++++++++++++++--- test.py | 2 +- 5 files changed, 30 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 72c5ba3..88a6ce9 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ The ONLY gluten-free plugin for displaying link titles. Check out the [available options](#available-options)! ## Install SpiffyTitles -- `git clone https://github.com/prgmrbill/limnoria-plugins.git` +- `git clone https://github.com/butterscotchstallion/limnoria-plugins.git` - `cd limnoria-plugins` - `cp -r SpiffyTitles ~/your_bot_directory/plugins` - `cd ~/your_bot_directory/plugins/SpiffyTitles` @@ -128,7 +128,7 @@ Example output: - If there is a problem reaching the API the default handler will be used as a fallback. See logs for details. - The API seems to report information on the originally uploaded image and not other formats - If you see something from [the imgur api](https://api.imgur.com/models/image) that you want and is not available -in the above example, [please open an issue!](https://github.com/prgmrbill/limnoria-plugins/issues/new) +in the above example, [please open an issue!](https://github.com/butterscotchstallion/limnoria-plugins/issues/new) ### coub handler @@ -227,6 +227,8 @@ Example: `!config supybot.plugins.SpiffyTitles.linkMessageIgnorePattern "/\[tw\] This would ignore any message that contains "[tw]". +`ignoreActionLinks` (Boolean) - By default SpiffyTitles will ignore links that appear in an action, like `/me`. + ### FAQ Q: I have a question. Where can I get help? @@ -248,7 +250,7 @@ A: I couldn't get this to work on my system and it has a lot of features I didn' Q: It doesn't work for me. What can I do? -A: [Open an issue](https://github.com/prgmrbill/limnoria-plugins/issues/new) and include at minimum the following: +A: [Open an issue](https://github.com/butterscotchstallion/limnoria-plugins/issues/new) and include at minimum the following: - Brief description of the problem - Any errors that were logged (Look for the ones prefixed "SpiffyTitles") diff --git a/__init__.py b/__init__.py index a287601..fae59f7 100644 --- a/__init__.py +++ b/__init__.py @@ -1,5 +1,5 @@ ### -# Copyright (c) 2015, PrgmrBill +# Copyright (c) 2015, butterscotchstallion # All rights reserved. # # diff --git a/config.py b/config.py index 349b619..3970a91 100644 --- a/config.py +++ b/config.py @@ -1,5 +1,5 @@ ### -# Copyright (c) 2015, PrgmrBill +# Copyright (c) 2015, butterscotchstallion # All rights reserved. # # @@ -141,7 +141,8 @@ conf.registerGlobalValue(SpiffyTitles, 'onDemandTitleError', conf.registerGlobalValue(SpiffyTitles, 'linkMessageIgnorePattern', registry.Regexp("", _("""Messages matching this pattern will be ignored."""))) - +conf.registerGlobalValue(SpiffyTitles, 'ignoreActionLinks', + registry.Boolean(True, _("""Ignores URLs that appear in an action such as /me"""))) diff --git a/plugin.py b/plugin.py index 4c5aecd..befabfd 100644 --- a/plugin.py +++ b/plugin.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ### -# Copyright (c) 2015, PrgmrBill +# Copyright (c) 2015, butterscotchstallion # All rights reserved. # # @@ -27,6 +27,7 @@ import datetime from jinja2 import Template from datetime import timedelta import timeout_decorator +import unicodedata try: from supybot.i18n import PluginInternationalization @@ -273,6 +274,7 @@ class SpiffyTitles(callbacks.Plugin): """ Observe each channel message and look for links """ + ignore_actions = self.registryValue("ignoreActionLinks") channel = msg.args[0].lower() is_channel = irc.isChannel(channel) is_ctcp = ircmsgs.isCtcp(msg) @@ -282,11 +284,20 @@ class SpiffyTitles(callbacks.Plugin): origin_nick = msg.nick is_message_from_self = origin_nick.lower() == bot_nick.lower() - if is_channel and not is_ctcp and not is_message_from_self: + """ + Configuration option determines whether we should + ignore links that appear within an action + """ + if is_ctcp and ignore_actions: + return + + if is_channel and not is_message_from_self: channel_is_allowed = self.is_channel_allowed(channel) url = self.get_url_from_message(message) ignore_match = self.message_matches_ignore_pattern(message) + self.log.info("SpiffyTitles: URL=%s" % url) + if ignore_match: self.log.info("SpiffyTitles: ignoring message due to linkMessagePattern match") return @@ -1035,8 +1046,14 @@ class SpiffyTitles(callbacks.Plugin): match = re.search(url_re, input) if match: - return match.group(0).strip() + raw_url = match.group(0).strip() + url = self.remove_control_characters(unicode(raw_url)) + + return url + def remove_control_characters(self, s): + return "".join(ch for ch in s if unicodedata.category(ch)[0]!="C") + Class = SpiffyTitles # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: diff --git a/test.py b/test.py index a74745e..1edcc94 100644 --- a/test.py +++ b/test.py @@ -1,5 +1,5 @@ ### -# Copyright (c) 2015, PrgmrBill +# Copyright (c) 2015, butterscotchstallion # All rights reserved. # #