mirror of https://github.com/Mikaela/Limnoria.git
Added the more command.
This commit is contained in:
parent
bb4290537f
commit
3873b351f4
|
@ -45,8 +45,8 @@ class MiscCommands(callbacks.Privmsg):
|
|||
def list(self, irc, msg, args):
|
||||
"""[<module name>]
|
||||
|
||||
Lists the commands available in the given module. If no module is
|
||||
given, lists the public modules available.
|
||||
Lists the commands available in the given plugin. If no plugin is
|
||||
given, lists the public plugins available.
|
||||
"""
|
||||
name = privmsgs.getArgs(args, needed=0, optional=1)
|
||||
name = name.lower()
|
||||
|
@ -67,15 +67,15 @@ class MiscCommands(callbacks.Privmsg):
|
|||
commands.sort()
|
||||
irc.reply(msg, ', '.join(commands))
|
||||
return
|
||||
irc.error(msg, 'There is no module named %s, ' \
|
||||
'or that module has no commands.' % name)
|
||||
irc.error(msg, 'There is no plugin named %s, ' \
|
||||
'or that plugin has no commands.' % name)
|
||||
|
||||
def help(self, irc, msg, args):
|
||||
"""<command>
|
||||
|
||||
Gives the help for a specific command. To find commands,
|
||||
use the 'list' command to go see the commands offered by a module.
|
||||
The 'list' command by itself will show you what modules have commands.
|
||||
use the 'list' command to go see the commands offered by a plugin.
|
||||
The 'list' command by itself will show you what plugins have commands.
|
||||
"""
|
||||
command = privmsgs.getArgs(args, needed=0, optional=1)
|
||||
if not command:
|
||||
|
@ -100,17 +100,25 @@ class MiscCommands(callbacks.Privmsg):
|
|||
if hasattr(cb, '__doc__') and cb.__doc__ is not None:
|
||||
doclines = cb.__doc__.strip().splitlines()
|
||||
help = ' '.join(map(str.strip, doclines))
|
||||
if not help.endswith('.'):
|
||||
help += '.'
|
||||
help += ' Use the list command to see what commands ' \
|
||||
'this plugin supports.'
|
||||
irc.reply(msg, help)
|
||||
else:
|
||||
module = __import__(cb.__module__)
|
||||
if hasattr(module, '__doc__') and module.__doc__:
|
||||
doclines = module.__doc__.strip().splitlines()
|
||||
help = ' '.join(map(str.strip, doclines))
|
||||
if not help.endswith('.'):
|
||||
help += '.'
|
||||
help += ' Use the list command to see what ' \
|
||||
'commands this plugin supports.'
|
||||
irc.reply(msg, help)
|
||||
else:
|
||||
irc.error(msg, 'That callback has no help.')
|
||||
irc.error(msg, 'That plugin has no help.')
|
||||
else:
|
||||
irc.error(msg, 'There is no such command or callback.')
|
||||
irc.error(msg, 'There is no such command or plugin.')
|
||||
|
||||
def morehelp(self, irc, msg, args):
|
||||
"""<command>
|
||||
|
@ -189,10 +197,10 @@ class MiscCommands(callbacks.Privmsg):
|
|||
"""
|
||||
irc.reply(msg, repr(conf.prefixChars))
|
||||
|
||||
def moduleof(self, irc, msg, args):
|
||||
def plugin(self, irc, msg, args):
|
||||
"""<command>
|
||||
|
||||
Returns the module <command> is in.
|
||||
Returns the plugin <command> is in.
|
||||
"""
|
||||
command = callbacks.canonicalName(privmsgs.getArgs(args))
|
||||
cb = irc.findCallback(command)
|
||||
|
@ -201,6 +209,21 @@ class MiscCommands(callbacks.Privmsg):
|
|||
else:
|
||||
irc.error(msg, 'There is no such command %s' % command)
|
||||
|
||||
def more(self, irc, msg, args):
|
||||
"""takes no arguments
|
||||
|
||||
If the last command was truncated due to IRC message length
|
||||
limitations, returns the next chunk of the result of the last command.
|
||||
"""
|
||||
userHostmask = msg.prefix.split('!', 1)[1]
|
||||
try:
|
||||
chunk = self._mores[userHostmask].pop()
|
||||
irc.reply(msg, chunk)
|
||||
except KeyError:
|
||||
irc.error(msg, 'You haven\'t asked me a command!')
|
||||
except IndexError:
|
||||
irc.error(msg, 'That\'s all, there is no more.')
|
||||
|
||||
|
||||
Class = MiscCommands
|
||||
|
||||
|
|
|
@ -47,6 +47,7 @@ import time
|
|||
import shlex
|
||||
import getopt
|
||||
import inspect
|
||||
import textwrap
|
||||
import threading
|
||||
from cStringIO import StringIO
|
||||
|
||||
|
@ -65,6 +66,7 @@ import debug
|
|||
###
|
||||
def addressed(nick, msg):
|
||||
"""If msg is addressed to 'name', returns the portion after the address.
|
||||
Otherwise returns the empty string.
|
||||
"""
|
||||
if msg.args[0] == nick:
|
||||
if msg.args[1][0] in conf.prefixChars:
|
||||
|
@ -336,10 +338,32 @@ class IrcObjectProxy:
|
|||
if isinstance(self.irc, self.__class__):
|
||||
self.irc.reply(msg, s)
|
||||
else:
|
||||
# The size of a PRIVMSG is:
|
||||
# 1 for the colon
|
||||
# len(prefix)
|
||||
# 1 for the space
|
||||
# 7 for the PRIVMSG
|
||||
# 1 for the space
|
||||
# len(target)
|
||||
# 1 for the space
|
||||
# 1 for the colon
|
||||
# len(payload)
|
||||
# 2 for the \r\n
|
||||
# So non-variable stuff it's 1+1+7+1+1+1+2, or 14
|
||||
# We'll estimate the channel length at 30, and we'll know the
|
||||
# prefix length exactly. We also might append the string
|
||||
# " (more)" to the end, so that's 7 more characters.
|
||||
# 512 - 51 == 461.
|
||||
s = ircutils.safeArgument(s)
|
||||
if len(s) + len(self.irc.prefix) > 512:
|
||||
s = 'My response would\'ve been too long.'
|
||||
self.irc.queueMsg(reply(msg, s))
|
||||
allowedLength = 461 - len(self.irc.prefix)
|
||||
msgs = textwrap.wrap(s, allowedLength)
|
||||
msgs.reverse()
|
||||
response = msgs.pop()
|
||||
if msgs:
|
||||
response += ' (more)'
|
||||
mask = msg.prefix.split('!', 1)[1]
|
||||
Privmsg._mores[mask] = msgs
|
||||
self.irc.queueMsg(reply(msg, response))
|
||||
else:
|
||||
self.args[self.counter] = s
|
||||
self.evalArgs()
|
||||
|
@ -445,6 +469,7 @@ class Privmsg(irclib.IrcCallback):
|
|||
threaded = False
|
||||
public = True
|
||||
commandArgs = ['self', 'irc', 'msg', 'args']
|
||||
_mores = {} # This must be class-scope, so all subclasses use the same one.
|
||||
def __init__(self):
|
||||
self.rateLimiter = RateLimiter()
|
||||
self.Proxy = IrcObjectProxy
|
||||
|
|
Loading…
Reference in New Issue