irc: Add help functionality for service commands.
patch 093705f786069ded6ba780f3dc2b53c928b6abbe
Author: E. Bosch <presidev@AT@gmail.com>
Date: Sun Mar 6 02:36:51 CET 2022
* irc: Add help functionality for service commands.
Use tuples for single or multiple lines (output) from commands.
hunk ./irc.py 386
- await self.send_msg(self.service_user, user.irc_nick, reply)
+ for reply_line in reply:
+ await self.send_msg(self.service_user, user.irc_nick, reply_line)
hunk ./service.py 12
- {
- # Command Handler Arguments Min Max
- 'help': (self.handle_command_help, 0, 0),
+ { # Command Handler Arguments Min Max
+ 'help': (self.handle_command_help, 0, 1),
hunk ./service.py 24
- reply = 'Wrong number of arguments'
+ reply = ('Wrong number of arguments',)
hunk ./service.py 28
- reply = 'Unknown command'
+ reply = ('Unknown command',)
hunk ./service.py 32
- def handle_command_help(self):
- return 'help'
+ def handle_command_help(self, help_command=None, help=None):
+
+ start_help = ('*** Telegram Service Help ***',)
+ end_help = ('*** End of Help ***',)
+
+ if not help_command or help_command == 'help':
+ help_text = start_help
+ help_text += \
+ (
+ 'This service contains specific Telegram commands that irgramd',
+ 'cannot map to IRC commands. The following commands are available:',
+ )
+ for command in self.commands.values():
+ handler = command[0]
+ if handler == self.handle_command_help: break
+ help_text += handler(help=HELP.brief)
+ help_text += \
+ (
+ 'If you need more information about a specific command you can use',
+ 'help <command>',
+ )
+ help_text += end_help
+ elif help_command in self.commands.keys():
+ handler = self.commands[help_command][0]
+ help_text = start_help
+ help_text += handler(help=HELP.desc)
+ help_text += end_help
+ else:
+ help_text = ('help: Unknown command',)
+ return help_text
+
+
+class HELP:
+ desc = 1
+ brief = 2