Updated to use commands.wrap.

This commit is contained in:
Jeremy Fincher 2004-10-26 20:45:52 +00:00
parent c0236521b2
commit 44d59fc651
2 changed files with 19 additions and 28 deletions

View File

@ -38,8 +38,8 @@ import supybot.plugins as plugins
import supybot.conf as conf import supybot.conf as conf
import supybot.utils as utils import supybot.utils as utils
import supybot.ircdb as ircdb import supybot.ircdb as ircdb
from supybot.commands import *
import supybot.ircmsgs as ircmsgs import supybot.ircmsgs as ircmsgs
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
@ -78,9 +78,6 @@ class Anonymous(callbacks.Privmsg):
_ = ircdb.users.getUser(msg.prefix) _ = ircdb.users.getUser(msg.prefix)
except KeyError: except KeyError:
irc.errorNotRegistered(Raise=True) irc.errorNotRegistered(Raise=True)
if channel not in irc.state.channels:
irc.error('I\'m not in %s, chances are that I can\'t say anything '
'in there.' % channel, Raise=True)
capability = self.registryValue('requireCapability') capability = self.registryValue('requireCapability')
if capability: if capability:
if not ircdb.checkCapability(msg.prefix, capability): if not ircdb.checkCapability(msg.prefix, capability):
@ -96,27 +93,27 @@ class Anonymous(callbacks.Privmsg):
irc.error('That channel has set its capabilities so as to ' irc.error('That channel has set its capabilities so as to '
'disallow the use of this plugin.', Raise=True) 'disallow the use of this plugin.', Raise=True)
def say(self, irc, msg, args): def say(self, irc, msg, args, channel, text):
"""<channel> <text> """<channel> <text>
Sends <text> to <channel>. Sends <text> to <channel>.
""" """
(channel, text) = privmsgs.getArgs(args, required=2)
self._preCheck(irc, msg, channel) self._preCheck(irc, msg, channel)
self.log.info('Saying %s in %s due to %s.', self.log.info('Saying %s in %s due to %s.',
utils.quoted(text), channel, msg.prefix) utils.quoted(text), channel, msg.prefix)
irc.queueMsg(ircmsgs.privmsg(channel, text)) irc.queueMsg(ircmsgs.privmsg(channel, text))
say = wrap(say, ['inChannel', 'text'])
def do(self, irc, msg, args): def do(self, irc, msg, args, channel, text):
"""<channel> <action> """<channel> <action>
Performs <action> in <channel>. Performs <action> in <channel>.
""" """
(channel, action) = privmsgs.getArgs(args, required=2)
self._preCheck(irc, msg, channel) self._preCheck(irc, msg, channel)
self.log.info('Performing %s in %s due to %s.', self.log.info('Performing %s in %s due to %s.',
utils.quoted(action), channel, msg.prefix) utils.quoted(text), channel, msg.prefix)
irc.queueMsg(ircmsgs.action(channel, action)) irc.queueMsg(ircmsgs.action(channel, text))
do = wrap(do, ['inChannel', 'text'])
Class = Anonymous Class = Anonymous

View File

@ -41,7 +41,7 @@ import random
import supybot.conf as conf import supybot.conf as conf
import supybot.utils as utils import supybot.utils as utils
import supybot.privmsgs as privmsgs from supybot.commands import *
import supybot.registry as registry import supybot.registry as registry
import supybot.callbacks as callbacks import supybot.callbacks as callbacks
@ -165,39 +165,36 @@ class Observer(callbacks.Privmsg):
else: else:
irc.reply('There were no relevant observers.') irc.reply('There were no relevant observers.')
def enable(self, irc, msg, args, channel): def enable(self, irc, msg, args, channel, name):
"""[<channel>] <name> """[<channel>] <name>
Enables the observer <name> in <channel>. <channel> is only Enables the observer <name> in <channel>. <channel> is only
necessary if the message isn't sent in the channel itself. necessary if the message isn't sent in the channel itself.
""" """
name = privmsgs.getArgs(args)
if name not in self.registryValue('observers'): if name not in self.registryValue('observers'):
irc.error('There is no observer %s.' % name, Raise=True) irc.error('There is no observer %s.' % name, Raise=True)
self.registryValue('observers.active', channel).append(name) self.registryValue('observers.active', channel).append(name)
irc.replySuccess() irc.replySuccess()
enable = privmsgs.checkChannelCapability(enable, 'op') enable = wrap(enable, [('checkChannelCapability', 'op'), 'something'])
def disable(self, irc, msg, args, channel): def disable(self, irc, msg, args, channel, name):
"""[<channel>] <name> """[<channel>] <name>
Disables the observer <name> in <channel>. <channel> is only Disables the observer <name> in <channel>. <channel> is only
necessary if the message isn't sent in the channel itself. necessary if the message isn't sent in the channel itself.
""" """
name = privmsgs.getArgs(args)
try: try:
self.registryValue('observers.active', channel).remove(name) self.registryValue('observers.active', channel).remove(name)
irc.replySuccess() irc.replySuccess()
except (KeyError, ValueError): except (KeyError, ValueError):
irc.error('The observer %s was not active on %s.' % (name,channel)) irc.error('The observer %s was not active on %s.' % (name,channel))
disable = privmsgs.checkChannelCapability(disable, 'op') disable = wrap(disable, [('checkChannelCapability', 'op'), 'something'])
def info(self, irc, msg, args): def info(self, irc, msg, args, name):
"""<name> """<name>
Returns the relevant information on the observer specified by <name>. Returns the relevant information on the observer specified by <name>.
""" """
name = privmsgs.getArgs(args)
if name not in self.registryValue('observers'): if name not in self.registryValue('observers'):
irc.error('That\'s not a valid observer.', Raise=True) irc.error('That\'s not a valid observer.', Raise=True)
g = self.registryValue('observers.%s' % name, value=False) g = self.registryValue('observers.%s' % name, value=False)
@ -207,8 +204,9 @@ class Observer(callbacks.Privmsg):
irc.reply('%s matches the regular expression %s and ' irc.reply('%s matches the regular expression %s and '
'runs the command %s with a probability of %s' % 'runs the command %s with a probability of %s' %
(name, regexp, command, probability)) (name, regexp, command, probability))
info = wrap(info, ['something'])
def add(self, irc, msg, args): def add(self, irc, msg, args, name, probability, regexp, command):
"""<name> [<probability>] <regexp> <command> """<name> [<probability>] <regexp> <command>
Calls <command> when <regexp> matches a given message. Before Calls <command> when <regexp> matches a given message. Before
@ -218,19 +216,15 @@ class Observer(callbacks.Privmsg):
otherwise it should be a floating point probability that the observer otherwise it should be a floating point probability that the observer
will execute if it matches. will execute if it matches.
""" """
if len(args) < 3:
raise callbacks.ArgumentError
try:
probability = float(args[1])
del args[1]
except ValueError:
probability = 1.0
(name, regexp, command) = privmsgs.getArgs(args, required=3)
if not registry.isValidRegistryName(name): if not registry.isValidRegistryName(name):
irc.error('That\'s not a valid observer name. Please be sure ' irc.error('That\'s not a valid observer name. Please be sure '
'there are no spaces in the name.', Raise=True) 'there are no spaces in the name.', Raise=True)
registerObserver(name, regexp, command, probability) registerObserver(name, regexp, command, probability)
irc.replySuccess() irc.replySuccess()
add = wrap(add, ['something',
optional('float', 1.0),
('regexpMatcher', False),
'text'])
def remove(self, irc, msg, args): def remove(self, irc, msg, args):
"""<name> """<name>