mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-04 18:29:21 +01:00
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):
|
def list(self, irc, msg, args):
|
||||||
"""[<module name>]
|
"""[<module name>]
|
||||||
|
|
||||||
Lists the commands available in the given module. If no module is
|
Lists the commands available in the given plugin. If no plugin is
|
||||||
given, lists the public modules available.
|
given, lists the public plugins available.
|
||||||
"""
|
"""
|
||||||
name = privmsgs.getArgs(args, needed=0, optional=1)
|
name = privmsgs.getArgs(args, needed=0, optional=1)
|
||||||
name = name.lower()
|
name = name.lower()
|
||||||
@ -67,15 +67,15 @@ class MiscCommands(callbacks.Privmsg):
|
|||||||
commands.sort()
|
commands.sort()
|
||||||
irc.reply(msg, ', '.join(commands))
|
irc.reply(msg, ', '.join(commands))
|
||||||
return
|
return
|
||||||
irc.error(msg, 'There is no module named %s, ' \
|
irc.error(msg, 'There is no plugin named %s, ' \
|
||||||
'or that module has no commands.' % name)
|
'or that plugin has no commands.' % name)
|
||||||
|
|
||||||
def help(self, irc, msg, args):
|
def help(self, irc, msg, args):
|
||||||
"""<command>
|
"""<command>
|
||||||
|
|
||||||
Gives the help for a specific command. To find commands,
|
Gives the help for a specific command. To find commands,
|
||||||
use the 'list' command to go see the commands offered by a module.
|
use the 'list' command to go see the commands offered by a plugin.
|
||||||
The 'list' command by itself will show you what modules have commands.
|
The 'list' command by itself will show you what plugins have commands.
|
||||||
"""
|
"""
|
||||||
command = privmsgs.getArgs(args, needed=0, optional=1)
|
command = privmsgs.getArgs(args, needed=0, optional=1)
|
||||||
if not command:
|
if not command:
|
||||||
@ -100,17 +100,25 @@ class MiscCommands(callbacks.Privmsg):
|
|||||||
if hasattr(cb, '__doc__') and cb.__doc__ is not None:
|
if hasattr(cb, '__doc__') and cb.__doc__ is not None:
|
||||||
doclines = cb.__doc__.strip().splitlines()
|
doclines = cb.__doc__.strip().splitlines()
|
||||||
help = ' '.join(map(str.strip, doclines))
|
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)
|
irc.reply(msg, help)
|
||||||
else:
|
else:
|
||||||
module = __import__(cb.__module__)
|
module = __import__(cb.__module__)
|
||||||
if hasattr(module, '__doc__') and module.__doc__:
|
if hasattr(module, '__doc__') and module.__doc__:
|
||||||
doclines = module.__doc__.strip().splitlines()
|
doclines = module.__doc__.strip().splitlines()
|
||||||
help = ' '.join(map(str.strip, doclines))
|
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)
|
irc.reply(msg, help)
|
||||||
else:
|
else:
|
||||||
irc.error(msg, 'That callback has no help.')
|
irc.error(msg, 'That plugin has no help.')
|
||||||
else:
|
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):
|
def morehelp(self, irc, msg, args):
|
||||||
"""<command>
|
"""<command>
|
||||||
@ -189,10 +197,10 @@ class MiscCommands(callbacks.Privmsg):
|
|||||||
"""
|
"""
|
||||||
irc.reply(msg, repr(conf.prefixChars))
|
irc.reply(msg, repr(conf.prefixChars))
|
||||||
|
|
||||||
def moduleof(self, irc, msg, args):
|
def plugin(self, irc, msg, args):
|
||||||
"""<command>
|
"""<command>
|
||||||
|
|
||||||
Returns the module <command> is in.
|
Returns the plugin <command> is in.
|
||||||
"""
|
"""
|
||||||
command = callbacks.canonicalName(privmsgs.getArgs(args))
|
command = callbacks.canonicalName(privmsgs.getArgs(args))
|
||||||
cb = irc.findCallback(command)
|
cb = irc.findCallback(command)
|
||||||
@ -201,6 +209,21 @@ class MiscCommands(callbacks.Privmsg):
|
|||||||
else:
|
else:
|
||||||
irc.error(msg, 'There is no such command %s' % command)
|
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
|
Class = MiscCommands
|
||||||
|
|
||||||
|
@ -47,6 +47,7 @@ import time
|
|||||||
import shlex
|
import shlex
|
||||||
import getopt
|
import getopt
|
||||||
import inspect
|
import inspect
|
||||||
|
import textwrap
|
||||||
import threading
|
import threading
|
||||||
from cStringIO import StringIO
|
from cStringIO import StringIO
|
||||||
|
|
||||||
@ -65,6 +66,7 @@ import debug
|
|||||||
###
|
###
|
||||||
def addressed(nick, msg):
|
def addressed(nick, msg):
|
||||||
"""If msg is addressed to 'name', returns the portion after the address.
|
"""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[0] == nick:
|
||||||
if msg.args[1][0] in conf.prefixChars:
|
if msg.args[1][0] in conf.prefixChars:
|
||||||
@ -336,10 +338,32 @@ class IrcObjectProxy:
|
|||||||
if isinstance(self.irc, self.__class__):
|
if isinstance(self.irc, self.__class__):
|
||||||
self.irc.reply(msg, s)
|
self.irc.reply(msg, s)
|
||||||
else:
|
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)
|
s = ircutils.safeArgument(s)
|
||||||
if len(s) + len(self.irc.prefix) > 512:
|
allowedLength = 461 - len(self.irc.prefix)
|
||||||
s = 'My response would\'ve been too long.'
|
msgs = textwrap.wrap(s, allowedLength)
|
||||||
self.irc.queueMsg(reply(msg, s))
|
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:
|
else:
|
||||||
self.args[self.counter] = s
|
self.args[self.counter] = s
|
||||||
self.evalArgs()
|
self.evalArgs()
|
||||||
@ -445,6 +469,7 @@ class Privmsg(irclib.IrcCallback):
|
|||||||
threaded = False
|
threaded = False
|
||||||
public = True
|
public = True
|
||||||
commandArgs = ['self', 'irc', 'msg', 'args']
|
commandArgs = ['self', 'irc', 'msg', 'args']
|
||||||
|
_mores = {} # This must be class-scope, so all subclasses use the same one.
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.rateLimiter = RateLimiter()
|
self.rateLimiter = RateLimiter()
|
||||||
self.Proxy = IrcObjectProxy
|
self.Proxy = IrcObjectProxy
|
||||||
|
Loading…
Reference in New Issue
Block a user