Exemple #1
0
def bot_start(message):
    if message.text == '/start':
        bot.send_chat_action(message.chat.id, 'typing')
        bot.send_message(message.chat.id, '哎哟欢迎😗我能查快递,陪聊,查美剧电影 ~\n要不戳这里试试看 /help')
    elif ',' in message.text:
        msg = message.text.split()[1].split(',')
        for item_tid in msg:
            bot.send_chat_action(message.chat.id, 'typing')
            r = kuaidi100.recv(item_tid, message.message_id, message.chat.id)
            bot.send_message(message.chat.id, r, parse_mode='Markdown')
    else:
        bot.send_chat_action(message.chat.id, 'typing')
        r = kuaidi100.recv(message.text.split()[1], message.message_id, message.chat.id)
        bot.send_message(message.chat.id, r, parse_mode='Markdown')
Exemple #2
0
def bot_help(message):
    if message.text == '/start':
        bot.send_chat_action(message.chat.id, 'typing')
        bot.send_message(message.chat.id, '直接把运单号告诉咱就好啦 ~')
    elif ',' in message.text:
        msg = message.text.split()[1].split(',')
        for item_tid in msg:
            bot.send_chat_action(message.chat.id, 'typing')
            r = kuaidi100.recv(item_tid, message.message_id, message.chat.id)
            bot.send_message(message.chat.id, r)
    else:
        bot.send_chat_action(message.chat.id, 'typing')
        r = kuaidi100.recv(message.text.split()[1], message.message_id, message.chat.id)
        bot.send_message(message.chat.id, r)
Exemple #3
0
def track_express(message):
    if '.' in message.text:
        bot.send_chat_action(message.chat.id, 'typing')
        bot.send_message(message.chat.id, utils.reply_fefuse())
    else:
        bot.send_chat_action(message.chat.id, 'typing')
        r = kuaidi100.recv(message.text, message.message_id, message.chat.id)
        bot.send_message(message.chat.id, r)
Exemple #4
0
def cron(code, mid, cid, db_content):
    """
    cron job process for timer.py
    :param code: express id
    :param mid: message id for reply_to_message
    :param cid: chat_id(a.k.a user_id)
    :param db_content: old express status in database
    :return: None
    """
    r = kuaidi100.recv(code, mid, cid)
    if db_content not in r:
        bot.send_message(chat_id=cid, reply_to_message_id=mid, text=r)
Exemple #5
0
def track_express(message):
    """
    get_season_count text/voice message, all digits means express id. Otherwise sends Turing or refuse message
    :param message: Telegram message sent by user.
    :return: None
    """
    if os.name == 'nt':
        temp = os.environ.get('TMP')
    else:
        temp = '/tmp'

    if message.voice:
        bot.send_chat_action(message.chat.id, 'record_audio')
        # download the file
        file_info = bot.get_file(message.voice.file_id)
        voice_file = requests.get(
            'https://api.telegram.org/file/bot{0}/{1}'.format(
                TOKEN, file_info.file_path))
        file_path = temp + os.sep
        with open(file_path + message.voice.file_id + '.ogg', 'wb') as f:
            f.write(voice_file.content)
        message.text = speech.voice_to_text(file_path,
                                            message.voice.file_id + '.ogg')

    if u'4C7' in message.text:
        bot.send_chat_action(message.chat.id, 'typing')
        r = utils.reply_refuse()
        bot.send_message(message.chat.id, r)
    elif message.text.isdigit():
        bot.send_chat_action(message.chat.id, 'typing')
        r = kuaidi100.recv(message.text, message.message_id, message.chat.id)
        if u'单号不存在或者已经过期' in r:
            bot.send_message(message.chat.id, '汝的单号可能刚刚生成,暂无信息,不如稍后试试?')
        else:
            bot.send_message(message.chat.id, r, parse_mode='Markdown')
    # use turing bot
    elif TURING_KEY == '':
        bot.send_chat_action(message.chat.id, 'typing')
        r = utils.reply_refuse()
        bot.send_message(message.chat.id, r)
    else:
        bot.send_chat_action(message.chat.id, 'typing')
        r = turing.send_turing(TURING_KEY, message.text, message.chat.id)
        bot.send_message(message.chat.id, r)

    return r
Exemple #6
0
def cron(code, mid, cid, db_content):
    """
    cron job process for timer.py
    :param code: express id
    :param mid: message id for reply_to_message
    :param cid: chat_id(a.k.a user_id)
    :param db_content: old express status in database
    :return: None
    """

    r = kuaidi100.recv(code, mid, cid)
    # suppress maximum 2000 queries
    if db_content not in r and r != u'非法访问:IP禁止访问':
        try:
            bot.send_message(chat_id=cid, reply_to_message_id=mid, text=r)
        except telebot.apihelper.ApiException as e:
            print(e.message)
Exemple #7
0
def track_express(message):
    """
    process ordinary message, all digits means express id. Otherwise active Turing or refuse message
    :param message: Telegram message sent by user.
    :return: None
    """
    if message.text.isdigit():
        bot.send_chat_action(message.chat.id, 'typing')
        r = kuaidi100.recv(message.text, message.message_id, message.chat.id)
        bot.send_message(message.chat.id, r)
    # use turing bot
    elif TURING_KEY == '':
        bot.send_chat_action(message.chat.id, 'typing')
        bot.send_message(message.chat.id, utils.reply_refuse())
    else:
        bot.send_chat_action(message.chat.id, 'typing')
        r = turing.send_turing(TURING_KEY, message.text, message.chat.id)
        bot.send_message(message.chat.id, r)
Exemple #8
0
def cron(code, mid, cid, db_content):
    r = kuaidi100.recv(code, mid, cid)
    if db_content not in r:
        bot.send_message(chat_id=cid, reply_to_message_id=mid, text=db_content)