Ejemplo n.º 1
0
def purge(update, context):
    update.effective_message.reply_text(
        _text[_lang]["mode_select_msg"].replace(
            "replace", _text[_lang]["purge_mode"]) + "\n" +
        _text[_lang]["request_target_folder"],
        reply_markup=_KB.dst_keyboard(update, context),
    )

    return _stage.COOK_FAV_PURGE
Ejemplo n.º 2
0
def copy(update, context):
    _func.mode = "copy"
    call_mode = update.effective_message.text

    if "/copy" == call_mode.strip()[:5]:
        update.effective_message.reply_text(
            _text[_lang]["mode_select_msg"].replace(
                "replace", _text[_lang]["copy_mode"]) + "\n" +
            _text[_lang]["request_dst_target"],
            reply_markup=_KB.dst_keyboard(update, context),
        )

        return GET_DST

    if update.callback_query.data == "copy":
        update.callback_query.edit_message_text(
            _text[_lang]["mode_select_msg"].replace(
                "replace", _text[_lang]["copy_mode"]) + "\n" +
            _text[_lang]["request_dst_target"],
            reply_markup=_KB.dst_keyboard(update, context),
        )

        return GET_DST
Ejemplo n.º 3
0
def dedupe(update, context):
    entry_cmd = update.effective_message.text
    match_cmd = re.search(r"^\/dedupe ([1-9]\d*)$", entry_cmd, flags=re.I)

    if entry_cmd == "/dedupe":
        update.effective_message.reply_text(
            _text[_lang]["mode_select_msg"].replace(
                "replace", _text[_lang]["dedupe_mode"]
            )
            + "\n"
            + _text[_lang]["request_target_folder"],
            reply_markup=_KB.dst_keyboard(update, context),
        )

        return _stage.COOK_FAV_DEDU

    elif match_cmd:
        limit_query = load.db_counters.find_one({"_id": "task_list_id"})
        check_query = match_cmd.group(1)

        if int(check_query) <= limit_query["future_id"]:

            global check_task
            check_task = load.task_list.find_one({"_id": int(check_query)})

            if check_task["status"] == 1:
                update.effective_message.reply_text(
                    _text[_lang]["mode_select_msg"].replace(
                        "replace", _text[_lang]["dedupe_mode"]
                    )
                    + "\n"
                    + _text[_lang]["request_dedupe_mode"],
                    reply_markup=_KB.dedupe_mode_keyboard(),
                )

                return _stage.COOK_ID_DEDU

            elif check_task["status"] == 0:
                update.effective_message.reply_text(
                    _text[_lang]["task_is_in_queue"]
                    + "\n"
                    + _text[_lang]["finished_could_be_dedupe"],
                )

                return ConversationHandler.END

            elif check_task["status"] == 2:
                update.effective_message.reply_text(
                    _text[_lang]["doing"]
                    + "\n"
                    + _text[_lang]["finished_could_be_dedupe"],
                )

                return ConversationHandler.END

        else:
            update.effective_message.reply_text(_text[_lang]["over_limit_to_dedupe"],)

            return ConversationHandler.END

    else:
        update.effective_message.reply_text(_text[_lang]["global_command_error"])
