patch 093705f786069ded6ba780f3dc2b53c928b6abbe Author: E. Bosch 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. diff -rN -u old-irgramd/irc.py new-irgramd/irc.py --- old-irgramd/irc.py 2024-10-23 04:32:38.371339773 +0200 +++ new-irgramd/irc.py 2024-10-23 04:32:38.371339773 +0200 @@ -383,7 +383,8 @@ tgl = target.lower() if self.service_user.irc_nick.lower() == tgl: reply = self.service.parse_command(message) - 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) return # Echo channel messages from IRC to other IRC connections # because they won't receive event from Telegram diff -rN -u old-irgramd/service.py new-irgramd/service.py --- old-irgramd/service.py 2024-10-23 04:32:38.371339773 +0200 +++ new-irgramd/service.py 2024-10-23 04:32:38.379339760 +0200 @@ -9,9 +9,8 @@ class service: def __init__(self): self.commands = \ - { - # Command Handler Arguments Min Max - 'help': (self.handle_command_help, 0, 0), + { # Command Handler Arguments Min Max + 'help': (self.handle_command_help, 0, 1), } def parse_command(self, line): @@ -22,13 +21,46 @@ handler, min_args, max_args = self.commands[command] num_words = len(words) if num_words < min_args or num_words > max_args: - reply = 'Wrong number of arguments' + reply = ('Wrong number of arguments',) else: reply = handler(*words) else: - reply = 'Unknown command' + reply = ('Unknown command',) return reply - 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 ', + ) + 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