mirror of https://github.com/Mikaela/Limnoria.git
Added pydoc command
This commit is contained in:
parent
7e8aab6619
commit
952b7b6517
|
@ -56,6 +56,7 @@ Commands include:
|
|||
last
|
||||
lastfrom
|
||||
lithp
|
||||
pydoc
|
||||
"""
|
||||
|
||||
from baseplugin import *
|
||||
|
@ -63,6 +64,8 @@ from baseplugin import *
|
|||
import os
|
||||
import gc
|
||||
import re
|
||||
import imp
|
||||
import sys
|
||||
import new
|
||||
import md5
|
||||
import sha
|
||||
|
@ -426,6 +429,42 @@ class FunCommands(callbacks.Privmsg):
|
|||
return
|
||||
irc.error(msg, 'I don\'t remember a message from that person.')
|
||||
|
||||
modulechars = '%s%s%s' % (string.ascii_letters, string.digits, '_.')
|
||||
def pydoc(self, irc, msg, args):
|
||||
"""<python function>
|
||||
|
||||
Returns the __doc__ string for a given Python function.
|
||||
"""
|
||||
funcname = privmsgs.getArgs(args)
|
||||
if funcname.translate(string.ascii, self.modulechars) != '':
|
||||
irc.error('That\'s not a valid module or function name.')
|
||||
return
|
||||
if '.' in funcname:
|
||||
parts = funcname.split('.')
|
||||
module = '.'.join(parts[:-1])
|
||||
if module not in sys.modules:
|
||||
path = os.path.dirname(os.__file__)
|
||||
for name in parts[:-1]:
|
||||
try:
|
||||
info = imp.find_module(name, path)
|
||||
newmodule = imp.load_module(name, *info)
|
||||
path = newmodule.__path__
|
||||
info[1].close()
|
||||
except ImportError:
|
||||
irc.error(msg, 'No such module %s exists.' % module)
|
||||
return
|
||||
try:
|
||||
s = eval(funcname + '.__doc__')
|
||||
s = s.replace('\n\n', '. ')
|
||||
s = s.replace('\n', ' ')
|
||||
except NameError:
|
||||
s = 'No such function exists.'
|
||||
except AttributeError:
|
||||
s = 'That function has no documentation.'
|
||||
irc.reply(msg, s)
|
||||
|
||||
|
||||
|
||||
|
||||
Class = FunCommands
|
||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||
|
|
Loading…
Reference in New Issue