From dda4d61421ad274f6e29a569fd674dd0ac933f3f Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Fri, 20 Feb 2004 05:33:12 +0000 Subject: [PATCH] Added the stuff needed for channel karma. --- plugins/Utilities.py | 19 ++++++++++++++++++ src/Channel.py | 12 +++++++++++ src/Owner.py | 48 +++++++++++++++++++++++--------------------- 3 files changed, 56 insertions(+), 23 deletions(-) diff --git a/plugins/Utilities.py b/plugins/Utilities.py index 8d0cfbf0f..865e60cb0 100644 --- a/plugins/Utilities.py +++ b/plugins/Utilities.py @@ -158,6 +158,25 @@ class Utilities(callbacks.Privmsg): irc.reply(f(text)) re = privmsgs.checkCapability(re, 'trusted') + def apply(self, irc, msg, args): + """ + + Tokenizes and calls with the resulting arguments. + """ + if not args: + raise callbacks.ArgumentError + command = args.pop(0) + args = [token and token or '""' for token in args] + text = privmsgs.getArgs(args) + commands = command.split() + commands = map(callbacks.canonicalName, commands) + tokens = callbacks.tokenize(text) + allTokens = commands + tokens + print '***', allTokens + Owner = irc.getCallback('Owner') + Owner.processTokens(irc, msg, allTokens) + + Class = Utilities # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: diff --git a/src/Channel.py b/src/Channel.py index d267e6fa5..ed9d9980d 100755 --- a/src/Channel.py +++ b/src/Channel.py @@ -549,6 +549,18 @@ class Channel(callbacks.Privmsg): irc.reply(s) else: irc.reply('I\'m not currently lobotomized in any channels.') + + def nicks(self, irc, msg, args): + """[] + + Returns the nicks in . is only necessary if the + message isn't sent in the channel itself. + """ + channel = privmsgs.getChannel(msg, args) + L = list(irc.state.channels[channel].users) + utils.sortBy(str.lower, L) + irc.reply(utils.commaAndify(L)) + Class = Channel diff --git a/src/Owner.py b/src/Owner.py index 4e833c645..992032ea7 100644 --- a/src/Owner.py +++ b/src/Owner.py @@ -233,6 +233,30 @@ class Owner(privmsgs.CapabilityCheckingPrivmsg): self.disambiguate(irc, elt, ambiguousCommands) return ambiguousCommands + def processTokens(self, irc, msg, tokens): + ambiguousCommands = self.disambiguate(irc, tokens) + if ambiguousCommands: + if len(ambiguousCommands) == 1: # Common case. + (command, names) = ambiguousCommands.popitem() + names.sort() + s = 'The command %r is available in the %s plugins. ' \ + 'Please specify the plugin whose command you ' \ + 'wish to call by using its name as a command ' \ + 'before calling it.' % \ + (command, utils.commaAndify(names)) + else: + L = [] + for (command, names) in ambiguousCommands.iteritems(): + names.sort() + L.append('The command %r is available in the %s ' + 'plugins' % + (command, utils.commaAndify(names))) + s = '%s; please specify from which plugins to ' \ + 'call these commands.' % '; '.join(L) + irc.queueMsg(callbacks.error(msg, s)) + else: + callbacks.IrcObjectProxy(irc, msg, tokens) + def doPrivmsg(self, irc, msg): callbacks.Privmsg.handled = False callbacks.Privmsg.errored = False @@ -247,33 +271,11 @@ class Owner(privmsgs.CapabilityCheckingPrivmsg): 'of a nested command.' irc.queueMsg(callbacks.error(msg, s)) return + self.processTokens(irc, msg, tokens) except SyntaxError, e: callbacks.Privmsg.errored = True irc.queueMsg(callbacks.error(msg, str(e))) return - ambiguousCommands = {} - self.disambiguate(irc, tokens, ambiguousCommands) - if ambiguousCommands: - if len(ambiguousCommands) == 1: # Common case. - (command, names) = ambiguousCommands.popitem() - names.sort() - s = 'The command %r is available in the %s plugins. ' \ - 'Please specify the plugin whose command you ' \ - 'wish to call by using its name as a command ' \ - 'before calling it.' % \ - (command, utils.commaAndify(names)) - else: - L = [] - for (command, names) in ambiguousCommands.iteritems(): - names.sort() - L.append('The command %r is available in the %s ' - 'plugins' % - (command, utils.commaAndify(names))) - s = '%s; please specify from which plugins to ' \ - 'call these commands.' % '; '.join(L) - irc.queueMsg(callbacks.error(msg, s)) - else: - callbacks.IrcObjectProxy(irc, msg, tokens) if conf.allowEval: def eval(self, irc, msg, args):