From 0c7765eef8f8619cc95ffb4317d5d895e2577181 Mon Sep 17 00:00:00 2001 From: fxxkrlab Date: Mon, 27 Jul 2020 02:58:04 +0900 Subject: [PATCH 1/2] Update v0.2.0b6.1 --- config/text.toml | 11 ++-- docs/CHANGELOG.md | 49 ++++++++++++++ docs/develop_update.md | 14 ++-- iCopy.py | 33 ++++++---- utils/callback_stage.py | 21 ++++++ utils/dedupe_payload.py | 36 +++++++---- utils/get_functions.py | 8 ++- utils/get_set.py | 14 ++-- utils/load.py | 2 +- workflow/copy_workflow.py | 28 +++++--- workflow/dedupe_workflow.py | 124 ++++++++++++++++++++++++++++++------ workflow/purge_workflow.py | 59 +++++++++++------ workflow/quick_workflow.py | 18 ++++-- workflow/regex_workflow.py | 102 +++++++++++++++++++---------- workflow/size_workflow.py | 12 ++-- workflow/start_workflow.py | 15 ++++- 16 files changed, 402 insertions(+), 144 deletions(-) create mode 100644 utils/callback_stage.py diff --git a/config/text.toml b/config/text.toml index b600995..be67403 100644 --- a/config/text.toml +++ b/config/text.toml @@ -69,7 +69,7 @@ task_is_in_queue = "任务正在队列中" finished_could_be_check = "只能查询已完成的任务" finished_could_be_dedupe = "只能对已完成的任务进行去重" support_error = "指定的任务不支持查询" -request_target_folder = "请选择目标盘 或 文件夹" +request_target_folder = "请选择目标收藏夹" ready_to_purge = "正在准备清空回收站" purging = "正在清空回收站,请耐心等待\n如果同时存在复制任务,则会影响复制与清空回收站双方的准确性" purging_done = "已清空回收站" @@ -77,6 +77,7 @@ request_dedupe_mode = "请选择去重模式 规则" ready_to_dedupe = "正在准备文件去重" deduping = "正在执行去重文件,请耐心等待\n如果同时存在复制任务,则会影响复制与文件去重双方的准确性" deduping_done = "文件去重已完成" +is_folder_not_drive = "被选择的收藏夹是一个'文件夹'不是'团队盘'\n无法清空回收站" [eng] start = "Hi! replace . Welcome to use iCopy" #replace==symbolic placeholder @@ -156,6 +157,7 @@ request_dedupe_mode = "Please select to dedupe mode rule" ready_to_dedupe = "Ready to dedupe" deduping = "In deduping task, pls wait \nIf there is a copy task, it will affect the accuracy of both copy and dedupe" deduping_done = "The task is be deduped" +is_folder_not_drive = "The selected favorites is a 'folder' not a 'shared drive'\n Can not be purged" [jp] start = "Hi! replace . iCopyへようこそ" #replace==置き換え指示記号 @@ -228,10 +230,11 @@ finished_could_be_check = "既に完了した任務しか調べられない" finished_could_be_dedupe = "すでに完了したタスクのみが重複ファイルの除去を行うことができる" support_error = "指定の任務の照会を支持しない" request_target_folder = "目標フォルダーを選んでください" -ready_to_purge = "空のごみ箱を清算する準備をしています" -purging = "空のごみ箱をクリアしています。\n同時にコピーの任務がある場合、コピーと空のごみ箱の両方の正確さに影響します" +ready_to_purge = "ごみ箱を空にする準備をしています" +purging = "ごみ箱をクリアしています。\n同時にコピーの任務がある場合、コピーとごみ箱を空にすることの両方の正確さに影響します" purging_done = "既にごみ箱を空にした" request_dedupe_mode = "重複除外モードのルールを選択してください" ready_to_dedupe = "重複ファイルを除去する準備をしています" deduping = "重複ファイルを除去しています。\n同時にコピーの任務がある場合、コピーと重複除外の両方の正確さに影響します" -deduping_done = "重複ファイルの除去が完了しました" \ No newline at end of file +deduping_done = "重複ファイルの除去が完了しました" +is_folder_not_drive = "選択されたお気に入りは「フォルダ」ではなく「シェアドライバ」で\nゴミ箱を空にできない" \ No newline at end of file diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 2a7cdc3..3c74165 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,5 +1,54 @@ # iCopy v0.2 CHANGELOG +## version 0.2.0-beta.6.1 + ++ Update : + + ADD : "/dedupe" Now you can choose favorites to dedupe + + CHANGE : Move the stage tag uniformly to new file “utils/callback_stage.py" + ++ Fixbugs : + + Judge select favorites if is shared drive when you use "/purge" mode. + + Separately define bot variables in asynchronous-process to prevent errors in connecting Telegram. + ++ Root Command: + + + start - nothing just say hello + + menu - main entry point +quick - quick mode +copy - full mode +set - customize settings +task - task query +reset - restore task +size - just size task +dedupe - dedupe drives and folders +purge - delete files and folder in specified fav trash bin +cancel - cancel TG conversation +kill - kill task which is in processing +ver - check iCopy version +restart - restart iCopy + + + Child Command: + + + set - customize settings + ┖ set - batch way + ┖ set rule - rules + ┖ fav|quick +/- id - single way + ┖ set purge - purge favorites + + size - size query + ┖ size - size the shared resource + ┖ size id - size specified task + ┖ size fav - size specified favorites + + dedupe - dedupe drives and folders + ┖ dedupe - dedupe specified favorites + ┖ dedupe id - dedupe specified task via task id + + task - task query + ┖ task - task in processing + ┖ task list - future 10 tasks + ┖ task id - show the specified task + + reset - restore task + ┖ reset - restore current task + ┖ reset id - restore the specified task + ## version 0.2.0-beta.6 + Update : diff --git a/docs/develop_update.md b/docs/develop_update.md index 7840d9c..e5389ce 100644 --- a/docs/develop_update.md +++ b/docs/develop_update.md @@ -1,13 +1,7 @@ # DEVELOP UPDATE CHANGELOG -## v0.2.0-beta.6 finished +## v0.2.0-beta.6.1 -+ ADD : insert more details into Database and more initialization data -+ ADD : feedback dst endpoint link when task end normally -+ ADD : 2 Group in RegEX -+ ADD : "/task id" only support the task which is start after v0.2.0b6 -+ ADD : mark tasks that have been reset in the database -+ ADD : "/size id" & "/size fav" -+ ADD : "/purge" to empty shared drive trash bin -+ ADD : "/dedupe id" to dedupe task - \ No newline at end of file +Fixbugs: + ++ FIX : "/purge" Determines whether it is a “shared drive" or a "folder" diff --git a/iCopy.py b/iCopy.py index 83ef5f4..028509a 100755 --- a/iCopy.py +++ b/iCopy.py @@ -20,6 +20,7 @@ get_functions as _func, task_box as _box, task_payload as _payload, + callback_stage as _stage, ) from workflow import ( @@ -45,6 +46,13 @@ def main(): + ''' + defualt path: + _set.SET_FAV_MULTI,_start.CHOOSE_MODE,_quick.GET_LINK,_set.IS_COVER_QUICK, + _copy.GET_DST,_size.COOK_ID,_regex.REGEX_IN,_regex.REGEX_GET_DST, + _size.COOK_FAV_TO_SIZE,_purge.COOK_FAV_PURGE,_dedupe.COOK_ID_DEDU, + _dedupe.COOK_FAV_DEDU,_stage.FAV_PRE_DEDU_INFO + ''' ### bot define request = TGRequest(con_pool_size=8) bot = Bot(token=f"{load.cfg['tg']['token']}", request=request) @@ -81,45 +89,48 @@ def main(): Filters.regex(pattern=load.regex_entry_pattern), _regex.regex_entry ), ], + states={ - _set.SET_FAV_MULTI: [ + _stage.SET_FAV_MULTI: [ # fav settings function MessageHandler(Filters.text, _set._multi_settings_recieved), ], - _start.CHOOSE_MODE: [ + _stage.CHOOSE_MODE: [ # call function judged via callback pattern CallbackQueryHandler(_quick.quick, pattern="quick"), CallbackQueryHandler(_copy.copy, pattern="copy"), ], - _quick.GET_LINK: [ + _stage.GET_LINK: [ # get Shared_Link states MessageHandler(Filters.text, _func.get_share_link), ], - _set.IS_COVER_QUICK: [ + _stage.IS_COVER_QUICK: [ # cover quick setting CallbackQueryHandler(_func.modify_quick_in_db, pattern="cover_quick"), CallbackQueryHandler(_func.cancel, pattern="not_cover_quick"), MessageHandler(Filters.text, _func.cancel), ], - _copy.GET_DST: [ + _stage.GET_DST: [ # request DST CallbackQueryHandler(_copy.request_srcinfo), ], - _size.COOK_ID: [ + _stage.COOK_ID: [ # request to COOK ID MessageHandler(Filters.text, _size.size_handle), ], - _regex.REGEX_IN: [ + _stage.REGEX_IN: [ # regex in choose mode CallbackQueryHandler(_regex.regex_callback, pattern=r"quick|copy|size"), ], - _regex.REGEX_GET_DST: [ + _stage.REGEX_GET_DST: [ # regex copy end CallbackQueryHandler(_regex.regex_copy_end), ], - _size.COOK_FAV_TO_SIZE: [CallbackQueryHandler(_size.pre_cook_fav_to_size),], - _purge.COOK_FAV_PURGE: [CallbackQueryHandler(_purge.pre_to_purge),], - _dedupe.COOK_ID_DEDU: [CallbackQueryHandler(_dedupe.dedupe_mode),], + _stage.COOK_FAV_TO_SIZE: [CallbackQueryHandler(_size.pre_cook_fav_to_size),], + _stage.COOK_FAV_PURGE: [CallbackQueryHandler(_purge.pre_to_purge),], + _stage.COOK_ID_DEDU: [CallbackQueryHandler(_dedupe.dedupe_mode),], + _stage.COOK_FAV_DEDU: [CallbackQueryHandler(_dedupe.dedupe_fav_mode),], + _stage.FAV_PRE_DEDU_INFO: [CallbackQueryHandler(_dedupe.pre_favdedu_info)], }, fallbacks=[CommandHandler("cancel", _func.cancel)], ) diff --git a/utils/callback_stage.py b/utils/callback_stage.py new file mode 100644 index 0000000..8c99893 --- /dev/null +++ b/utils/callback_stage.py @@ -0,0 +1,21 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- + +from telegram.ext import ConversationHandler + +( + SET_FAV_MULTI, + CHOOSE_MODE, + GET_LINK, + IS_COVER_QUICK, + GET_DST, + COOK_ID, + REGEX_IN, + REGEX_GET_DST, + COOK_FAV_TO_SIZE, + COOK_FAV_PURGE, + COOK_ID_DEDU, + COOK_FAV_DEDU, + FAV_PRE_DEDU_INFO, + +) = range(13) \ No newline at end of file diff --git a/utils/dedupe_payload.py b/utils/dedupe_payload.py index 4f10d52..2b4d614 100644 --- a/utils/dedupe_payload.py +++ b/utils/dedupe_payload.py @@ -66,17 +66,31 @@ def dedupe_task( {"_id": int(dedu_task_id)}, {"$set": {"last_dedupe_time": last_dedupe_time,}}, ) - deduped_msg = ( - " ༺ ✪iCopy✪ ༻ | " - + "🏳️" + _text[_lang]["current_task_id"] - + str(dedu_task_id) - + "\n\n" - + '{}'.format(dedu_link, dedu_name) - + "\n[" - + dedu_id - + "]\n\n" - + _text[_lang]["deduping_done"] - ) + if dedu_task_id == 0: + deduped_msg = ( + " ༺ ✪iCopy✪ ༻ | " + + "🏳️" + + " FAVORITES" + + "\n\n" + + '{}'.format(dedu_link, dedu_name) + + "\n[" + + dedu_id + + "]\n\n" + + _text[_lang]["deduping_done"] + ) + + else: + deduped_msg = ( + " ༺ ✪iCopy✪ ༻ | " + + "🏳️" + _text[_lang]["current_task_id"] + + str(dedu_task_id) + + "\n\n" + + '{}'.format(dedu_link, dedu_name) + + "\n[" + + dedu_id + + "]\n\n" + + _text[_lang]["deduping_done"] + ) bot.edit_message_text( chat_id=dedu_chat_id, diff --git a/utils/get_functions.py b/utils/get_functions.py index 4445a43..15b2b31 100644 --- a/utils/get_functions.py +++ b/utils/get_functions.py @@ -6,6 +6,7 @@ get_set as _set, task_box as _box, task_payload as _payload, + callback_stage as _stage, ) from workflow import copy_workflow as _copy from utils.load import _lang, _text @@ -20,7 +21,7 @@ format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO ) logger = logging.getLogger(__name__) - +''' ( SET_FAV_MULTI, CHOOSE_MODE, @@ -33,8 +34,9 @@ COOK_FAV_TO_SIZE, COOK_FAV_PURGE, COOK_ID_DEDU, -) = range(11) - + COOK_FAV_DEDU, +) = range(12) +''' regex1 = r"[-\w]{11,}" regex2 = r"[-\w]" judge_folder_len = [28, 33] diff --git a/utils/get_set.py b/utils/get_set.py index 86d1dac..c8c2313 100644 --- a/utils/get_set.py +++ b/utils/get_set.py @@ -7,12 +7,13 @@ messages as _msg, restricted as _r, keyboard as _KB, + callback_stage as stage, ) from telegram.ext import ConversationHandler from telegram import ParseMode from utils.load import _lang, _text from drive.gdrive import GoogleDrive as _gd - +''' ( SET_FAV_MULTI, CHOOSE_MODE, @@ -25,8 +26,9 @@ COOK_FAV_TO_SIZE, COOK_FAV_PURGE, COOK_ID_DEDU, -) = range(11) - + COOK_FAV_DEDU, +) = range(12) +''' pick_quick = [] pick_fav = [] unpick_fav = [] @@ -46,7 +48,7 @@ def _setting(update, context): _msg.set_multi_fav_guide(_lang), parse_mode=ParseMode.MARKDOWN_V2 ) - return SET_FAV_MULTI + return _stage.SET_FAV_MULTI if "purge" == entry_cmd[4:]: fav_count = load.db_counters.find_one({"_id": "fav_count_list"}) @@ -134,7 +136,7 @@ def _setting(update, context): reply_markup=_KB.is_cover_keyboard(), ) - return IS_COVER_QUICK + return _stage.IS_COVER_QUICK elif "quick-" == each[:6]: _func.delete_in_db_quick @@ -249,7 +251,7 @@ def _multi_settings_recieved(update, context): reply_markup=_KB.is_cover_keyboard(), ) - return IS_COVER_QUICK + return _stage.IS_COVER_QUICK elif _tmp_quick_counter < 1: pass diff --git a/utils/load.py b/utils/load.py index 7783002..fef1b75 100644 --- a/utils/load.py +++ b/utils/load.py @@ -11,7 +11,7 @@ ### local version -_version = "v0.2.0-beta.6" +_version = "v0.2.0-beta.6.1" _cfgFile_RAW = os.path.abspath(os.path.join("config", "conf.toml")) cfg = toml.load(_cfgFile_RAW) diff --git a/workflow/copy_workflow.py b/workflow/copy_workflow.py index 5e3532b..e5b964f 100644 --- a/workflow/copy_workflow.py +++ b/workflow/copy_workflow.py @@ -3,9 +3,16 @@ from utils.load import _lang, _text from telegram.ext import ConversationHandler -from utils import messages as _msg, restricted as _r, get_functions as _func, task_box as _box, keyboard as _KB - +from utils import ( + messages as _msg, + restricted as _r, + get_functions as _func, + task_box as _box, + keyboard as _KB, + callback_stage as _stage, +) +''' ( SET_FAV_MULTI, CHOOSE_MODE, @@ -18,10 +25,12 @@ COOK_FAV_TO_SIZE, COOK_FAV_PURGE, COOK_ID_DEDU, -) = range(11) - + COOK_FAV_DEDU, +) = range(12) +''' current_dst_info = "" + @_r.restricted @_r.restricted_copy def copy(update, context): @@ -38,7 +47,7 @@ def copy(update, context): reply_markup=_KB.dst_keyboard(update, context), ) - return GET_DST + return _stage.GET_DST if update.callback_query.data == "copy": update.callback_query.edit_message_text( @@ -50,14 +59,13 @@ def copy(update, context): reply_markup=_KB.dst_keyboard(update, context), ) - return GET_DST + return _stage.GET_DST + def request_srcinfo(update, context): global current_dst_info current_dst_info = update.callback_query.data - update.callback_query.edit_message_text( - _text[_lang]["request_share_link"] - ) + update.callback_query.edit_message_text(_text[_lang]["request_share_link"]) - return GET_LINK + return _stage.GET_LINK diff --git a/workflow/dedupe_workflow.py b/workflow/dedupe_workflow.py index f574e0b..c13e2ac 100644 --- a/workflow/dedupe_workflow.py +++ b/workflow/dedupe_workflow.py @@ -1,10 +1,20 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- + import re from utils.load import _lang, _text -from utils import load, restricted as _r, keyboard as _KB, dedupe_payload as _d_payload +from utils import ( + load, + restricted as _r, + keyboard as _KB, + dedupe_payload as _d_payload, + callback_stage as _stage, +) from multiprocessing import Process as _mp from telegram.ext import ConversationHandler from drive.gdrive import GoogleDrive as _gd +""" ( SET_FAV_MULTI, CHOOSE_MODE, @@ -17,21 +27,38 @@ COOK_FAV_TO_SIZE, COOK_FAV_PURGE, COOK_ID_DEDU, -) = range(11) + COOK_FAV_DEDU, + +) = range(12) +""" bot = load.bot check_task = {} +dedufav_callback = "" +@_r.restricted def dedupe(update, context): entry_cmd = update.effective_message.text - match_cmd = re.search(r'^\/dedupe ([1-9]\d*)$', entry_cmd, flags=re.I) + 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 - if match_cmd: - limit_query = load.db_counters.find_one({"_id":"task_list_id"}) + 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']: - + if int(check_query) <= limit_query["future_id"]: + global check_task check_task = load.task_list.find_one({"_id": int(check_query)}) @@ -45,7 +72,7 @@ def dedupe(update, context): reply_markup=_KB.dedupe_mode_keyboard(), ) - return COOK_ID_DEDU + return _stage.COOK_ID_DEDU elif check_task["status"] == 0: update.effective_message.reply_text( @@ -64,18 +91,14 @@ def dedupe(update, context): ) return ConversationHandler.END - + else: - update.effective_message.reply_text( - _text[_lang]["over_limit_to_dedupe"], - ) + 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"] - ) + update.effective_message.reply_text(_text[_lang]["global_command_error"]) def dedupe_mode(update, context): @@ -91,14 +114,13 @@ def dedupe_mode(update, context): dedu_chat_id = dedu_msg.chat_id dedu_message_id = dedu_msg.message_id dedu_mode = get_callback - + if "dst_endpoint_id" and "dst_endpoint_link" in check_task: dedu_task_id = check_task["_id"] dedu_name = check_task["src_name"] dedu_id = check_task["dst_endpoint_id"] dedu_link = check_task["dst_endpoint_link"] - else: dst_endpoint_id = _gd.get_dst_endpoint_id( _gd(), check_task["dst_id"], check_task["src_name"] @@ -138,9 +160,69 @@ def dedupe_mode(update, context): progress.start() bot.edit_message_text( - chat_id=dedu_chat_id, - message_id=dedu_message_id, - text=_text[_lang]["deduping"], + chat_id=dedu_chat_id, message_id=dedu_message_id, text=_text[_lang]["deduping"], + ) + + return ConversationHandler.END + + +def dedupe_fav_mode(update, context): + global dedufav_callback + dedufav_callback = update.callback_query.data + update.callback_query.edit_message_text( + _text[_lang]["mode_select_msg"].replace("replace", _text[_lang]["dedupe_mode"]) + + "\n" + + _text[_lang]["request_dedupe_mode"], + reply_markup=_KB.dedupe_mode_keyboard(), + ) + + dedu_chat_id = dedu_msg.chat_id + dedu_message_id = dedu_msg.message_id + + return _stage.FAV_PRE_DEDU_INFO + + +def pre_favdedu_info(update, context): + print(update.callback_query.data) + print(dedufav_callback) + + dedu_mode = update.callback_query.data + + dedu_msg = bot.edit_message_text( + chat_id=update.callback_query.message.chat_id, + message_id=update.callback_query.message.message_id, + text=_text[_lang]["ready_to_dedupe"], + reply_markup=None, + ) + + dedu_chat_id = dedu_msg.chat_id + dedu_message_id = dedu_msg.message_id + + dedu_task_id = 0 + + dedufav_info = dedufav_callback.split("id+name") + dedu_id = dedufav_info[0] + dedu_name = dedufav_info[1] + dedu_link = r"https://drive.google.com/open?id={}".format( + dedufav_info[0] + ) + + progress = _mp( + target=_d_payload.dedupe_task, + args=( + dedu_mode, + dedu_chat_id, + dedu_message_id, + dedu_task_id, + dedu_link, + dedu_id, + dedu_name, + ), + ) + progress.start() + + bot.edit_message_text( + chat_id=dedu_chat_id, message_id=dedu_message_id, text=_text[_lang]["deduping"], ) - return ConversationHandler.END \ No newline at end of file + return ConversationHandler.END diff --git a/workflow/purge_workflow.py b/workflow/purge_workflow.py index d40c691..440ef62 100644 --- a/workflow/purge_workflow.py +++ b/workflow/purge_workflow.py @@ -1,8 +1,14 @@ from utils.load import _lang, _text -from utils import load, restricted as _r, keyboard as _KB, purge_payload as _p_payload +from utils import ( + load, + restricted as _r, + keyboard as _KB, + purge_payload as _p_payload, + callback_stage as _stage, +) from multiprocessing import Process as _mp from telegram.ext import ConversationHandler - +''' ( SET_FAV_MULTI, CHOOSE_MODE, @@ -15,10 +21,13 @@ COOK_FAV_TO_SIZE, COOK_FAV_PURGE, COOK_ID_DEDU, -) = range(11) + COOK_FAV_DEDU, +) = range(12) +''' bot = load.bot +@_r.restricted def purge(update, context): update.effective_message.reply_text( _text[_lang]["mode_select_msg"].replace( @@ -29,7 +38,7 @@ def purge(update, context): reply_markup=_KB.dst_keyboard(update, context), ) - return COOK_FAV_PURGE + return _stage.COOK_FAV_PURGE def pre_to_purge(update, context): get_callback = update.callback_query.data @@ -47,22 +56,32 @@ def pre_to_purge(update, context): fav_id = fav_info_list[0] fav_name = fav_info_list[1] - progress = _mp( - target=_p_payload.purge_fav, - args=( - purge_chat_id, - purge_message_id, - fav_id, - fav_name, - ), - ) + if len(fav_id) < 28: + progress = _mp( + target=_p_payload.purge_fav, + args=( + purge_chat_id, + purge_message_id, + fav_id, + fav_name, + ), + ) - progress.start() + progress.start() - bot.edit_message_text( - chat_id=purge_chat_id, - message_id=purge_message_id, - text=_text[_lang]["purging"], - ) + bot.edit_message_text( + chat_id=purge_chat_id, + message_id=purge_message_id, + text=_text[_lang]["purging"], + ) + + return ConversationHandler.END + + else: + bot.edit_message_text( + chat_id=purge_chat_id, + message_id=purge_message_id, + text=_text[_lang]["is_folder_not_drive"], + ) - return ConversationHandler.END \ No newline at end of file + return ConversationHandler.END \ No newline at end of file diff --git a/workflow/quick_workflow.py b/workflow/quick_workflow.py index d85fbf9..b992e23 100644 --- a/workflow/quick_workflow.py +++ b/workflow/quick_workflow.py @@ -3,8 +3,13 @@ from utils.load import _lang, _text from telegram.ext import ConversationHandler -from utils import restricted as _r, get_functions as _func, task_box as _box - +from utils import ( + restricted as _r, + get_functions as _func, + task_box as _box, + callback_stage as _stage, +) +''' ( SET_FAV_MULTI, CHOOSE_MODE, @@ -17,8 +22,9 @@ COOK_FAV_TO_SIZE, COOK_FAV_PURGE, COOK_ID_DEDU, -) = range(11) - + COOK_FAV_DEDU, +) = range(12) +''' @_r.restricted @_r.restricted_quick def quick(update, context): @@ -34,7 +40,7 @@ def quick(update, context): + _text[_lang]["request_share_link"] ) - return GET_LINK + return _stage.GET_LINK if update.callback_query.data == "quick": update.callback_query.edit_message_text( @@ -45,4 +51,4 @@ def quick(update, context): + _text[_lang]["request_share_link"] ) - return GET_LINK + return _stage.GET_LINK diff --git a/workflow/regex_workflow.py b/workflow/regex_workflow.py index e67c616..bf6c571 100644 --- a/workflow/regex_workflow.py +++ b/workflow/regex_workflow.py @@ -1,9 +1,17 @@ from utils.load import _lang, _text -from utils import load, get_functions as _func, restricted as _r, keyboard as _KB, task_box as _box, size_payload as _s_payload +from utils import ( + load, + get_functions as _func, + restricted as _r, + keyboard as _KB, + task_box as _box, + size_payload as _s_payload, + callback_stage as _stage, +) from telegram.ext import CallbackQueryHandler, ConversationHandler from threading import Thread from multiprocessing import Process as _mp - +''' ( SET_FAV_MULTI, CHOOSE_MODE, @@ -16,13 +24,15 @@ COOK_FAV_TO_SIZE, COOK_FAV_PURGE, COOK_ID_DEDU, -) = range(11) - + COOK_FAV_DEDU, +) = range(12) +''' src_name_list = [] src_id_list = [] regex_in_update = None regex_in_context = None + @_r.restricted def regex_entry(update, context): global src_id_list @@ -33,12 +43,13 @@ def regex_entry(update, context): get_share_link = update.effective_message.text src_id_list = _func.cook_to_id(get_share_link) for item in src_id_list: - src_name_list += _func.get_src_name_from_id(update, taget_id=item, list_name=tmp_src_name_list) + src_name_list += _func.get_src_name_from_id( + update, taget_id=item, list_name=tmp_src_name_list + ) tmp_src_name_list = "" - + update.effective_message.reply_text( - _text[_lang]["menu_msg"], - reply_markup=_KB.regex_in_keyboard(), + _text[_lang]["menu_msg"], reply_markup=_KB.regex_in_keyboard(), ) global regex_in_update @@ -46,16 +57,19 @@ def regex_entry(update, context): regex_in_update = update regex_in_context = context - return REGEX_IN + return _stage.REGEX_IN + def regex_callback(update, context): if "quick" == update.callback_query.data: - load.bot.edit_message_text(chat_id=update.callback_query.message.chat_id, - message_id=update.callback_query.message.message_id, - text=_text[_lang]["mode_select_msg"].replace( - "replace", _text[_lang]["quick_mode"] - ), - reply_markup=None) + load.bot.edit_message_text( + chat_id=update.callback_query.message.chat_id, + message_id=update.callback_query.message.message_id, + text=_text[_lang]["mode_select_msg"].replace( + "replace", _text[_lang]["quick_mode"] + ), + reply_markup=None, + ) regex_in_chat_id = regex_in_update.effective_message.chat_id regex_in_message_id = regex_in_update.effective_message.message_id @@ -63,7 +77,7 @@ def regex_callback(update, context): 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"] @@ -85,7 +99,10 @@ def regex_callback(update, context): } ) - Thread(target=_box.cook_task_to_db, args=(regex_in_update, regex_in_context, tmp_task_list)).start() + Thread( + target=_box.cook_task_to_db, + args=(regex_in_update, regex_in_context, tmp_task_list), + ).start() tmp_task_list = [] return ConversationHandler.END @@ -98,38 +115,54 @@ def regex_callback(update, context): + _text[_lang]["request_dst_target"], reply_markup=_KB.dst_keyboard(update, context), ) - - return REGEX_GET_DST + return _stage.REGEX_GET_DST if "size" == update.callback_query.data: for item in src_id_list: - size_msg = load.bot.edit_message_text(chat_id=update.callback_query.message.chat_id, - message_id=update.callback_query.message.message_id, - text=_text[_lang]["ready_to_size"], - reply_markup=None) + size_msg = load.bot.edit_message_text( + chat_id=update.callback_query.message.chat_id, + message_id=update.callback_query.message.message_id, + text=_text[_lang]["ready_to_size"], + reply_markup=None, + ) 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 = _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"] + chat_id=size_chat_id, + message_id=size_message_id, + text=_text[_lang]["sizing"], ) return ConversationHandler.END + def regex_copy_end(update, context): - load.bot.edit_message_text(chat_id=update.callback_query.message.chat_id, - message_id=update.callback_query.message.message_id, - text=_text[_lang]["mode_select_msg"].replace( - "replace", _text[_lang]["copy_mode"] - ), - reply_markup=None) + load.bot.edit_message_text( + chat_id=update.callback_query.message.chat_id, + message_id=update.callback_query.message.message_id, + text=_text[_lang]["mode_select_msg"].replace( + "replace", _text[_lang]["copy_mode"] + ), + reply_markup=None, + ) mode = "copy" regex_in_chat_id = regex_in_update.effective_message.chat_id @@ -140,7 +173,7 @@ def regex_copy_end(update, context): dstinfo = is_dstinfo.split("id+name") dst_id = dstinfo[0] dst_name = dstinfo[1] - + for item in src_name_list: src_id = item["G_id"] src_name = item["G_name"] @@ -157,7 +190,10 @@ def regex_copy_end(update, context): } ) - Thread(target=_box.cook_task_to_db, args=(regex_in_update, regex_in_context, tmp_task_list)).start() + Thread( + target=_box.cook_task_to_db, + args=(regex_in_update, regex_in_context, tmp_task_list), + ).start() dstinfo = "" return ConversationHandler.END diff --git a/workflow/size_workflow.py b/workflow/size_workflow.py index f6bf2e6..f60a29f 100644 --- a/workflow/size_workflow.py +++ b/workflow/size_workflow.py @@ -11,10 +11,11 @@ task_box as _box, size_payload as _s_payload, keyboard as _KB, + callback_stage as _stage, ) from drive.gdrive import GoogleDrive as _gd from multiprocessing import Process as _mp - +''' ( SET_FAV_MULTI, CHOOSE_MODE, @@ -27,8 +28,9 @@ COOK_FAV_TO_SIZE, COOK_FAV_PURGE, COOK_ID_DEDU, -) = range(11) - + COOK_FAV_DEDU, +) = range(12) +''' bot = load.bot @_r.restricted @@ -38,7 +40,7 @@ def size(update, context): if "/size" == entry_cmd: update.effective_message.reply_text(_text[_lang]["request_share_link"]) - return COOK_ID + return _stage.COOK_ID elif match_cmd: limit_query = load.db_counters.find_one({"_id": "task_list_id"}) @@ -170,7 +172,7 @@ def size(update, context): reply_markup=_KB.dst_keyboard(update, context), ) - return COOK_FAV_TO_SIZE + return _stage.COOK_FAV_TO_SIZE def pre_cook_fav_to_size(update, context): diff --git a/workflow/start_workflow.py b/workflow/start_workflow.py index 52e339f..5bad7bc 100644 --- a/workflow/start_workflow.py +++ b/workflow/start_workflow.py @@ -12,8 +12,14 @@ ConversationHandler, ) from utils.load import _lang, _text -from utils import messages as _msg, restricted as _r, keyboard as _KB +from utils import ( + messages as _msg, + restricted as _r, + keyboard as _KB, + callback_stage as _stage, +) +''' ( SET_FAV_MULTI, CHOOSE_MODE, @@ -26,8 +32,11 @@ COOK_FAV_TO_SIZE, COOK_FAV_PURGE, COOK_ID_DEDU, -) = range(11) + COOK_FAV_DEDU, +) = range(12) +''' +@_r.restricted def start(update, context): _first_name = update.effective_user.first_name update.effective_message.reply_text( @@ -43,4 +52,4 @@ def menu(update, context): reply_markup=_KB.start_keyboard(), ) - return CHOOSE_MODE + return _stage.CHOOSE_MODE From d439e000c3236490f03e9eb3cc63505b15c2cf43 Mon Sep 17 00:00:00 2001 From: fxxkrlab Date: Mon, 27 Jul 2020 02:58:36 +0900 Subject: [PATCH 2/2] Update v0.2.0b6.1 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 32a6542..2c8a0bc 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [![iCopy Telegram-Bot](https://img.shields.io/badge/iCopy-Telegram%20BOT-red?style=flat-square&logo=appveyor)](https://bbs.jsu.net/c/official-project/icopy/6) [![Programming Language](https://img.shields.io/badge/LANGUAGE-Python%203.6%2B-success?style=flat-square&logo=appveyor)](https://bbs.jsu.net/c/official-project/icopy/6) -[![Version](https://img.shields.io/badge/Version-0.2.0--beta.6-ff69b4?style=flat-square&logo=appveyor)](https://bbs.jsu.net/c/official-project/icopy/6) +[![Version](https://img.shields.io/badge/Version-0.2.0--beta.6.1-ff69b4?style=flat-square&logo=appveyor)](https://bbs.jsu.net/c/official-project/icopy/6) [![License](https://img.shields.io/github/license/fxxkrlab/iCopy?style=flat-square&logo=appveyor)](https://bbs.jsu.net/c/official-project/icopy/6) [![DATABASE](https://img.shields.io/badge/DATABASE-MongoDB-brightgreen?style=flat-square&logo=appveyor)](https://github.com/mongodb/mongo) [![Stars](https://img.shields.io/github/stars/fxxkrlab/iCopy?style=flat-square&logo=appveyor)](https://github.com/fxxkrlab/iCopy)