Beispiel #1
0
def process_vcode_step(message, session, hash):
    chat_id = message.chat.id
    # try:
    vcode_str = message.text
    user = user_dict[chat_id]
    bot.send_message(chat_id, 'Okay~')
    bot.send_chat_action(chat_id, 'typing')  # show the bot "typing" (max. 5 secs)
    time.sleep(0.5)

    cookie = get_cookie(session, user.username, user.password, vcode_str, hash)
    user.cookie = cookie

    if cookie == cookie_prefix:
        bot.send_message(chat_id, 'Get cookie ERROR!')
        return
    else:
        bot.send_message(chat_id, 'Get cookie Success!')
        bot.send_message(chat_id, 'Now, please use /set_notify_level to set your notify level.')

    # save or update user in database
    result = query_user(chat_id)
    if result is None:
        user_obj = User()
        user_obj.tg_user_id = user.chat_id
        user_obj.bt_user = user.username
        user_obj.bt_cookie = user.cookie
        add_user(user_obj)
    else:
        update_user_cookie(user.chat_id, user.username, user.cookie)
Beispiel #2
0
def command_stop_stream(message):
    chat_id = message.chat.id
    try:
        user = query_user(chat_id)
        if user is None:
            bot.send_message(chat_id, 'Please set user information with command /set first.')
        else:
            update_user_stream_status(chat_id, 0)
            bot.send_message(chat_id, 'Stream stopped.')
    except Exception as e:
        bot.send_message(chat_id, 'oooops:' + str(e))
Beispiel #3
0
def command_info(message):
    chat_id = message.chat.id
    try:
        user = query_user(chat_id)
        if user is None:
            bot.send_message(chat_id, 'Please set your account with command /set first.')
            return
        cookie = user.bt_cookie
        user_info_msg = get_user_info(cookie)
        bot.send_message(chat_id, user_info_msg)
    except Exception as e:
        bot.send_message(chat_id, 'oooops:' + str(e))
Beispiel #4
0
def callback_page_torrent_download(call):
    chat_id = call.message.chat.id
    try:
        result = query_user(chat_id)
        if result is None:
            bot.send_message(chat_id, 'Please set your account with command /set first.')
            return
        page_num_str = call.data[2:]
        markup = types.ForceReply(selective=False)
        msg = bot.send_message(chat_id, 'OK, which one do you want to download? [1-50]', reply_markup=markup)
        bot.register_next_step_handler(msg, process_page_order_reply, page_num_str)
    except Exception as e:
        bot.send_message(chat_id, 'oooops:' + str(e))
Beispiel #5
0
def command_start_stream(message):
    chat_id = message.chat.id
    try:
        user = query_user(chat_id)
        if user is None:
            bot.send_message(chat_id, 'Please set user information with command /set first.')
        elif user.notify_level == 0:
            bot.send_message(chat_id, 'Please set your notify level with command /set_notify_level .')
        else:
            update_user_stream_status(chat_id, 1)
            bot.send_message(chat_id, 'Stream started! \nUse /stop_stream to stop.')
    except Exception as e:
        bot.send_message(chat_id, 'oooops:' + str(e))
Beispiel #6
0
def update_notify_level(chat_id, notify_level_str):
    if not notify_level_str.isdigit():
        bot.send_message(chat_id, 'Please enter a NUMBER.')
        return
    else:
        notify_level = int(notify_level_str)
        if notify_level <= 0 or notify_level > 3:
            bot.send_message(chat_id, 'Page number out of range, please enter a number in 1 2 and 3.')
            return
        result = query_user(chat_id)
        if result is not None:
            update_user_notify_level(chat_id, notify_level)
            bot.send_message(chat_id, 'Update notify level success. ' +
                             '\nNow, you can use /start_stream to start receive torrent update.')
        else:
            bot.send_message(chat_id, 'Sorry, we didn\'t have your cookie yet. Please use /set to set your cookie.')
Beispiel #7
0
def callback_download_torrent(call):
    chat_id = call.message.chat.id
    try:
        download_link = call.data[2:]
        torrent_id = re.search(r'\?id=(\d+)', download_link).group(1)
        user = query_user(chat_id)
        user_cookie = user.bt_cookie
        user_header = dict(header)
        user_header['cookie'] = user_cookie
        file_name = '_'.join([str(torrent_id), str(chat_id)])
        file_path, _ = download_file(session=None, header=user_header, link=download_link, path=torrent_save_path,
                                     file_name=file_name, format='.torrent')
        torrent_file = open(file_path, 'rb')
        files = {'document': torrent_file}
        response = requests.post("https://api.telegram.org/bot{}/sendDocument?chat_id={}".format(TOKEN, str(chat_id)),
                                 files=files)
        if str(response.status_code) != '200':
            bot.send_message(chat_id, 'Download torrent file fail!')

    except Exception as e:
        bot.send_message(chat_id, 'oooops:' + str(e))