pep 8 command_handler.py

This commit is contained in:
mattijn 2015-09-07 04:17:43 +02:00
parent ea5c690e7a
commit 5b8f41b3c1

View file

@ -133,22 +133,23 @@ class CommandHandlerWithHelp(CommandHandler):
self._help_before_list = '' # text with information about the bot
self._help_after_list = '' # a footer
self._help_list_title = 'These are the commands:' # the title of the list
self._help_extra_message = 'These commands are only usefull to the developer.'
self._help_extra_message = 'These commands are only usefull to the developer.'
self.is_reply = True
self.command_start = self.command_help
self.skip_in_help = []
def command_helpextra(self,update):
""" The commands in here are only usefull to the developer of the bot"""
command_functions = [attr[1] for attr in getmembers(self, predicate=ismethod) if attr[0][:8] == 'command_' and attr[0] in self.skip_in_help]
command_functions = [attr[1] for attr in getmembers(self, predicate=ismethod) if attr[0][:8] == 'command_' and
attr[0] in self.skip_in_help]
chat_id = update.message.chat.id
help_message = self._help_extra_message +'\n'
help_message = self._help_extra_message + '\n'
for command_function in command_functions:
if command_function.__doc__ is not None:
help_message += ' /' + command_function.__name__[8:] + ' - ' + command_function.__doc__ + '\n'
else:
help_message += ' /' + command_function.__name__[8:] + ' - ' + '\n'
self.bot.sendMessage(chat_id=chat_id,text=help_message)
self.bot.sendMessage(chat_id=chat_id, text=help_message)
def _generate_help(self):
""" Generate a string which can be send as a help file.
@ -158,7 +159,6 @@ class CommandHandlerWithHelp(CommandHandler):
command to the telegram user.
"""
help_message = self._help_title + '\n\n'
help_message += self._help_before_list + '\n\n'
help_message += self._help_list_title + '\n'
@ -168,7 +168,8 @@ class CommandHandlerWithHelp(CommandHandler):
return help_message
def _generate_help_list(self):
command_functions = [attr[1] for attr in getmembers(self, predicate=ismethod) if attr[0][:8] == 'command_' and attr[0] not in self.skip_in_help]
command_functions = [attr[1] for attr in getmembers(self, predicate=ismethod) if attr[0][:8] == 'command_' and
attr[0] not in self.skip_in_help]
help_message = ''
for command_function in command_functions:
if command_function.__doc__ is not None:
@ -204,20 +205,23 @@ class CommandHandlerWithFatherCommand(CommandHandler):
self.skip_in_help = ['command_father']
def command_father(self, update):
"""Gives you the commands you need to setup this bot. in telegram.me/BotFather"""
chat_id = update.message.chat.id
self.bot.sendMessage(chat_id=chat_id, text='Send the following messages to telegram.me/BotFather')
self.bot.sendMessage(chat_id=chat_id, text='/setcommands')
self.bot.sendMessage(chat_id=chat_id, text='@' + self.bot.getMe()['username'])
commands = ''
command_functions = [attr[1] for attr in getmembers(self, predicate=ismethod) if attr[0][:8] == 'command_' and attr[0] not in self.skip_in_help]
command_functions = [attr[1] for attr in getmembers(self, predicate=ismethod) if attr[0][:8] == 'command_' and
attr[0] not in self.skip_in_help]
for command_function in command_functions:
if command_function.__doc__ is not None:
commands += command_function.__name__[8:] + ' - ' + command_function.__doc__ + '\n'
commands += command_function.__name__[8:] + ' - ' + command_function.__doc__ + '\n'
else:
commands += command_function.__name__[8:] + ' - ' + '\n'
commands += command_function.__name__[8:] + ' - ' + '\n'
self.bot.sendMessage(chat_id=chat_id, text=commands)
class CommandHandlerWithHelpAndFather(CommandHandlerWithFatherCommand, CommandHandlerWithHelp):
"""A class that combines CommandHandlerWithHelp and CommandHandlerWithFatherCommand.
"""