Exemplo n.º 1
0
def chat_setting(client: Client, call: CallbackQuery):
    user, _ = get_user_model(call.from_user)
    if call.data == 'set.back':
        send_chat_list(client, user, call)
        return

    if is_user_input_expected(user):
        return

    setting, chat_id = call.data.split('.')[1:]
    try:
        chat = AllowedChat.objects.get(chat_id=chat_id,
                                       creator=user,
                                       status='activated')
    except AllowedChat.DoesNotExist:
        return

    prompt_txt = user.choice_localized(text_name=f'msg-chat-setting-{setting}')
    if setting == 'dt':
        now = datetime.utcnow()
        prompt_txt = prompt_txt.format(now=now.strftime("%H:%M"))
    call.edit_message_text(prompt_txt)
    user.conversation_flags['await_input_type'] = setting
    user.conversation_flags['input_params'] = {
        'chat_id': str(chat_id),
        'root_message_id': str(call.message.message_id)
    }
    user.save()
Exemplo n.º 2
0
def CbQryUpdateFolder(client: pyrogram.Client, cb_qry: pyrogram.CallbackQuery):
    cb_qry.answer(text="Updating folder...")
    cb_qry.edit_message_text(
        text="Path: " + utils.config["file_manager"]["path"],
        reply_markup=pyrogram.InlineKeyboardMarkup(
            keyboards.BuildItemsKeyboard(
                path=utils.config["file_manager"]["path"],
                page=utils.config["file_manager"]["page"],
                max_columns=utils.config["file_manager"]["max_columns"],
                max_rows=utils.config["file_manager"]["max_rows"],
            )
        ),
    )
Exemplo n.º 3
0
def privacy(client: Client, message: CallbackQuery):
    action = message.data.split()[-1]
    if action == 'on':
        privacy = True
    else:
        privacy = False

    mongo = db_tools.use_mongo()
    query = {'chat.id': message.from_user.id}
    query_result = mongo.nintendo.find_one(query)

    if not isinstance(query_result, dict):
        text = '發生不明錯誤,無法查詢到該筆資料.'
        message.answer(text, show_alert=True)
        return

    if 'privacy' not in query_result.keys():
        current = False
    else:
        current = query_result['privacy']

    if current == privacy:
        message.answer("你已經設定好了啦 ヾ(⌒(ノシ'ω')ノシ", show_alert=True)
        return

    # update settings.
    # 忍術拖延戰術!
    message.answer('已更新設定', show_alert=True)
    query_ = copy.copy(query)
    query_.update({'privacy': privacy})
    update = {'$set': query_}
    mongo.nintendo.update_one(query, update)

    text = '目前你的隱私狀態為 `{status}`\n' \
           '意思是任何人都 `{visble}` 利用 `/findfc` 指令找到你喔!'.format(
               status='開啟' if privacy else '關閉',
               visble='不可以' if privacy else '可以'
           )
    while True:
        try:
            message.edit_message_text(text,
                                      parse_mode='markdown',
                                      reply_markup=keyboard.privacy())
        except FloodWait as wait:
            sleep(wait.x)
        else:
            break
Exemplo n.º 4
0
def CbQryCdDrive(client: pyrogram.Client, cb_qry: pyrogram.CallbackQuery):
    utils.config["file_manager"]["path"] = (
        utils.GetDrives()[int(cb_qry.data.replace("FMcddrive", ""))] + ":\\"
    )
    utils.config["file_manager"]["page"] = 0

    cb_qry.answer(text="Moving to drive " + utils.config["file_manager"]["path"])
    cb_qry.edit_message_text(
        text="Path: " + utils.config["file_manager"]["path"],
        reply_markup=pyrogram.InlineKeyboardMarkup(
            keyboards.BuildItemsKeyboard(
                path=utils.config["file_manager"]["path"],
                page=utils.config["file_manager"]["page"],
                max_columns=utils.config["file_manager"]["max_columns"],
                max_rows=utils.config["file_manager"]["max_rows"],
            )
        ),
    )

    with open(file="utils.config.json", mode="w", encoding="utf-8") as f:
        json.dump(utils.config, f, indent=4)
Exemplo n.º 5
0
def CbQryCdFolder(client: pyrogram.Client, cb_qry: pyrogram.CallbackQuery):
    i = int(cb_qry.data.replace("FMcd", ""))
    folder = sorted(os.listdir(utils.config["file_manager"]["path"]))[i]
    utils.config["file_manager"]["path"] = os.path.abspath(
        os.path.join(utils.config["file_manager"]["path"], folder)
    )
    utils.config["file_manager"]["page"] = 0

    cb_qry.answer(text="Moving to " + utils.config["file_manager"]["path"])
    cb_qry.edit_message_text(
        text="Path: " + utils.config["file_manager"]["path"],
        reply_markup=pyrogram.InlineKeyboardMarkup(
            keyboards.BuildItemsKeyboard(
                path=utils.config["file_manager"]["path"],
                page=utils.config["file_manager"]["page"],
                max_columns=utils.config["file_manager"]["max_columns"],
                max_rows=utils.config["file_manager"]["max_rows"],
            )
        ),
    )

    with open(file="utils.config.json", mode="w", encoding="utf-8") as f:
        json.dump(utils.config, f, indent=4)
Exemplo n.º 6
0
def CbQryPreviousFolder(client: pyrogram.Client, cb_qry: pyrogram.CallbackQuery):
    if utils.config["file_manager"]["path"][1:].endswith(":\\"):
        utils.config["file_manager"]["path"] = "/"
    else:
        utils.config["file_manager"]["path"] = str(
            pathlib.Path(utils.config["file_manager"]["path"]).parent
        )
    utils.config["file_manager"]["page"] = 0

    cb_qry.answer(text="Moving to " + utils.config["file_manager"]["path"])
    cb_qry.edit_message_text(
        text="Path: " + utils.config["file_manager"]["path"],
        reply_markup=pyrogram.InlineKeyboardMarkup(
            keyboards.BuildItemsKeyboard(
                path=utils.config["file_manager"]["path"],
                page=utils.config["file_manager"]["page"],
                max_columns=utils.config["file_manager"]["max_columns"],
                max_rows=utils.config["file_manager"]["max_rows"],
            )
        ),
    )

    with open(file="utils.config.json", mode="w", encoding="utf-8") as f:
        json.dump(utils.config, f, indent=4)