From 8071e0236b3ad6a62c0ecb4dc65d284f094131ee Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Fri, 19 Nov 2004 23:54:14 +0000 Subject: [PATCH] Converted to commands.wrap. These are all untested, so someone should test them at some point. --- plugins/Currency.py | 36 +++++----------------- plugins/Services.py | 75 +++++++++++++++++++-------------------------- 2 files changed, 40 insertions(+), 71 deletions(-) diff --git a/plugins/Currency.py b/plugins/Currency.py index 3d22ed0bc..6912a1aae 100644 --- a/plugins/Currency.py +++ b/plugins/Currency.py @@ -41,8 +41,8 @@ import re import supybot.conf as conf import supybot.utils as utils +from supybot.commands import * import supybot.ircutils as ircutils -import supybot.privmsgs as privmsgs import supybot.registry as registry import supybot.webutils as webutils import supybot.callbacks as callbacks @@ -76,24 +76,12 @@ class Currency(callbacks.Privmsg): r'(.*)', re.I | re.S) _xeConvert = re.compile(r']+>]+>\s+([\d.]+\s+\w{3}\s+=' r'\s+[\d.]+\s+\w{3})', re.I | re.S) - def xe(self, irc, msg, args): - """[] to + def xe(self, irc, msg, args, number, curr1, to, curr2): + """[] [to] Converts from to . If number isn't given, it defaults to 1. """ - (number, curr1, curr2) = privmsgs.getArgs(args, required=2, - optional=1) - try: - number = float(number) - except ValueError: - curr2 = curr1 - curr1 = number - number = 1 - curr1 = curr1.lower() - curr2 = curr2.lower() - if curr2.startswith('to '): - curr2 = curr2[3:] if len(curr1) != 3 and len(curr2) != 3: irc.error(self._symbolError) return @@ -119,25 +107,15 @@ class Currency(callbacks.Privmsg): else: irc.error('XE must\'ve changed the format of their site.') return + xe = wrap(xe, [optional('float', 1.0), 'lowered', + optional(literal('to')), 'lowered']) - def yahoo(self, irc, msg, args): + def yahoo(self, irc, msg, args, number, curr1, to, curr2): """[] to Converts from to . If number isn't given, it defaults to 1. """ - (number, curr1, curr2) = privmsgs.getArgs(args, required=2, - optional=1) - try: - number = float(number) - except ValueError: - curr2 = curr1 - curr1 = number - number = 1 - curr1 = curr1.upper() - curr2 = curr2.upper() - if curr2.startswith('TO '): - curr2 = curr2[3:] if len(curr1) != 3 and len(curr2) != 3: irc.error(self._symbolError) return @@ -157,6 +135,8 @@ class Currency(callbacks.Privmsg): if '.' not in resp[0] and 'e' not in resp[0]: resp[0] = '%s.00' % resp[0] irc.reply(' '.join(resp)) + yahoo = wrap(yahoo, [optional(float, 1.0), 'lowered', + optional(literal('to')), 'lowered']) conf.registerPlugin('Currency') conf.registerChannelValue(conf.supybot.plugins.Currency, 'command', diff --git a/plugins/Services.py b/plugins/Services.py index 35f618b77..b9ceeefd6 100644 --- a/plugins/Services.py +++ b/plugins/Services.py @@ -43,8 +43,8 @@ import time import supybot.conf as conf import supybot.utils as utils +from supybot.commands import * import supybot.ircmsgs as ircmsgs -import supybot.privmsgs as privmsgs import supybot.ircutils as ircutils import supybot.registry as registry import supybot.schedule as schedule @@ -123,7 +123,7 @@ conf.registerChannelValue(conf.supybot.plugins.Services.ChanServ, 'voice', voiced by the ChanServ when it joins the channel.""")) -class Services(privmsgs.CapabilityCheckingPrivmsg): +class Services(callbacks.Privmsg): """This plugin handles dealing with Services on networks that provide them. Basically, you should use the "password" command to tell the bot a nick to identify with and what password to use to identify with that nick. You can @@ -132,7 +132,6 @@ class Services(privmsgs.CapabilityCheckingPrivmsg): configuration variables to match the NickServ and ChanServ nicks on your network. Other commands such as identify, getops, etc. should not be necessary if the bot is properly configured.""" - capability = 'admin' def __init__(self): self.__parent = super(Services, self) self.__parent.__init__() @@ -436,35 +435,29 @@ class Services(privmsgs.CapabilityCheckingPrivmsg): irc.error('You must set supybot.plugins.Services.ChanServ ' 'before I\'m able to do get voiced.', Raise=True) - def op(self, irc, msg, args): + def op(self, irc, msg, args, channel): """[] Attempts to get opped by ChanServ in . is only necessary if the message isn't sent in the channel itself. """ - channel = privmsgs.getChannel(msg, args) - try: - if irc.nick in irc.state.channels[channel].ops: - irc.error('I\'m already opped in %s.' % channel) - else: - self._chanservCommand(irc, channel, 'op') - except KeyError: - irc.error('I\'m not in %s.' % channel) + if irc.nick in irc.state.channels[channel].ops: + irc.error('I\'m already opped in %s.' % channel) + else: + self._chanservCommand(irc, channel, 'op') + op = wrap(op, [('checkChannelCapability', 'op'), 'inChannel']) - def voice(self, irc, msg, args): + def voice(self, irc, msg, args, channel): """[] Attempts to get voiced by ChanServ in . is only necessary if the message isn't sent in the channel itself. """ - channel = privmsgs.getChannel(msg, args) - try: - if irc.nick in irc.state.channels[channel].voices: - irc.error('I\'m already voiced in %s.' % channel) - else: - self._chanservCommand(irc, channel, 'voice') - except KeyError: - irc.error('I\'m not in %s.' % channel) + if irc.nick in irc.state.channels[channel].voices: + irc.error('I\'m already voiced in %s.' % channel) + else: + self._chanservCommand(irc, channel, 'voice') + voice = wrap(voice, [('checkChannelCapability', 'op'), 'inChannel']) def do474(self, irc, msg): channel = msg.args[1] @@ -472,7 +465,7 @@ class Services(privmsgs.CapabilityCheckingPrivmsg): self._chanservCommand(irc, channel, 'unban', log=True) # Success log in doChanservNotice. - def unban(self, irc, msg, args): + def unban(self, irc, msg, args, channel): """[] Attempts to get unbanned by ChanServ in . is only @@ -480,19 +473,16 @@ class Services(privmsgs.CapabilityCheckingPrivmsg): are, if you need this command, you're not sending it in the channel itself. """ - channel = privmsgs.getChannel(msg, args) - try: - self._chanservCommand(irc, channel, 'unban') - irc.replySuccess() - except KeyError: - irc.error('I\'m not in %s.' % channel) + self._chanservCommand(irc, channel, 'unban') + irc.replySuccess() + unban = wrap(unban, [('checkChannelCapability', 'op')]) def do473(self, irc, msg): channel = msg.args[1] self.log.info('%s is +i, attempting ChanServ invite.', channel) self._chanservCommand(irc, channel, 'invite', log=True) - def invite(self, irc, msg, args): + def invite(self, irc, msg, args, channel): """[] Attempts to get invited by ChanServ to . is only @@ -500,12 +490,9 @@ class Services(privmsgs.CapabilityCheckingPrivmsg): are, if you need this command, you're not sending it in the channel itself. """ - channel = privmsgs.getChannel(msg, args) - try: - self._chanservCommand(irc, channel, 'invite') - irc.replySuccess() - except KeyError: - irc.error('I\'m not in %s.' % channel) + self._chanservCommand(irc, channel, 'invite') + irc.replySuccess() + invite = wrap(invite, [('checkChannelCapability', 'op'), 'inChannel']) def doInvite(self, irc, msg): if ircutils.strEqual(msg.nick, self.registryValue('ChanServ')): @@ -516,7 +503,7 @@ class Services(privmsgs.CapabilityCheckingPrivmsg): def identify(self, irc, msg, args): """takes no arguments - Identifies with NickServ. + Identifies with NickServ using the current nick. """ if self.registryValue('NickServ'): if irc.nick in self.registryValue('nicks'): @@ -528,15 +515,15 @@ class Services(privmsgs.CapabilityCheckingPrivmsg): else: irc.error('You must set supybot.plugins.Services.NickServ before ' 'I\'m able to do identify.') + identify = wrap(identify, ['checkCapability', 'admin']) - def ghost(self, irc, msg, args): + def ghost(self, irc, msg, args, nick): """[] Ghosts the bot's given nick and takes it. If no nick is given, ghosts the bot's configured nick and takes it. """ if self.registryValue('NickServ'): - nick = privmsgs.getArgs(args, required=0, optional=1) if not nick: nick = self._getNick() if ircutils.strEqual(nick, irc.nick): @@ -547,16 +534,14 @@ class Services(privmsgs.CapabilityCheckingPrivmsg): else: irc.error('You must set supybot.plugins.Services.NickServ before ' 'I\'m able to ghost a nick.') + ghost = wrap(ghost, [('checkCapability', 'admin'), additional('nick')]) - def password(self, irc, msg, args): + def password(self, irc, msg, args, nick, password): """ [] Sets the NickServ password for to . If is not given, removes from the configured nicks. """ - if ircutils.isChannel(msg.args[0]): - irc.errorRequiresPrivacy(Raise=True) - (nick, password) = privmsgs.getArgs(args, optional=1) if not password: try: self.registryValue('nicks').remove(nick) @@ -568,18 +553,22 @@ class Services(privmsgs.CapabilityCheckingPrivmsg): self.registryValue('nicks').add(nick) registerNick(nick, password) irc.replySuccess() + password = wrap(password, [('checkCapability', 'admin'), + 'private', 'nick', 'text']) def nicks(self, irc, msg, args): """takes no arguments Returns the nicks that this plugin is configured to identify and ghost - with.""" + with. + """ L = list(self.registryValue('nicks')) if L: utils.sortBy(ircutils.toLower, L) irc.reply(utils.commaAndify(L)) else: irc.reply('I\'m not currently configured for any nicks.') + nicks = wrap(nicks, [('checkCapability', 'admin')]) Class = Services