Converted to use commands.

This commit is contained in:
Jeremy Fincher 2004-10-19 16:48:52 +00:00
parent 2179548da9
commit 10fc3bf42a

View File

@ -43,10 +43,10 @@ import supybot.conf as conf
import supybot.utils as utils import supybot.utils as utils
import supybot.world as world import supybot.world as world
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.plugins as plugins import supybot.plugins as plugins
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.callbacks as callbacks import supybot.callbacks as callbacks
@ -147,7 +147,7 @@ class Herald(callbacks.Privmsg):
raise KeyError raise KeyError
return id return id
def default(self, irc, msg, args): def default(self, irc, msg, args, channel, optlist, text):
"""[<channel>] [--remove|<msg>] """[<channel>] [--remove|<msg>]
If <msg> is given, sets the default herald to <msg>. A <msg> of "" If <msg> is given, sets the default herald to <msg>. A <msg> of ""
@ -155,108 +155,84 @@ class Herald(callbacks.Privmsg):
current default herald. <channel> is only necessary if the message current default herald. <channel> is only necessary if the message
isn't sent in the channel itself. isn't sent in the channel itself.
""" """
channel = privmsgs.getChannel(msg, args) if optlist and text:
(optlist, rest) = getopt.getopt(args, '', ['remove'])
if optlist and rest:
raise callbacks.ArgumentError raise callbacks.ArgumentError
for (option, _) in optlist: for (option, _) in optlist:
if option == '--remove': if option == 'remove':
self.setRegistryValue('default', '', channel) self.setRegistryValue('default', '', channel)
irc.replySuccess() irc.replySuccess()
return return
text = privmsgs.getArgs(rest, required=0, optional=1) if text:
if not text: self.setRegistryValue('default', text, channel)
resp = self.registryValue('default', channel) irc.replySuccess()
if not resp: else:
irc.reply('I do not have a default herald set.') resp = self.registryValue('default', channel) or \
return 'I do not have a default herald set for %s.' % channel
else: irc.reply(resp)
irc.reply(resp) default = wrap(default, ['channel',
return getopts({'remove': ''}),
self.setRegistryValue('default', text, channel) additional('text')])
irc.replySuccess()
def get(self, irc, msg, args): def get(self, irc, msg, args, channel, user):
"""[<channel>] <user|nick|hostmask> """[<channel>] [<user|nick|hostmask>]
Returns the current herald message for <user> (or the user Returns the current herald message for <user> (or the user
<nick|hostmask> is currently identified or recognized as). <channel> <nick|hostmask> is currently identified or recognized as). If <user>
is not given, defaults to the user giving the command. <channel>
is only necessary if the message isn't sent in the channel itself. is only necessary if the message isn't sent in the channel itself.
""" """
channel = privmsgs.getChannel(msg, args)
userNickHostmask = privmsgs.getArgs(args)
try: try:
id = self._getId(irc, userNickHostmask) herald = self.db[channel, user.id]
except KeyError:
irc.errorNoUser()
return
try:
herald = self.db[channel, id]
irc.reply(herald) irc.reply(herald)
except KeyError: except KeyError:
irc.error('I have no herald for that user.') irc.error('I have no herald for %s.' % user.name)
get = wrap(get, ['channel', first('otherUser', 'user')])
def add(self, irc, msg, args): # I chose not to make <user|nick|hostmask> optional in this command because
# if it's not a valid username (e.g., if the user tyops and misspells a
# username), it may be nice not to clobber the user's herald.
def add(self, irc, msg, args, channel, user, herald):
"""[<channel>] <user|nick|hostmask> <msg> """[<channel>] <user|nick|hostmask> <msg>
Sets the herald message for <user> (or the user <nick|hostmask> is Sets the herald message for <user> (or the user <nick|hostmask> is
currently identified or recognized as) to <msg>. <channel> is only currently identified or recognized as) to <msg>. <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) self.db[channel, user.id] = herald
(userNickHostmask, herald) = privmsgs.getArgs(args, required=2)
try:
id = self._getId(irc, userNickHostmask)
except KeyError:
irc.errorNoUser()
return
self.db[channel, id] = herald
irc.replySuccess() irc.replySuccess()
add = wrap(add, ['channel', 'otherUser', 'text'])
def remove(self, irc, msg, args): def remove(self, irc, msg, args, channel, user):
"""[<channel>] <user|nick|hostmask> """[<channel>] [<user|nick|hostmask>]
Removes the herald message set for <user>, or the user Removes the herald message set for <user>, or the user
<nick|hostmask> is currently identified or recognized as. <nick|hostmask> is currently identified or recognized as. If <user>
is not given, defaults to the user giving the command.
<channel> is only necessary if the message isn't sent in the channel <channel> is only necessary if the message isn't sent in the channel
itself. itself.
""" """
channel = privmsgs.getChannel(msg, args)
userNickHostmask = privmsgs.getArgs(args)
try: try:
id = self._getId(irc, userNickHostmask) del self.db[channel, user.id]
except KeyError:
irc.errorNoUser()
return
try:
del self.db[channel, id]
irc.replySuccess() irc.replySuccess()
except KeyError: except KeyError:
irc.error('I have no herald for that user.') irc.error('I have no herald for that user.')
remove = wrap(remove, ['channel', first('otherUser', 'user')])
def change(self, irc, msg, args): def change(self, irc, msg, args, channel, user, changer):
"""[<channel>] <user|nick|hostmask> <regexp> """[<channel>] [<user|nick|hostmask>] <regexp>
Changes the herald message for <user>, or the user <nick|hostmask> is Changes the herald message for <user>, or the user <nick|hostmask> is
currently identified or recognized as, according to <regexp>. <channel> currently identified or recognized as, according to <regexp>. If
is only necessary if the message isn't sent in the channel itself. <user> is not given, defaults to the calling user. <channel> is only
necessary if the message isn't sent in the channel itself.
""" """
channel = privmsgs.getChannel(msg, args) s = self.db[channel, user.id]
(userNickHostmask, regexp) = privmsgs.getArgs(args, required=2)
try:
id = self._getId(irc, userNickHostmask)
except KeyError:
irc.errorNoUser()
return
try:
changer = utils.perlReToReplacer(regexp)
except ValueError, e:
irc.error('That\'s not a valid regexp: %s.' % e)
return
s = self.db[channel, id]
newS = changer(s) newS = changer(s)
self.db[channel, id] = newS self.db[channel, user.id] = newS
irc.replySuccess() irc.replySuccess()
change = wrap(change, ['channel',
first('otherUser', 'user'),
'regexpReplacer'])
Class = Herald Class = Herald