Fixes #65 - Adds "ignoreActionLinks" configuration option, which allows users to

specify whether links that appear within actions are ignored. False by default.
This commit is contained in:
butterscotchstallion 2015-10-17 20:41:33 -04:00
parent e13bc6b8fa
commit cdbf7932e1
5 changed files with 30 additions and 10 deletions

View File

@ -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")

View File

@ -1,5 +1,5 @@
###
# Copyright (c) 2015, PrgmrBill
# Copyright (c) 2015, butterscotchstallion
# All rights reserved.
#
#

View File

@ -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""")))

View File

@ -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:

View File

@ -1,5 +1,5 @@
###
# Copyright (c) 2015, PrgmrBill
# Copyright (c) 2015, butterscotchstallion
# All rights reserved.
#
#