]>
jfr.im git - erebus.git/blob - modules/help.py
1 # Erebus IRC bot - Author: Erebus Team
3 # This file is released into the public domain; see http://unlicense.org/
7 'author': 'Erebus Team',
8 'license': 'public domain',
9 'compatible': [1], # compatible module API versions
10 'depends': [], # other modules required to work properly?
15 lib
= modlib
.modlib(__name__
)
16 modstart
= lib
.modstart
23 # ! this is part of this module's API, called from modlib.help()
24 # this function only handles the command name and aliases - the rest is passed directly to _reghelp()
25 def reghelp(func
, *args
, **kwargs
):
37 if 'syntax' in kwargs
:
38 syntax
= kwargs
['syntax']
39 if 'shorthelp' in kwargs
:
40 shorthelp
= kwargs
['shorthelp']
41 if 'longhelps' in kwargs
:
42 longhelps
= kwargs
['longhelps']
44 if syntax
is None: syntax
= ""
45 if shorthelp
is None: shorthelp
= ""
48 func
.shorthelp
= shorthelp
49 func
.longhelps
= longhelps
54 def dereghelp(func
, *args
, **kwargs
):
59 class HelpLine(object):
60 def __init__(self
, cmd
, syntax
, shorthelp
, admin
, level
, module
):
63 self
.shorthelp
= shorthelp
68 def __cmp__(self
, other
):
69 if self
.level
== other
.level
:
70 return cmp(self
.cmd
, other
.cmd
)
72 return cmp(self
.level
, other
.level
)
77 return "%-35s(%3s) - %-10s - %-50s" % (self
.cmd
+' '+self
.syntax
, self
.level
, self
.module
, self
.shorthelp
)
79 return "%-40s - %-50s" % (self
.cmd
+' '+self
.syntax
, self
.shorthelp
)
81 @lib.hook(needchan
=False)
82 @lib.help('[<command>]', 'lists commands or describes a command')
83 def help(bot
, user
, chan
, realtarget
, *args
):
84 if len(args
) == 0: # list commands
86 for func
in helps
.itervalues():
87 if user
.glevel
>= func
.reqglevel
:
88 lines
.append(HelpLine(func
.cmd
[0], func
.syntax
, func
.shorthelp
, (user
.glevel
> 0), func
.reqglevel
, func
.__module
__))
90 for c
in func
.cmd
[1:]:
91 lines
.append(HelpLine(c
, "", "Alias of %s" % (func
.cmd
[0]), (user
.glevel
> 0), func
.reqglevel
, func
.__module
__))
92 for line
in sorted(lines
):
93 bot
.slowmsg(user
, str(line
))
94 bot
.slowmsg(user
, "End of command listing.")
95 else: # help for a specific command/topic
96 cmd
= str(' '.join(args
))
97 if cmd
in cmds
and user
.glevel
>= cmds
[cmd
].reqglevel
:
99 bot
.slowmsg(user
, str(HelpLine(func
.cmd
[0], func
.syntax
, func
.shorthelp
, (user
.glevel
> 0), func
.reqglevel
, func
.__module
__)))
100 for line
in func
.longhelps
:
101 bot
.slowmsg(user
, " %s" % (line
))
102 bot
.slowmsg(user
, "End of help for %s." % (func
.cmd
[0]))
104 if len(func
.cmd
) > 1:
105 bot
.slowmsg(user
, " Aliases: %s" % (' '.join(func
.cmd
[1:])))
107 bot
.slowmsg(user
, "No help found for %s" % (cmd
))