forked from DesertBot/DesertBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Help.py
45 lines (37 loc) · 1.89 KB
/
Help.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from twisted.plugin import IPlugin
from desertbot.moduleinterface import IModule
from desertbot.modules.commandinterface import BotCommand
from zope.interface import implementer
from desertbot.message import IRCMessage
from desertbot.response import IRCResponse, ResponseType
@implementer(IPlugin, IModule)
class Help(BotCommand):
def triggers(self):
return['help', 'module', 'modules']
def help(self, query):
return ('help/module(s) (<module>) - returns a list of loaded modules,'
' or the help text of a particular module if one is specified')
def execute(self, message: IRCMessage):
moduleHandler = self.bot.moduleHandler
if message.parameterList:
helpStr = moduleHandler.runActionUntilValue('help', message.parameterList)
if isinstance(helpStr, str):
return IRCResponse(ResponseType.Say, helpStr, message.replyTo)
elif isinstance(helpStr, list):
return [IRCResponse(ResponseType.Say, line, message.replyTo) for line in helpStr]
else:
return IRCResponse(ResponseType.Say,
'"{0}" not found, try "{1}" without parameters'
' to see a list of loaded module names'
.format(message.parameterList[0], message.command),
message.replyTo)
else:
modules = ', '.join(sorted(moduleHandler.modules, key=lambda s: s.lower()))
return [IRCResponse(ResponseType.Say,
"Modules loaded are"
" (use 'help <module>' to get help for that module):",
message.replyTo),
IRCResponse(ResponseType.Say,
modules,
message.replyTo)]
help = Help()