Uses commands.wrap now.

This commit is contained in:
Jeremy Fincher 2004-10-02 05:37:00 +00:00
parent dc55a330fa
commit 9298888353
1 changed files with 14 additions and 19 deletions

View File

@ -37,13 +37,7 @@ __revision__ = "$Id$"
import supybot.plugins as plugins import supybot.plugins as plugins
import os
import re import re
import sets
import time
import getopt
import urlparse
import itertools
import supybot.dbi as dbi import supybot.dbi as dbi
import supybot.conf as conf import supybot.conf as conf
@ -52,7 +46,6 @@ from supybot.commands import wrap
import supybot.ircmsgs as ircmsgs import supybot.ircmsgs as ircmsgs
import supybot.ircutils as ircutils import supybot.ircutils as ircutils
import supybot.webutils as webutils import supybot.webutils as webutils
import supybot.privmsgs as privmsgs
import supybot.registry as registry import supybot.registry as registry
import supybot.callbacks as callbacks import supybot.callbacks as callbacks
@ -148,19 +141,19 @@ class URL(callbacks.PrivmsgCommandAndRegexp):
irc.reply(s, prefixName=False) irc.reply(s, prefixName=False)
titleSnarfer = wrap(titleSnarfer, decorators=['urlSnarfer']) titleSnarfer = wrap(titleSnarfer, decorators=['urlSnarfer'])
def stats(self, irc, msg, args): def stats(self, irc, msg, args, channel):
"""[<channel>] """[<channel>]
Returns the number of URLs in the URL database. <channel> is only Returns the number of URLs in the URL database. <channel> is only
required if the message isn't sent in the channel itself. required if the message isn't sent in the channel itself.
""" """
channel = privmsgs.getChannel(msg, args)
self.db.vacuum(channel) self.db.vacuum(channel)
count = self.db.size(channel) count = self.db.size(channel)
irc.reply('I have %s in my database.' % utils.nItems('URL', count)) irc.reply('I have %s in my database.' % utils.nItems('URL', count))
stats = wrap(stats, ['channeldb'])
def last(self, irc, msg, args): def last(self, irc, msg, args, optlist, channel):
"""[<channel>] [--{from,with,near,proto}=<value>] --{nolimit} """[<channel>] [--{from,with,near,proto}=<value>] --nolimit
Gives the last URL matching the given criteria. --from is from whom Gives the last URL matching the given criteria. --from is from whom
the URL came; --proto is the protocol the URL used; --with is something the URL came; --proto is the protocol the URL used; --with is something
@ -169,25 +162,22 @@ class URL(callbacks.PrivmsgCommandAndRegexp):
URL. <channel> is only necessary if the message isn't sent in the URL. <channel> is only necessary if the message isn't sent in the
channel itself. channel itself.
""" """
channel = privmsgs.getChannel(msg, args)
(optlist, rest) = getopt.getopt(args, '', ['from=', 'with=', 'near=',
'proto=', 'nolimit',])
predicates = [] predicates = []
f = None f = None
nolimit = False nolimit = False
for (option, arg) in optlist: for (option, arg) in optlist:
if option == '--nolimit': if option == 'nolimit':
nolimit = True nolimit = True
elif option == '--from': elif option == 'from':
def f(record, arg=arg): def f(record, arg=arg):
return ircutils.strEqual(record.by, arg) return ircutils.strEqual(record.by, arg)
elif option == '--with': elif option == 'with':
def f(record, arg=arg): def f(record, arg=arg):
return arg in record.url return arg in record.url
elif option == '--proto': elif option == 'proto':
def f(record, arg=arg): def f(record, arg=arg):
return record.url.startswith(arg) return record.url.startswith(arg)
elif option == '--near': elif option == 'near':
def f(record, arg=arg): def f(record, arg=arg):
return arg in record.near return arg in record.near
if f is not None: if f is not None:
@ -208,6 +198,11 @@ class URL(callbacks.PrivmsgCommandAndRegexp):
# We should optimize this with another URLDB method eventually. # We should optimize this with another URLDB method eventually.
s = urls[0] s = urls[0]
irc.reply(s) irc.reply(s)
last = wrap(last, ['channeldb'], getopts={'from': 'text',
'with': 'text',
'near': 'text',
'proto': 'text',
'nolimit': '',})
Class = URL Class = URL