mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-23 19:22:45 +01:00
Updated to use commands.wrap.
This commit is contained in:
parent
98c716d8cb
commit
e24c1c0cc6
@ -46,11 +46,11 @@ from itertools import imap, ifilter
|
||||
import supybot.conf as conf
|
||||
import supybot.utils as utils
|
||||
import supybot.world as world
|
||||
from supybot.commands import *
|
||||
import supybot.irclib as irclib
|
||||
import supybot.drivers as drivers
|
||||
import supybot.ircmsgs as ircmsgs
|
||||
import supybot.ircutils as ircutils
|
||||
import supybot.privmsgs as privmsgs
|
||||
import supybot.registry as registry
|
||||
import supybot.callbacks as callbacks
|
||||
from supybot.structures import RingBuffer
|
||||
@ -146,45 +146,38 @@ class Relay(callbacks.Privmsg):
|
||||
irc.queueMsg(ircmsgs.who(channel))
|
||||
irc.queueMsg(ircmsgs.names(channel))
|
||||
|
||||
def join(self, irc, msg, args):
|
||||
"""<channel>
|
||||
def join(self, irc, msg, args, channel):
|
||||
"""[<channel>]
|
||||
|
||||
Starts relaying between the channel <channel> on all networks. If on a
|
||||
network the bot isn't in <channel>, he'll join. This commands is
|
||||
required even if the bot is in the channel on both networks; he won't
|
||||
relay between those channels unless he's told to join both
|
||||
channels.
|
||||
channels. If <channel> is not given, starts relaying on the channel
|
||||
the message was sent in.
|
||||
"""
|
||||
channel = privmsgs.getArgs(args)
|
||||
if not ircutils.isChannel(channel):
|
||||
irc.error('%r is not a valid channel.' % channel)
|
||||
return
|
||||
self.registryValue('channels').add(channel)
|
||||
for otherIrc in world.ircs: # Should we abstract this?
|
||||
if channel not in otherIrc.state.channels:
|
||||
otherIrc.queueMsg(ircmsgs.join(channel))
|
||||
irc.replySuccess()
|
||||
join = privmsgs.checkCapability(join, 'owner')
|
||||
join = wrap(join, ['channel'])
|
||||
|
||||
def part(self, irc, msg, args):
|
||||
def part(self, irc, msg, args, channel):
|
||||
"""<channel>
|
||||
|
||||
Ceases relaying between the channel <channel> on all networks. The bot
|
||||
will part from the channel on all networks in which it is on the
|
||||
channel.
|
||||
"""
|
||||
channel = privmsgs.getArgs(args)
|
||||
if not ircutils.isChannel(channel):
|
||||
irc.error('%r is not a valid channel.' % channel)
|
||||
return
|
||||
self.registryValue('channels').remove(channel)
|
||||
self.registryValue('channels').discard(channel)
|
||||
for otherIrc in world.ircs:
|
||||
if channel in otherIrc.state.channels:
|
||||
otherIrc.queueMsg(ircmsgs.part(channel))
|
||||
irc.replySuccess()
|
||||
part = privmsgs.checkCapability(part, 'owner')
|
||||
part = wrap(part, ['channel'])
|
||||
|
||||
def nicks(self, irc, msg, args):
|
||||
def nicks(self, irc, msg, args, channel):
|
||||
"""[<channel>]
|
||||
|
||||
Returns the nicks of the people in the channel on the various networks
|
||||
@ -192,7 +185,6 @@ class Relay(callbacks.Privmsg):
|
||||
isn't sent on the channel itself.
|
||||
"""
|
||||
realIrc = self._getRealIrc(irc)
|
||||
channel = privmsgs.getChannel(msg, args)
|
||||
if channel not in self.registryValue('channels'):
|
||||
irc.error('I\'m not relaying in %s.' % channel)
|
||||
return
|
||||
@ -234,15 +226,7 @@ class Relay(callbacks.Privmsg):
|
||||
(ircutils.bold(network), numUsers, usersS))
|
||||
users.sort()
|
||||
irc.reply('; '.join(users))
|
||||
|
||||
def ignore(self, irc, msg, args):
|
||||
"""[<channel>] <nick|hostmask>
|
||||
|
||||
Ignores everything said or done by <nick|hostmask> in <channel>.
|
||||
<channel> is only necessary if the message isn't sent in the channel
|
||||
itself.
|
||||
"""
|
||||
pass
|
||||
nicks = wrap(nicks, ['channel'])
|
||||
|
||||
def do311(self, irc, msg):
|
||||
irc = self._getRealIrc(irc)
|
||||
|
@ -44,6 +44,7 @@ import time
|
||||
|
||||
import supybot.conf as conf
|
||||
import supybot.utils as utils
|
||||
from supybot.commands import *
|
||||
import supybot.privmsgs as privmsgs
|
||||
import supybot.schedule as schedule
|
||||
import supybot.callbacks as callbacks
|
||||
@ -63,7 +64,7 @@ class Scheduler(callbacks.Privmsg):
|
||||
self.Proxy(irc.irc, msg, tokens)
|
||||
return f
|
||||
|
||||
def add(self, irc, msg, args):
|
||||
def add(self, irc, msg, args, seconds, command):
|
||||
"""<seconds> <command>
|
||||
|
||||
Schedules the command string <command> to run <seconds> seconds in the
|
||||
@ -72,25 +73,18 @@ class Scheduler(callbacks.Privmsg):
|
||||
command was given in (with no prefixed nick, a consequence of using
|
||||
echo). Do pay attention to the quotes in that example.
|
||||
"""
|
||||
(seconds, command) = privmsgs.getArgs(args, required=2)
|
||||
try:
|
||||
seconds = int(seconds)
|
||||
except ValueError:
|
||||
irc.error('Invalid seconds value: %r' % seconds)
|
||||
return
|
||||
f = self._makeCommandFunction(irc, msg, command)
|
||||
id = schedule.addEvent(f, time.time() + seconds)
|
||||
f.eventId = id
|
||||
self.events[str(id)] = command
|
||||
irc.replySuccess('Event #%s added.' % id)
|
||||
add = wrap(add, ['positiveInt', 'text'])
|
||||
|
||||
def remove(self, irc, msg, args):
|
||||
def remove(self, irc, msg, args, id):
|
||||
"""<id>
|
||||
|
||||
Removes the event scheduled with id <id> from the schedule.
|
||||
"""
|
||||
id = privmsgs.getArgs(args)
|
||||
id = id.lower()
|
||||
if id in self.events:
|
||||
del self.events[id]
|
||||
try:
|
||||
@ -104,8 +98,9 @@ class Scheduler(callbacks.Privmsg):
|
||||
irc.error('Invalid event id.')
|
||||
else:
|
||||
irc.error('Invalid event id.')
|
||||
remove = wrap(remove, ['lowered'])
|
||||
|
||||
def repeat(self, irc, msg, args):
|
||||
def repeat(self, irc, msg, args, name, seconds, command):
|
||||
"""<name> <seconds> <command>
|
||||
|
||||
Schedules the command <command> to run every <seconds> seconds,
|
||||
@ -113,19 +108,7 @@ class Scheduler(callbacks.Privmsg):
|
||||
thereafter). <name> is a name by which the command can be
|
||||
unscheduled.
|
||||
"""
|
||||
(name, seconds, command) = privmsgs.getArgs(args, required=3)
|
||||
name = name.lower()
|
||||
try:
|
||||
seconds = int(seconds)
|
||||
except ValueError:
|
||||
irc.error('Invalid seconds: %r' % seconds)
|
||||
return
|
||||
try:
|
||||
name = int(name)
|
||||
irc.error('Names must not be an integer.')
|
||||
return
|
||||
except ValueError:
|
||||
pass
|
||||
name = name.lower() # XXX We should have a "compose" context for this.
|
||||
self.events[name] = command
|
||||
f = self._makeCommandFunction(irc, msg, command, remove=False)
|
||||
id = schedule.addPeriodicEvent(f, seconds, name)
|
||||
@ -133,6 +116,7 @@ class Scheduler(callbacks.Privmsg):
|
||||
# We don't reply because the command runs immediately.
|
||||
# But should we? What if the command doesn't have visible output?
|
||||
# irc.replySuccess()
|
||||
repeat = wrap(repeat, ['nonInt', 'positiveInt', 'text'])
|
||||
|
||||
def list(self, irc, msg, args):
|
||||
"""takes no arguments
|
||||
@ -147,6 +131,7 @@ class Scheduler(callbacks.Privmsg):
|
||||
irc.reply(utils.commaAndify(L))
|
||||
else:
|
||||
irc.reply('There are currently no scheduled commands.')
|
||||
list = wrap(list)
|
||||
|
||||
|
||||
Class = Scheduler
|
||||
|
@ -51,10 +51,10 @@ import supybot.conf as conf
|
||||
import supybot.utils as utils
|
||||
import supybot.world as world
|
||||
import supybot.ircdb as ircdb
|
||||
from supybot.commands import *
|
||||
import supybot.ircmsgs as ircmsgs
|
||||
import supybot.plugins as plugins
|
||||
import supybot.ircutils as ircutils
|
||||
import supybot.privmsgs as privmsgs
|
||||
import supybot.registry as registry
|
||||
import supybot.callbacks as callbacks
|
||||
|
||||
@ -130,15 +130,13 @@ class Seen(callbacks.Privmsg):
|
||||
except KeyError:
|
||||
pass # Not in the database.
|
||||
|
||||
def seen(self, irc, msg, args):
|
||||
def seen(self, irc, msg, args, channel, name):
|
||||
"""[<channel>] <nick>
|
||||
|
||||
Returns the last time <nick> was seen and what <nick> was last seen
|
||||
saying. <channel> is only necessary if the message isn't sent on the
|
||||
channel itself.
|
||||
"""
|
||||
channel = privmsgs.getChannel(msg, args)
|
||||
name = privmsgs.getArgs(args)
|
||||
try:
|
||||
results = []
|
||||
if '*' in name:
|
||||
@ -156,29 +154,31 @@ class Seen(callbacks.Privmsg):
|
||||
(when, said) = info
|
||||
L.append('%s (%s ago)' %
|
||||
(nick, utils.timeElapsed(time.time()-when)))
|
||||
irc.reply('%s could be %s' % (name, utils.commaAndify(L, And='or')))
|
||||
irc.reply('%s could be %s' %
|
||||
(name, utils.commaAndify(L, And='or')))
|
||||
else:
|
||||
irc.reply('I haven\'t seen anyone matching %s' % name)
|
||||
|
||||
irc.reply('I haven\'t seen anyone matching %s.' % name)
|
||||
except KeyError:
|
||||
irc.reply('I have not seen %s.' % name)
|
||||
# XXX This should be channeldb, but ChannelUserDictionary does't support it.
|
||||
seen = wrap(seen, ['channel', 'nick'])
|
||||
|
||||
def last(self, irc, msg, args):
|
||||
def last(self, irc, msg, args, channel):
|
||||
"""[<channel>]
|
||||
|
||||
Returns the last thing said in <channel>. <channel> is only necessary
|
||||
if the message isn't sent in the channel itself.
|
||||
"""
|
||||
channel = privmsgs.getChannel(msg, args)
|
||||
try:
|
||||
(when, said) = self.db.seen(channel, '<last>')
|
||||
irc.reply('Someone was last seen here %s ago saying: %s' %
|
||||
(utils.timeElapsed(time.time()-when), said))
|
||||
except KeyError:
|
||||
irc.reply('I have never seen anyone.')
|
||||
last = wrap(last, ['channel'])
|
||||
|
||||
|
||||
def user(self, irc, msg, args):
|
||||
def user(self, irc, msg, args, channel, user):
|
||||
"""[<channel>] <name>
|
||||
|
||||
Returns the last time <name> was seen and what <name> was last seen
|
||||
@ -187,23 +187,13 @@ class Seen(callbacks.Privmsg):
|
||||
<channel> is only necessary if the message isn't sent in the channel
|
||||
itself.
|
||||
"""
|
||||
channel = privmsgs.getChannel(msg, args)
|
||||
name = privmsgs.getArgs(args)
|
||||
try:
|
||||
id = ircdb.users.getUserId(name)
|
||||
except KeyError:
|
||||
try:
|
||||
hostmask = irc.state.nickToHostmask(name)
|
||||
id = ircdb.users.getUserId(hostmask)
|
||||
except KeyError:
|
||||
irc.errorNoUser()
|
||||
return
|
||||
try:
|
||||
(when, said) = self.db.seen(channel, id)
|
||||
(when, said) = self.db.seen(channel, user.id)
|
||||
irc.reply('%s was last seen here %s ago saying: %s' %
|
||||
(name, utils.timeElapsed(time.time()-when), said))
|
||||
(user.name, utils.timeElapsed(time.time()-when), said))
|
||||
except KeyError:
|
||||
irc.reply('I have not seen %s.' % name)
|
||||
user = wrap(user, ['channel', 'otherUser'])
|
||||
|
||||
|
||||
Class = Seen
|
||||
|
@ -44,6 +44,7 @@ import getopt
|
||||
|
||||
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
|
||||
@ -138,32 +139,32 @@ class Tail(privmsgs.CapabilityCheckingPrivmsg):
|
||||
for target in self.registryValue('targets'):
|
||||
irc.reply(payload, to=target, notice=notice, private=True)
|
||||
|
||||
def add(self, irc, msg, args):
|
||||
def add(self, irc, msg, args, filename):
|
||||
"""<filename>
|
||||
|
||||
Basically does the equivalent of tail -f to the targets.
|
||||
"""
|
||||
filename = privmsgs.getArgs(args)
|
||||
try:
|
||||
self._add(filename)
|
||||
except EnvironmentError, e:
|
||||
irc.error(utils.exnTostring(e))
|
||||
return
|
||||
irc.replySuccess()
|
||||
add = wrap(add, ['filename'])
|
||||
|
||||
def remove(self, irc, msg, args):
|
||||
def remove(self, irc, msg, args, filename):
|
||||
"""<filename>
|
||||
|
||||
Stops announcing the lines appended to <filename>.
|
||||
"""
|
||||
filename = privmsgs.getArgs(args)
|
||||
try:
|
||||
self._remove(filename)
|
||||
irc.replySuccess()
|
||||
except KeyError:
|
||||
irc.error('I\'m not currently announcing %s.' % filename)
|
||||
remove = wrap(remove, ['filename'])
|
||||
|
||||
def target(self, irc, msg, args):
|
||||
def target(self, irc, msg, args, optlist, targets):
|
||||
"""[--remove] [<target> ...]
|
||||
|
||||
If given no arguments, returns the current list of targets for this
|
||||
@ -171,12 +172,11 @@ class Tail(privmsgs.CapabilityCheckingPrivmsg):
|
||||
the current list of targets. If given --remove and any number of
|
||||
targets, will remove those targets from the current list of targets.
|
||||
"""
|
||||
(optlist, args) = getopt.getopt(args, '', ['remove'])
|
||||
remove = False
|
||||
for (option, arg) in optlist:
|
||||
if option == '--remove':
|
||||
if option == 'remove':
|
||||
remove = True
|
||||
if not args:
|
||||
if not targets:
|
||||
L = self.registryValue('targets')
|
||||
if L:
|
||||
utils.sortBy(ircutils.toLower, L)
|
||||
@ -185,6 +185,8 @@ class Tail(privmsgs.CapabilityCheckingPrivmsg):
|
||||
irc.reply('I\'m not currently targeting anywhere.')
|
||||
elif remove:
|
||||
pass #XXX
|
||||
|
||||
target = wrap(target, [getopts({'remove': ''}), any('something')])
|
||||
|
||||
|
||||
Class = Tail
|
||||
|
@ -49,6 +49,7 @@ import struct
|
||||
|
||||
import supybot.conf as conf
|
||||
import supybot.utils as utils
|
||||
from supybot.commands import *
|
||||
import supybot.privmsgs as privmsgs
|
||||
import supybot.registry as registry
|
||||
import supybot.callbacks as callbacks
|
||||
@ -121,12 +122,11 @@ conf.registerGlobalValue(conf.supybot.plugins.Unix.wtf, 'command',
|
||||
|
||||
|
||||
class Unix(callbacks.Privmsg):
|
||||
def errno(self, irc, msg, args):
|
||||
def errno(self, irc, msg, args, s):
|
||||
"""<error number or code>
|
||||
|
||||
Returns the number of an errno code, or the errno code of a number.
|
||||
"""
|
||||
s = privmsgs.getArgs(args)
|
||||
try:
|
||||
i = int(s)
|
||||
name = errno.errorcode[i]
|
||||
@ -140,6 +140,7 @@ class Unix(callbacks.Privmsg):
|
||||
except KeyError:
|
||||
name = '(unknown)'
|
||||
irc.reply('%s (#%s): %s' % (name, i, os.strerror(i)))
|
||||
errno = wrap(errno, ['something'])
|
||||
|
||||
def progstats(self, irc, msg, args):
|
||||
"""takes no arguments
|
||||
@ -154,10 +155,10 @@ class Unix(callbacks.Privmsg):
|
||||
Returns the current pid of the process for this Supybot.
|
||||
"""
|
||||
irc.reply(str(os.getpid()), private=True)
|
||||
pid = privmsgs.checkCapability(pid, 'owner')
|
||||
pid = wrap(pid, [('checkCapability', 'owner')])
|
||||
|
||||
_cryptre = re.compile(r'[./0-9A-Za-z]')
|
||||
def crypt(self, irc, msg, args):
|
||||
def crypt(self, irc, msg, args, password, salt):
|
||||
"""<password> [<salt>]
|
||||
|
||||
Returns the resulting of doing a crypt() on <password> If <salt> is
|
||||
@ -170,12 +171,12 @@ class Unix(callbacks.Privmsg):
|
||||
while self._cryptre.sub('', s) != '':
|
||||
s = struct.pack('<h', random.randrange(2**16))
|
||||
return s
|
||||
(password, salt) = privmsgs.getArgs(args, optional=1)
|
||||
if salt == '':
|
||||
if not salt:
|
||||
salt = makeSalt()
|
||||
irc.reply(crypt.crypt(password, salt))
|
||||
crypt = wrap(crypt, ['something', optional('something')])
|
||||
|
||||
def spell(self, irc, msg, args):
|
||||
def spell(self, irc, msg, args, word):
|
||||
"""<word>
|
||||
|
||||
Returns the result of passing <word> to aspell/ispell. The results
|
||||
@ -189,7 +190,6 @@ class Unix(callbacks.Privmsg):
|
||||
'installed on this computer. If one is installed, '
|
||||
'reconfigure supybot.plugins.Unix.spell.command '
|
||||
'appropriately.', Raise=True)
|
||||
word = privmsgs.getArgs(args)
|
||||
if word and not word[0].isalpha():
|
||||
irc.error('<word> must begin with an alphabet character.')
|
||||
return
|
||||
@ -228,6 +228,7 @@ class Unix(callbacks.Privmsg):
|
||||
else:
|
||||
resp = 'Something unexpected was seen in the [ai]spell output.'
|
||||
irc.reply(resp)
|
||||
spell = wrap(spell, ['something'])
|
||||
|
||||
def fortune(self, irc, msg, args):
|
||||
"""takes no arguments
|
||||
@ -259,7 +260,7 @@ class Unix(callbacks.Privmsg):
|
||||
'supybot.plugins.Unix.fortune.command configuration '
|
||||
'variable appropriately.')
|
||||
|
||||
def wtf(self, irc, msg, args):
|
||||
def wtf(self, irc, msg, args, _, something):
|
||||
"""[is] <something>
|
||||
|
||||
Returns wtf <something> is. 'wtf' is a *nix command that first
|
||||
@ -268,9 +269,6 @@ class Unix(callbacks.Privmsg):
|
||||
"""
|
||||
wtfCmd = self.registryValue('wtf.command')
|
||||
if wtfCmd:
|
||||
if args and args[0] == 'is':
|
||||
del args[0]
|
||||
something = privmsgs.getArgs(args)
|
||||
something = something.rstrip('?')
|
||||
(r, w) = popen2.popen4([wtfCmd, something])
|
||||
try:
|
||||
@ -284,6 +282,7 @@ class Unix(callbacks.Privmsg):
|
||||
'If it is installed on this system, reconfigure the '
|
||||
'supybot.plugins.Unix.wtf.command configuration '
|
||||
'variable appropriately.')
|
||||
wtf = wrap(wtf, [optional(('literal', ['is'])), 'something'])
|
||||
|
||||
|
||||
Class = Unix
|
||||
|
Loading…
Reference in New Issue
Block a user