Converted to commands.wrap. These are all untested, so someone should test them at some point.

This commit is contained in:
Jeremy Fincher 2004-11-19 23:54:14 +00:00
parent 4a4a0915b7
commit 8071e0236b
2 changed files with 40 additions and 71 deletions

View File

@ -41,8 +41,8 @@ import re
import supybot.conf as conf import supybot.conf as conf
import supybot.utils as utils import supybot.utils as utils
from supybot.commands import *
import supybot.ircutils as ircutils import supybot.ircutils as ircutils
import supybot.privmsgs as privmsgs
import supybot.registry as registry import supybot.registry as registry
import supybot.webutils as webutils import supybot.webutils as webutils
import supybot.callbacks as callbacks import supybot.callbacks as callbacks
@ -76,24 +76,12 @@ class Currency(callbacks.Privmsg):
r'(.*)</body>', re.I | re.S) r'(.*)</body>', re.I | re.S)
_xeConvert = re.compile(r'<TD[^>]+><FONT[^>]+>\s+([\d.]+\s+\w{3}\s+=' _xeConvert = re.compile(r'<TD[^>]+><FONT[^>]+>\s+([\d.]+\s+\w{3}\s+='
r'\s+[\d.]+\s+\w{3})', re.I | re.S) r'\s+[\d.]+\s+\w{3})', re.I | re.S)
def xe(self, irc, msg, args): def xe(self, irc, msg, args, number, curr1, to, curr2):
"""[<number>] <currency1> to <currency2> """[<number>] <currency1> [to] <currency2>
Converts from <currency1> to <currency2>. If number isn't given, it Converts from <currency1> to <currency2>. If number isn't given, it
defaults to 1. 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: if len(curr1) != 3 and len(curr2) != 3:
irc.error(self._symbolError) irc.error(self._symbolError)
return return
@ -119,25 +107,15 @@ class Currency(callbacks.Privmsg):
else: else:
irc.error('XE must\'ve changed the format of their site.') irc.error('XE must\'ve changed the format of their site.')
return 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):
"""[<number>] <currency1> to <currency2> """[<number>] <currency1> to <currency2>
Converts from <currency1> to <currency2>. If number isn't given, it Converts from <currency1> to <currency2>. If number isn't given, it
defaults to 1. 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: if len(curr1) != 3 and len(curr2) != 3:
irc.error(self._symbolError) irc.error(self._symbolError)
return return
@ -157,6 +135,8 @@ class Currency(callbacks.Privmsg):
if '.' not in resp[0] and 'e' not in resp[0]: if '.' not in resp[0] and 'e' not in resp[0]:
resp[0] = '%s.00' % resp[0] resp[0] = '%s.00' % resp[0]
irc.reply(' '.join(resp)) irc.reply(' '.join(resp))
yahoo = wrap(yahoo, [optional(float, 1.0), 'lowered',
optional(literal('to')), 'lowered'])
conf.registerPlugin('Currency') conf.registerPlugin('Currency')
conf.registerChannelValue(conf.supybot.plugins.Currency, 'command', conf.registerChannelValue(conf.supybot.plugins.Currency, 'command',

View File

@ -43,8 +43,8 @@ import time
import supybot.conf as conf import supybot.conf as conf
import supybot.utils as utils import supybot.utils as utils
from supybot.commands import *
import supybot.ircmsgs as ircmsgs import supybot.ircmsgs as ircmsgs
import supybot.privmsgs as privmsgs
import supybot.ircutils as ircutils import supybot.ircutils as ircutils
import supybot.registry as registry import supybot.registry as registry
import supybot.schedule as schedule 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.""")) 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. """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 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 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 configuration variables to match the NickServ and ChanServ nicks on your
network. Other commands such as identify, getops, etc. should not be network. Other commands such as identify, getops, etc. should not be
necessary if the bot is properly configured.""" necessary if the bot is properly configured."""
capability = 'admin'
def __init__(self): def __init__(self):
self.__parent = super(Services, self) self.__parent = super(Services, self)
self.__parent.__init__() self.__parent.__init__()
@ -436,35 +435,29 @@ class Services(privmsgs.CapabilityCheckingPrivmsg):
irc.error('You must set supybot.plugins.Services.ChanServ ' irc.error('You must set supybot.plugins.Services.ChanServ '
'before I\'m able to do get voiced.', Raise=True) 'before I\'m able to do get voiced.', Raise=True)
def op(self, irc, msg, args): def op(self, irc, msg, args, channel):
"""[<channel>] """[<channel>]
Attempts to get opped by ChanServ in <channel>. <channel> is only Attempts to get opped by ChanServ 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.
""" """
channel = privmsgs.getChannel(msg, args) if irc.nick in irc.state.channels[channel].ops:
try: irc.error('I\'m already opped in %s.' % channel)
if irc.nick in irc.state.channels[channel].ops: else:
irc.error('I\'m already opped in %s.' % channel) self._chanservCommand(irc, channel, 'op')
else: op = wrap(op, [('checkChannelCapability', 'op'), 'inChannel'])
self._chanservCommand(irc, channel, 'op')
except KeyError:
irc.error('I\'m not in %s.' % channel)
def voice(self, irc, msg, args): def voice(self, irc, msg, args, channel):
"""[<channel>] """[<channel>]
Attempts to get voiced by ChanServ in <channel>. <channel> is only Attempts to get voiced by ChanServ 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.
""" """
channel = privmsgs.getChannel(msg, args) if irc.nick in irc.state.channels[channel].voices:
try: irc.error('I\'m already voiced in %s.' % channel)
if irc.nick in irc.state.channels[channel].voices: else:
irc.error('I\'m already voiced in %s.' % channel) self._chanservCommand(irc, channel, 'voice')
else: voice = wrap(voice, [('checkChannelCapability', 'op'), 'inChannel'])
self._chanservCommand(irc, channel, 'voice')
except KeyError:
irc.error('I\'m not in %s.' % channel)
def do474(self, irc, msg): def do474(self, irc, msg):
channel = msg.args[1] channel = msg.args[1]
@ -472,7 +465,7 @@ class Services(privmsgs.CapabilityCheckingPrivmsg):
self._chanservCommand(irc, channel, 'unban', log=True) self._chanservCommand(irc, channel, 'unban', log=True)
# Success log in doChanservNotice. # Success log in doChanservNotice.
def unban(self, irc, msg, args): def unban(self, irc, msg, args, channel):
"""[<channel>] """[<channel>]
Attempts to get unbanned by ChanServ in <channel>. <channel> is only Attempts to get unbanned by ChanServ in <channel>. <channel> is only
@ -480,19 +473,16 @@ class Services(privmsgs.CapabilityCheckingPrivmsg):
are, if you need this command, you're not sending it in the channel are, if you need this command, you're not sending it in the channel
itself. itself.
""" """
channel = privmsgs.getChannel(msg, args) self._chanservCommand(irc, channel, 'unban')
try: irc.replySuccess()
self._chanservCommand(irc, channel, 'unban') unban = wrap(unban, [('checkChannelCapability', 'op')])
irc.replySuccess()
except KeyError:
irc.error('I\'m not in %s.' % channel)
def do473(self, irc, msg): def do473(self, irc, msg):
channel = msg.args[1] channel = msg.args[1]
self.log.info('%s is +i, attempting ChanServ invite.', channel) self.log.info('%s is +i, attempting ChanServ invite.', channel)
self._chanservCommand(irc, channel, 'invite', log=True) self._chanservCommand(irc, channel, 'invite', log=True)
def invite(self, irc, msg, args): def invite(self, irc, msg, args, channel):
"""[<channel>] """[<channel>]
Attempts to get invited by ChanServ to <channel>. <channel> is only Attempts to get invited by ChanServ to <channel>. <channel> is only
@ -500,12 +490,9 @@ class Services(privmsgs.CapabilityCheckingPrivmsg):
are, if you need this command, you're not sending it in the channel are, if you need this command, you're not sending it in the channel
itself. itself.
""" """
channel = privmsgs.getChannel(msg, args) self._chanservCommand(irc, channel, 'invite')
try: irc.replySuccess()
self._chanservCommand(irc, channel, 'invite') invite = wrap(invite, [('checkChannelCapability', 'op'), 'inChannel'])
irc.replySuccess()
except KeyError:
irc.error('I\'m not in %s.' % channel)
def doInvite(self, irc, msg): def doInvite(self, irc, msg):
if ircutils.strEqual(msg.nick, self.registryValue('ChanServ')): if ircutils.strEqual(msg.nick, self.registryValue('ChanServ')):
@ -516,7 +503,7 @@ class Services(privmsgs.CapabilityCheckingPrivmsg):
def identify(self, irc, msg, args): def identify(self, irc, msg, args):
"""takes no arguments """takes no arguments
Identifies with NickServ. Identifies with NickServ using the current nick.
""" """
if self.registryValue('NickServ'): if self.registryValue('NickServ'):
if irc.nick in self.registryValue('nicks'): if irc.nick in self.registryValue('nicks'):
@ -528,15 +515,15 @@ class Services(privmsgs.CapabilityCheckingPrivmsg):
else: else:
irc.error('You must set supybot.plugins.Services.NickServ before ' irc.error('You must set supybot.plugins.Services.NickServ before '
'I\'m able to do identify.') 'I\'m able to do identify.')
identify = wrap(identify, ['checkCapability', 'admin'])
def ghost(self, irc, msg, args): def ghost(self, irc, msg, args, nick):
"""[<nick>] """[<nick>]
Ghosts the bot's given nick and takes it. If no nick is given, Ghosts the bot's given nick and takes it. If no nick is given,
ghosts the bot's configured nick and takes it. ghosts the bot's configured nick and takes it.
""" """
if self.registryValue('NickServ'): if self.registryValue('NickServ'):
nick = privmsgs.getArgs(args, required=0, optional=1)
if not nick: if not nick:
nick = self._getNick() nick = self._getNick()
if ircutils.strEqual(nick, irc.nick): if ircutils.strEqual(nick, irc.nick):
@ -547,16 +534,14 @@ class Services(privmsgs.CapabilityCheckingPrivmsg):
else: else:
irc.error('You must set supybot.plugins.Services.NickServ before ' irc.error('You must set supybot.plugins.Services.NickServ before '
'I\'m able to ghost a nick.') '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):
"""<nick> [<password>] """<nick> [<password>]
Sets the NickServ password for <nick> to <password>. If <password> is Sets the NickServ password for <nick> to <password>. If <password> is
not given, removes <nick> from the configured nicks. not given, removes <nick> from the configured nicks.
""" """
if ircutils.isChannel(msg.args[0]):
irc.errorRequiresPrivacy(Raise=True)
(nick, password) = privmsgs.getArgs(args, optional=1)
if not password: if not password:
try: try:
self.registryValue('nicks').remove(nick) self.registryValue('nicks').remove(nick)
@ -568,18 +553,22 @@ class Services(privmsgs.CapabilityCheckingPrivmsg):
self.registryValue('nicks').add(nick) self.registryValue('nicks').add(nick)
registerNick(nick, password) registerNick(nick, password)
irc.replySuccess() irc.replySuccess()
password = wrap(password, [('checkCapability', 'admin'),
'private', 'nick', 'text'])
def nicks(self, irc, msg, args): def nicks(self, irc, msg, args):
"""takes no arguments """takes no arguments
Returns the nicks that this plugin is configured to identify and ghost Returns the nicks that this plugin is configured to identify and ghost
with.""" with.
"""
L = list(self.registryValue('nicks')) L = list(self.registryValue('nicks'))
if L: if L:
utils.sortBy(ircutils.toLower, L) utils.sortBy(ircutils.toLower, L)
irc.reply(utils.commaAndify(L)) irc.reply(utils.commaAndify(L))
else: else:
irc.reply('I\'m not currently configured for any nicks.') irc.reply('I\'m not currently configured for any nicks.')
nicks = wrap(nicks, [('checkCapability', 'admin')])
Class = Services Class = Services