]>
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',
16 lib
= modlib
.modlib(__name__
)
17 modstart
= lib
.modstart
24 # ! this is part of this module's API, called from modlib.help()
25 # this function only handles the command name and aliases - the rest is passed directly to _reghelp()
26 def reghelp(func
, *args
, **kwargs
):
38 if 'syntax' in kwargs
:
39 syntax
= kwargs
['syntax']
40 if 'shorthelp' in kwargs
:
41 shorthelp
= kwargs
['shorthelp']
42 if 'longhelps' in kwargs
:
43 longhelps
= kwargs
['longhelps']
45 if syntax
is None: syntax
= ""
46 if shorthelp
is None: shorthelp
= ""
49 func
.shorthelp
= shorthelp
50 func
.longhelps
= longhelps
55 def dereghelp(func
, *args
, **kwargs
):
60 class HelpLine(object):
61 def __init__(self
, cmd
, syntax
, shorthelp
, admin
, level
, module
):
64 self
.shorthelp
= shorthelp
69 def __cmp__(self
, other
):
70 if self
.level
== other
.level
:
71 return cmp(self
.cmd
, other
.cmd
)
73 return cmp(self
.level
, other
.level
)
78 return "%-35s(%3s) - %-10s - %-50s" % (self
.cmd
+' '+self
.syntax
, self
.level
, self
.module
, self
.shorthelp
)
80 return "%-40s - %-50s" % (self
.cmd
+' '+self
.syntax
, self
.shorthelp
)
82 @lib.hook(needchan
=False)
83 @lib.help('[<command>]', 'lists commands or describes a command')
84 def help(bot
, user
, chan
, realtarget
, *args
):
85 if len(args
) == 0: # list commands
87 for func
in helps
.itervalues():
88 if user
.glevel
>= func
.reqglevel
:
89 lines
.append(HelpLine(func
.cmd
[0], func
.syntax
, func
.shorthelp
, (user
.glevel
> 0), func
.reqglevel
, func
.__module
__))
91 for c
in func
.cmd
[1:]:
92 lines
.append(HelpLine(c
, "", "Alias of %s" % (func
.cmd
[0]), (user
.glevel
> 0), func
.reqglevel
, func
.__module
__))
93 for line
in sorted(lines
):
94 bot
.slowmsg(user
, str(line
))
95 bot
.slowmsg(user
, "End of command listing.")
96 else: # help for a specific command/topic
97 cmd
= str(' '.join(args
))
98 if cmd
in cmds
and user
.glevel
>= cmds
[cmd
].reqglevel
:
100 bot
.slowmsg(user
, str(HelpLine(func
.cmd
[0], func
.syntax
, func
.shorthelp
, (user
.glevel
> 0), func
.reqglevel
, func
.__module
__)))
101 for line
in func
.longhelps
:
102 bot
.slowmsg(user
, " %s" % (line
))
103 bot
.slowmsg(user
, "End of help for %s." % (func
.cmd
[0]))
105 if len(func
.cmd
) > 1:
106 bot
.slowmsg(user
, " Aliases: %s" % (' '.join(func
.cmd
[1:])))
108 bot
.slowmsg(user
, "No help found for %s" % (cmd
))