From bdec243909d043b7c963ec2c4a1fc59578e9b91f Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Mon, 18 Nov 2013 20:44:56 +0000 Subject: [PATCH 1/8] ChannelStats: Fix error when using @channelstats on a channel the bot did not join. --- plugins/ChannelStats/plugin.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/ChannelStats/plugin.py b/plugins/ChannelStats/plugin.py index 9e353a671..1ea05eacd 100644 --- a/plugins/ChannelStats/plugin.py +++ b/plugins/ChannelStats/plugin.py @@ -358,9 +358,11 @@ class ChannelStats(callbacks.Plugin): Returns the statistics for . is only necessary if the message isn't sent on the channel itself. """ - if msg.nick not in irc.state.channels[channel].users: - irc.error(format('You must be in %s to use this command.', channel)) - return + if channel not in irc.state.channels: + irc.error(_('I am not in %s.', channel), Raise=True) + elif msg.nick not in irc.state.channels[channel].users: + irc.error(_('You must be in %s to use this command.') % channel, + Raise=True) try: channeldb = conf.supybot.databases.plugins.channelSpecific. \ getChannelLink(channel) From 11d8f4655b38ee1a355ab0251d0b8ba1fa3ba01e Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Tue, 19 Nov 2013 10:16:43 +0000 Subject: [PATCH 2/8] Web: Display the target domain in snarfer. Re-implements pull request GH-523. --- plugins/Web/plugin.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/plugins/Web/plugin.py b/plugins/Web/plugin.py index cdcbbd7e7..ea6493195 100644 --- a/plugins/Web/plugin.py +++ b/plugins/Web/plugin.py @@ -131,11 +131,13 @@ class Web(callbacks.PluginRegexp): return try: size = conf.supybot.protocols.http.peekSize() - text = utils.web.getUrl(url, size=size) - except utils.web.Error, e: + fd = utils.web.getUrlFd(url) + text = fd.read(size) + fd.close() + except socket.timeout, e: self.log.info('Couldn\'t snarf title of %u: %s.', url, e) if self.registryValue('snarferReportIOExceptions', channel): - irc.reply(url+" : "+utils.web.strError(e), prefixNick=False) + irc.reply(url+" : "+utils.web.TIMED_OUT, prefixNick=False) return try: text = text.decode(utils.web.getEncoding(text) or 'utf8', @@ -149,7 +151,7 @@ class Web(callbacks.PluginRegexp): self.log.debug('Encountered a problem parsing %u. Title may ' 'already be set, though', url) if parser.title: - domain = utils.web.getDomain(url) + domain = utils.web.getDomain(fd.geturl()) title = utils.web.htmlToText(parser.title.strip()) if sys.version_info[0] < 3: if isinstance(title, unicode): From 289f614bfa9eebefe5e65df52fed13bcdd283074 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Tue, 19 Nov 2013 10:20:32 +0000 Subject: [PATCH 3/8] Web: Make choice of displayed domain (origin/target) configurable. --- plugins/Web/config.py | 4 ++++ plugins/Web/plugin.py | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/plugins/Web/config.py b/plugins/Web/config.py index 2e1ef1847..e27f0da29 100644 --- a/plugins/Web/config.py +++ b/plugins/Web/config.py @@ -52,6 +52,10 @@ conf.registerChannelValue(Web, 'titleSnarfer', conf.registerChannelValue(Web, 'snarferReportIOExceptions', registry.Boolean(False, _("""Determines whether the bot will notfiy the user about network exceptions like hostnotfound, timeout ...."""))) +conf.registerChannelValue(Web, 'snarferShowTargetDomain', + registry.Boolean(False, _("""Determines whether the domain name displayed + by the snarfer will be the original one (posted on IRC) or the target one + (got after following redirects, if any)."""))) conf.registerChannelValue(Web, 'nonSnarfingRegexp', registry.Regexp(None, _("""Determines what URLs matching the given regexp will not be snarfed. Give the empty string if you have no URLs that you'd diff --git a/plugins/Web/plugin.py b/plugins/Web/plugin.py index ea6493195..1337313dd 100644 --- a/plugins/Web/plugin.py +++ b/plugins/Web/plugin.py @@ -151,7 +151,9 @@ class Web(callbacks.PluginRegexp): self.log.debug('Encountered a problem parsing %u. Title may ' 'already be set, though', url) if parser.title: - domain = utils.web.getDomain(fd.geturl()) + domain = utils.web.getDomain(fd.geturl() + if self.registryValue('snarferShowTargetDomain', channel) + else url) title = utils.web.htmlToText(parser.title.strip()) if sys.version_info[0] < 3: if isinstance(title, unicode): From a0c5e06445208a9922ef843efd05be40b2970e34 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Tue, 19 Nov 2013 18:18:28 +0000 Subject: [PATCH 4/8] PluginDownloader: Add skgsergio's repository. --- plugins/PluginDownloader/plugin.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugins/PluginDownloader/plugin.py b/plugins/PluginDownloader/plugin.py index 1858f85fd..348238048 100644 --- a/plugins/PluginDownloader/plugin.py +++ b/plugins/PluginDownloader/plugin.py @@ -254,6 +254,10 @@ repositories = { 'Jonimoose', 'Supybot-plugins', ), + 'skgsergio': GithubRepository( + 'skgsergio', + 'Limnoria-plugins', + ), } class PluginDownloader(callbacks.Plugin): From b8abbd1e36067a29432176ae59775af0ee885a63 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Sun, 24 Nov 2013 14:47:26 +0000 Subject: [PATCH 5/8] Make dependency on python-dateutil optionnal. --- plugins/Time/plugin.py | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/plugins/Time/plugin.py b/plugins/Time/plugin.py index c796ecb4d..0053971b4 100644 --- a/plugins/Time/plugin.py +++ b/plugins/Time/plugin.py @@ -31,8 +31,6 @@ import time TIME = time # For later use. from datetime import datetime -from dateutil import parser - import supybot.conf as conf import supybot.utils as utils from supybot.commands import * @@ -40,20 +38,25 @@ import supybot.callbacks as callbacks from supybot.i18n import PluginInternationalization, internationalizeDocstring _ = PluginInternationalization('Time') -def parse(s): - todo = [] - s = s.replace('noon', '12:00') - s = s.replace('midnight', '00:00') - if 'tomorrow' in s: - todo.append(lambda i: i + 86400) - s = s.replace('tomorrow', '') - if 'next week' in s: - todo.append(lambda i: i + 86400*7) - s = s.replace('next week', '') - i = int(time.mktime(parser.parse(s, fuzzy=True).timetuple())) - for f in todo: - i = f(i) - return i + +try: + from dateutil import parser + def parse(s): + todo = [] + s = s.replace('noon', '12:00') + s = s.replace('midnight', '00:00') + if 'tomorrow' in s: + todo.append(lambda i: i + 86400) + s = s.replace('tomorrow', '') + if 'next week' in s: + todo.append(lambda i: i + 86400*7) + s = s.replace('next week', '') + i = int(time.mktime(parser.parse(s, fuzzy=True).timetuple())) + for f in todo: + i = f(i) + return i +except ImportError: + parse = None class Time(callbacks.Plugin): @internationalizeDocstring @@ -99,6 +102,9 @@ class Time(callbacks.Plugin):