Added the stuff needed for channel karma.

This commit is contained in:
Jeremy Fincher 2004-02-20 05:33:12 +00:00
parent d9a4a6da36
commit dda4d61421
3 changed files with 56 additions and 23 deletions

View File

@ -158,6 +158,25 @@ class Utilities(callbacks.Privmsg):
irc.reply(f(text)) irc.reply(f(text))
re = privmsgs.checkCapability(re, 'trusted') re = privmsgs.checkCapability(re, 'trusted')
def apply(self, irc, msg, args):
"""<command> <text>
Tokenizes <text> and calls <command> 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 Class = Utilities
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:

View File

@ -550,6 +550,18 @@ class Channel(callbacks.Privmsg):
else: else:
irc.reply('I\'m not currently lobotomized in any channels.') irc.reply('I\'m not currently lobotomized in any channels.')
def nicks(self, irc, msg, args):
"""[<channel>]
Returns the nicks in <channel>. <channel> 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 Class = Channel

View File

@ -233,26 +233,8 @@ class Owner(privmsgs.CapabilityCheckingPrivmsg):
self.disambiguate(irc, elt, ambiguousCommands) self.disambiguate(irc, elt, ambiguousCommands)
return ambiguousCommands return ambiguousCommands
def doPrivmsg(self, irc, msg): def processTokens(self, irc, msg, tokens):
callbacks.Privmsg.handled = False ambiguousCommands = self.disambiguate(irc, tokens)
callbacks.Privmsg.errored = False
if ircdb.checkIgnored(msg.prefix):
return
s = callbacks.addressed(irc.nick, msg)
if s:
try:
tokens = callbacks.tokenize(s)
if tokens and isinstance(tokens[0], list):
s = 'The command called may not be the result ' \
'of a nested command.'
irc.queueMsg(callbacks.error(msg, s))
return
except SyntaxError, e:
callbacks.Privmsg.errored = True
irc.queueMsg(callbacks.error(msg, str(e)))
return
ambiguousCommands = {}
self.disambiguate(irc, tokens, ambiguousCommands)
if ambiguousCommands: if ambiguousCommands:
if len(ambiguousCommands) == 1: # Common case. if len(ambiguousCommands) == 1: # Common case.
(command, names) = ambiguousCommands.popitem() (command, names) = ambiguousCommands.popitem()
@ -275,6 +257,26 @@ class Owner(privmsgs.CapabilityCheckingPrivmsg):
else: else:
callbacks.IrcObjectProxy(irc, msg, tokens) callbacks.IrcObjectProxy(irc, msg, tokens)
def doPrivmsg(self, irc, msg):
callbacks.Privmsg.handled = False
callbacks.Privmsg.errored = False
if ircdb.checkIgnored(msg.prefix):
return
s = callbacks.addressed(irc.nick, msg)
if s:
try:
tokens = callbacks.tokenize(s)
if tokens and isinstance(tokens[0], list):
s = 'The command called may not be the result ' \
'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
if conf.allowEval: if conf.allowEval:
def eval(self, irc, msg, args): def eval(self, irc, msg, args):
"""<expression> """<expression>