Ejemplo n.º 4
0
def size(update, context):
    entry_cmd = update.effective_message.text
    match_cmd = re.search(r"^\/size ([1-9]\d*)$", entry_cmd, flags=re.I)
    if "/size" == entry_cmd:
        update.effective_message.reply_text(_text[_lang]["request_share_link"])

        return _stage.COOK_ID

    elif match_cmd:
        limit_query = load.db_counters.find_one({"_id": "task_list_id"})
        check_query = match_cmd.group(1)
        size_msg = update.effective_message.reply_text(_text[_lang]["ready_to_size"])
        size_chat_id = size_msg.chat_id
        size_message_id = size_msg.message_id

        if int(check_query) <= limit_query["future_id"]:

            check_task = load.task_list.find_one({"_id": int(check_query)})

            if check_task["status"] == 1:
                if "dst_endpoint_link" and "dst_endpoint_id" in check_task:
                    task_id = str(check_query)
                    task_link = check_task["dst_endpoint_link"]
                    endpoint_id = check_task["dst_endpoint_id"]
                    endpoint_name = check_task["src_name"]

                    progress = _mp(
                        target=_s_payload.owner_size,
                        args=(
                            ns,
                            size_chat_id,
                            size_message_id,
                            task_id,
                            task_link,
                            endpoint_id,
                            endpoint_name,
                        ),
                    )
                    progress.start()

                    context.bot.edit_message_text(
                        chat_id=size_chat_id,
                        message_id=size_message_id,
                        text=_text[_lang]["sizing"],
                    )

                    return ConversationHandler.END

                else:
                    dst_endpoint_id = _gd.get_dst_endpoint_id(
                        _gd(), check_task["dst_id"], check_task["src_name"]
                    )
                    if dst_endpoint_id:
                        dst_endpoint_link = r"https://drive.google.com/open?id={}".format(
                            dst_endpoint_id["id"]
                        )

                        load.task_list.update_one(
                            {"_id": int(check_query)},
                            {
                                "$set": {
                                    "dst_endpoint_id": dst_endpoint_id["id"],
                                    "dst_endpoint_link": dst_endpoint_link,
                                },
                            },
                        )

                        task_id = str(check_query)
                        task_link = dst_endpoint_link
                        endpoint_id = dst_endpoint_id["id"]
                        endpoint_name = check_task["src_name"]

                        progress = _mp(
                            target=_s_payload.owner_size,
                            args=(
                                ns,
                                size_chat_id,
                                size_message_id,
                                task_id,
                                task_link,
                                endpoint_id,
                                endpoint_name,
                            ),
                        )
                        progress.start()

                        context.bot.edit_message_text(
                            chat_id=size_chat_id,
                            message_id=size_message_id,
                            text=_text[_lang]["sizing"],
                        )

                        return ConversationHandler.END

                    else:
                        bot.edit_message_text(
                            chat_id=size_chat_id,
                            message_id=size_message_id,
                            text=_text[_lang]["support_error"],
                        )

                        return ConversationHandler.END

            elif check_task["status"] == 0:
                bot.edit_message_text(
                    chat_id=size_chat_id,
                    message_id=size_message_id,
                    text=_text[_lang]["task_is_in_queue"]
                    + "\n"
                    + _text[_lang]["finished_could_be_check"],
                )

                return ConversationHandler.END

            elif check_task["status"] == 2:
                bot.edit_message_text(
                    chat_id=size_chat_id,
                    message_id=size_message_id,
                    text=_text[_lang]["doing"]
                    + "\n"
                    + _text[_lang]["finished_could_be_check"],
                )

                return ConversationHandler.END

        else:
            bot.edit_message_text(
                chat_id=size_chat_id,
                message_id=size_message_id,
                text=_text[_lang]["over_limit_to_check"],
            )

            return ConversationHandler.END

    elif entry_cmd.split(" ")[1].strip() == "fav":
        update.effective_message.reply_text(
            _text[_lang]["request_target_folder"],
            reply_markup=_KB.dst_keyboard(update, context),
        )

        return _stage.COOK_FAV_TO_SIZE
Ejemplo n.º 5
0
def regex_callback(update, context):
    if "quick" == update.callback_query.data:
        regex_in_chat_id = regex_in_update.effective_message.chat_id
        regex_in_message_id = regex_in_update.effective_message.message_id
        tmp_task_list = []
        mode = "quick"
        is_quick = {"_id": "fav_quick"}
        is_quick_cur = load.fav_col.find(is_quick)

        if is_quick_cur is not None:
            for doc in is_quick_cur:
                dst_id = doc["G_id"]
                dst_name = doc["G_name"]

        for item in src_name_list:
            src_id = item["G_id"]
            src_name = item["G_name"]

            tmp_task_list.append({
                "mode_type": mode,
                "src_id": src_id,
                "src_name": src_name,
                "dst_id": dst_id,
                "dst_name": dst_name,
                "chat_id": regex_in_chat_id,
                "raw_message_id": regex_in_message_id,
            })

        Thread(target=_box.cook_task_to_db,
               args=(regex_in_update, regex_in_context,
                     tmp_task_list)).start()

        return ConversationHandler.END

    if "copy" == update.callback_query.data:
        update.callback_query.edit_message_text(
            _text[_lang]["mode_select_msg"].replace(
                "replace", _text[_lang]["copy_mode"]) + "\n" +
            _text[_lang]["request_dst_target"],
            reply_markup=_KB.dst_keyboard(update, context),
        )

        return REGEX_GET_DST

    if "size" == update.callback_query.data:

        for item in src_id_list:
            size_msg = update.effective_message.reply_text(
                _text[_lang]["ready_to_size"])
            size_chat_id = size_msg.chat_id
            size_message_id = size_msg.message_id

            # to payload
            progress = _mp(target=_s_payload.simple_size,
                           args=(update, context, item, size_chat_id,
                                 size_message_id, src_name_list))
            progress.start()

            context.bot.edit_message_text(chat_id=size_chat_id,
                                          message_id=size_message_id,
                                          text=_text[_lang]["sizing"])

        return ConversationHandler.END