Exemplo n.º 1
0
 def toggle_standalone(self, bot, update, user_data):
     chat_id = user_data['chat_id']
     new_state = not Cache.chat_is_standalone(chat_id)
     Cache.chat_set_standalone(chat_id, new_state)
     self.send_or_edit(
         bot, user_data, update.callback_query.message,
         '%s global handlers' % ('Disabled' if new_state else 'Enabled'))
     return ConversationHandler.END
Exemplo n.º 2
0
    def edit_chat(self, bot, update, user_data):
        query = update.callback_query
        chat_id = query.data
        user_data['chat_id'] = chat_id
        chat_name = 'global handlers' if chat_id == HandlerGroup.GLOBAL else Cache.get_chat_title(
            chat_id)

        toggle_global_text = '%s global handlers' % (
            'Enable' if Cache.chat_is_standalone(chat_id) else 'Disable')

        buttons = [[
            InlineKeyboardButton(text='Add a handler',
                                 callback_data=str(self.ADD)),
            InlineKeyboardButton(text='Remove handler',
                                 callback_data=str(self.REMOVE))
        ],
                   [
                       InlineKeyboardButton(text='Edit a handler',
                                            callback_data=str(self.EDIT)),
                       InlineKeyboardButton(text='Copy a handler',
                                            callback_data=str(self.COPY))
                   ]]
        toggle_button = [[
            InlineKeyboardButton(text=toggle_global_text,
                                 callback_data=str(self.TOGGLE))
        ]] if chat_id != HandlerGroup.GLOBAL else []
        exit_button = [[
            InlineKeyboardButton(text='Exit', callback_data=str(self.EXIT))
        ]]

        bot.edit_message_text(
            chat_id=query.message.chat_id,
            message_id=query.message.message_id,
            text='Select what to configure for chat \'%s\'' % chat_name,
            reply_markup=InlineKeyboardMarkup(buttons + toggle_button +
                                              exit_button))
        return self.SELECT_ACTION