From 7e441285c75e019ca89b068893b70804e83cac45 Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Mon, 14 Mar 2005 02:44:55 +0000 Subject: [PATCH] Added the Web.fetch command. --- plugins/Web/config.py | 5 +++++ plugins/Web/plugin.py | 17 +++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/plugins/Web/config.py b/plugins/Web/config.py index a2723e53d..93782e434 100644 --- a/plugins/Web/config.py +++ b/plugins/Web/config.py @@ -53,4 +53,9 @@ conf.registerChannelValue(Web, 'nonSnarfingRegexp', snarfed. Give the empty string if you have no URLs that you'd like to exclude from being snarfed.""")) +conf.registerGroup(Web, 'fetch') +conf.registerGlobalValue(Web.fetch, 'maximum', + registry.NonNegativeInteger(0, """Determines the maximum number of + bytes the bot will download via the 'fetch' command in this plugin.""")) + # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78 diff --git a/plugins/Web/plugin.py b/plugins/Web/plugin.py index 983fded2b..11fd12644 100644 --- a/plugins/Web/plugin.py +++ b/plugins/Web/plugin.py @@ -38,8 +38,8 @@ import supybot.callbacks as callbacks class Web(callbacks.PluginRegexp): """Add the help for "@help Web" here.""" - regexps = ['titleSnarfer'] threaded = True + regexps = ['titleSnarfer'] def callCommand(self, command, irc, msg, *args, **kwargs): try: super(Web, self).callCommand(command, irc, msg, *args, **kwargs) @@ -184,9 +184,22 @@ class Web(callbacks.PluginRegexp): irc.reply(s) urlunquote = wrap(urlunquote, ['text']) + def fetch(self, irc, msg, args, url): + """ + Returns the contents of , or as much as is configured in + supybot.plugins.Web.fetch.maximum. If that configuration variable is + set to 0, this command will be effectively disabled. + """ + max = self.registryValue('fetch.maximum') + if not max: + irc.error('This command is disabled ' + '(supybot.plugins.Web.fetch.maximum is set to 0).', + Raise=True) + fd = utils.web.getUrlFd(url) + irc.reply(fd.read(max)) + fetch = wrap(fetch, ['url']) Class = Web - # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: