Exemplo n.º 1
0
def append_restricted_delete_button(
        update, chat_data, reply_markup
) -> Tuple[Optional[ReplyMarkup], Callable[[Message], None]]:
    uid = update.effective_user.id
    command_mid = update.effective_message.message_id

    if not util.is_group_message(update) or not isinstance(
            reply_markup, InlineKeyboardMarkup):
        return reply_markup, lambda _: None

    def append_callback(message):
        if message is None:  # No message was saved
            return
        if isinstance(message, Message):
            mid = message.message_id
        else:
            mid = message
        deletions_pending = chat_data.get("deletions_pending", dict())
        if not deletions_pending.get(mid):
            deletions_pending[mid] = dict(user_id=uid, command_id=command_mid)
            chat_data["deletions_pending"] = deletions_pending

    buttons = reply_markup.inline_keyboard
    buttons.append([
        InlineKeyboardButton(
            captions.random_done_delete(),
            callback_data=util.callback_for_action(
                CallbackActions.DELETE_CONVERSATION),
        )
    ])
    reply_markup.inline_keyboard = buttons
    return reply_markup, append_callback
Exemplo n.º 2
0
def append_delete_button(update, chat_data, reply_markup):
    uid = update.effective_user.id
    cid = update.effective_chat.id
    command_mid = update.effective_message.message_id
    if not isinstance(reply_markup, InlineKeyboardMarkup):
        return reply_markup, callable
    if cid != settings.BOTLISTCHAT_ID:
        return reply_markup, callable

    def append_callback(message):
        if message is None:
            return
        if isinstance(message, Message):
            mid = message.message_id
        else:
            mid = message
        deletions_pending = chat_data.get('deletions_pending', dict())
        if not deletions_pending.get(mid):
            deletions_pending[mid] = dict(user_id=uid, command_id=command_mid)
            chat_data['deletions_pending'] = deletions_pending

    buttons = reply_markup.inline_keyboard
    buttons.append([
        InlineKeyboardButton(captions.random_done_delete(),
                             callback_data=util.callback_for_action(
                                 CallbackActions.DELETE_CONVERSATION))
    ])
    reply_markup.inline_keyboard = buttons
    return reply_markup, append_callback
Exemplo n.º 3
0
def append_free_delete_button(update, reply_markup) -> Optional[ReplyMarkup]:
    if not util.is_group_message(update) or not isinstance(
            reply_markup, InlineKeyboardMarkup):
        return reply_markup

    buttons = reply_markup.inline_keyboard
    buttons.append([
        InlineKeyboardButton(
            captions.random_done_delete(),
            callback_data=util.callback_for_action(
                CallbackActions.DELETE_CONVERSATION),
        )
    ])

    reply_markup.inline_keyboard = buttons
    return reply_markup