Added dictionaries command and changed the order of the arguments to the dict command; also added --fancy argument to last command.

This commit is contained in:
Jeremy Fincher 2003-09-05 04:28:56 +00:00
parent ea74e4e898
commit d43b1ea700
2 changed files with 33 additions and 12 deletions

View File

@ -156,12 +156,15 @@ example = utils.wrapLines("""
""") """)
class FunCommands(callbacks.Privmsg): class FunCommands(callbacks.Privmsg):
dictServer = 'dict.org'
def __init__(self): def __init__(self):
callbacks.Privmsg.__init__(self) callbacks.Privmsg.__init__(self)
self.sentMsgs = 0 self.sentMsgs = 0
self.recvdMsgs = 0 self.recvdMsgs = 0
self.sentBytes = 0 self.sentBytes = 0
self.recvdBytes = 0 self.recvdBytes = 0
conn = dictclient.Connection(self.dictServer)
self.dictdbs = sets.Set(conn.getdbdescs().iterkeys())
def inFilter(self, irc, msg): def inFilter(self, irc, msg):
self.recvdMsgs += 1 self.recvdMsgs += 1
@ -621,7 +624,7 @@ class FunCommands(callbacks.Privmsg):
irc.reply(msg, response) irc.reply(msg, response)
def last(self, irc, msg, args): def last(self, irc, msg, args):
"""[--{from,in,to,with,regexp}] <args> """[--{from,in,to,with,regexp,nodecorate}] <args>
Returns the last message matching the given criteria. --from requires Returns the last message matching the given criteria. --from requires
a nick from whom the message came; --in and --to require a channel the a nick from whom the message came; --in and --to require a channel the
@ -630,12 +633,15 @@ class FunCommands(callbacks.Privmsg):
""" """
(optlist, rest) = getopt.getopt(args, '', ['from=', 'in=', 'to=', (optlist, rest) = getopt.getopt(args, '', ['from=', 'in=', 'to=',
'with=', 'regexp=']) 'with=', 'regexp=',
undecorated = False 'fancy'])
fancy = False
predicates = [] predicates = []
for (option, arg) in optlist: for (option, arg) in optlist:
option = option.strip('-') option = option.strip('-')
if option == 'from': if option == 'fancy':
fancy = True
elif option == 'from':
predicates.append(lambda m, arg=arg: m.nick == arg) predicates.append(lambda m, arg=arg: m.nick == arg)
elif option == 'in' or option == 'to': elif option == 'in' or option == 'to':
if not ircutils.isChannel(arg): if not ircutils.isChannel(arg):
@ -662,10 +668,10 @@ class FunCommands(callbacks.Privmsg):
if not predicate(m): if not predicate(m):
break break
else: else:
if undecorated: if fancy:
irc.reply(msg, m.args[1])
else:
irc.reply(msg, ircmsgs.prettyPrint(m)) irc.reply(msg, ircmsgs.prettyPrint(m))
else:
irc.reply(msg, m.args[1])
return return
irc.error(msg, 'I couldn\'t find a message matching that criteria.') irc.error(msg, 'I couldn\'t find a message matching that criteria.')
@ -798,15 +804,24 @@ class FunCommands(callbacks.Privmsg):
irc.error(msg, 'Host not found.') irc.error(msg, 'Host not found.')
dns = privmsgs.thread(dns) dns = privmsgs.thread(dns)
def dictionaries(self, irc, msg, args):
"""takes no arguments.
Returns the dictionaries valid for the dict command.
"""
irc.reply(msg, utils.commaAndify(self.dictdbs))
def dict(self, irc, msg, args): def dict(self, irc, msg, args):
"""<word> [<dictionary>] """[<dictionary>] <word>
Looks up the definition of <word> on dict.org's dictd server. Looks up the definition of <word> on dict.org's dictd server.
""" """
(word, dictionary) = privmsgs.getArgs(args, optional=1) if args[0] in self.dictdbs:
if not dictionary: dictionary = args.pop(0)
else:
dictionary = '*' dictionary = '*'
conn = dictclient.Connection('dict.org') word = privmsgs.getArgs(args)
conn = dictclient.Connection(self.dictServer)
definitions = conn.define(dictionary, word) definitions = conn.define(dictionary, word)
dbs = sets.Set() dbs = sets.Set()
if not definitions: if not definitions:
@ -824,10 +839,12 @@ class FunCommands(callbacks.Privmsg):
ircutils.shrinkList(L, '; ') ircutils.shrinkList(L, '; ')
if not L: if not L:
irc.reply(msg, 'Chopped: %s' % originalFirst[:400]) irc.reply(msg, 'Chopped: %s' % originalFirst[:400])
else: elif dictionary == '*':
s = '%s responded, %s shown: %s' % \ s = '%s responded, %s shown: %s' % \
(utils.commaAndify(dbs), len(L), '; '.join(L)) (utils.commaAndify(dbs), len(L), '; '.join(L))
irc.reply(msg, s) irc.reply(msg, s)
else:
irc.reply('; '.join(L))
dict = privmsgs.thread(dict) dict = privmsgs.thread(dict)

View File

@ -101,6 +101,10 @@ class FunCommandsTest(PluginTestCase):
def testDict(self): def testDict(self):
self.assertNotError('dict slash') self.assertNotError('dict slash')
self.assertNotRegexp('dict web1913 slash', 'foldoc')
def testDictionaries(self):
self.assertNotError('dictionaries')