Added the Web.fetch command.

This commit is contained in:
Jeremy Fincher 2005-03-14 02:44:55 +00:00
parent c598e4cca9
commit 7e441285c7
2 changed files with 20 additions and 2 deletions

View File

@ -53,4 +53,9 @@ conf.registerChannelValue(Web, 'nonSnarfingRegexp',
snarfed. Give the empty string if you have no URLs that you'd like to snarfed. Give the empty string if you have no URLs that you'd like to
exclude from being snarfed.""")) 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 # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78

View File

@ -38,8 +38,8 @@ import supybot.callbacks as callbacks
class Web(callbacks.PluginRegexp): class Web(callbacks.PluginRegexp):
"""Add the help for "@help Web" here.""" """Add the help for "@help Web" here."""
regexps = ['titleSnarfer']
threaded = True threaded = True
regexps = ['titleSnarfer']
def callCommand(self, command, irc, msg, *args, **kwargs): def callCommand(self, command, irc, msg, *args, **kwargs):
try: try:
super(Web, self).callCommand(command, irc, msg, *args, **kwargs) super(Web, self).callCommand(command, irc, msg, *args, **kwargs)
@ -184,9 +184,22 @@ class Web(callbacks.PluginRegexp):
irc.reply(s) irc.reply(s)
urlunquote = wrap(urlunquote, ['text']) urlunquote = wrap(urlunquote, ['text'])
def fetch(self, irc, msg, args, url):
"""<url>
Returns the contents of <url>, 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 Class = Web
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: