Python telepot 模块,message_identifier() 实例源码

我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用telepot.message_identifier()

项目:pockebot    作者:Fillll    | 项目源码 | 文件源码
def on_callback_query(self, msg):
        query_id, self.request_chat_id, query_data = telepot.glance(msg, flavor='callback_query')
        self.mongo.chat_id = self.request_chat_id
        self.store_contacts(msg)
        self.known_user = self.is_user_known()
        self.__debug_print('>')
        self.__debug_print('> callback')
        self.__debug_print(msg)
        to_send_msg, keyboard = self.process_command(query_data)

        if to_send_msg is None:
            await self._editor.editMessageReplyMarkup(reply_markup=keyboard)
            self.waiting_for_menu_action = True
        else:
            await self._cancel_last()
            sent = await self.sender.sendMessage(to_send_msg, reply_markup=keyboard, parse_mode='Markdown')
            self._editor = telepot.aio.helper.Editor(self.bot, sent)
            self._edit_msg_ident = telepot.message_identifier(sent)
            self.waiting_for_menu_action = False
项目:MensaUniurbBot    作者:Radeox    | 项目源码 | 文件源码
def edit_msg_news(msg):
    """
    Edit last message sent to all users
    """
    for user in get_user_list():
        try:
            edited = telepot.message_identifier(TEMP[user]['sent'])
            bot.editMessageText(edited, msg, parse_mode="Markdown")
        except:
            continue
    return 1
项目:MensaUniurbBot    作者:Radeox    | 项目源码 | 文件源码
def delete_msg_news():
    """
    Delete last message sent to all users
    """
    for user in get_user_list():
        try:
            edited = telepot.message_identifier(TEMP[user]['sent'])
            bot.deleteMessage(edited)
        except:
            continue
    return 1
项目:Telyrics    作者:hamedafra    | 项目源码 | 文件源码
def print_search(self, keyboard, msg):
        sent = self.sender.sendMessage("Showing results for '" + msg['text'] + "'", reply_markup=keyboard)
        self._editor = telepot.helper.Editor(self.bot, sent)
        self._edit_msg_ident = telepot.message_identifier(sent)
项目:Telyrics    作者:hamedafra    | 项目源码 | 文件源码
def get_translate(self, text):
        text = text.replace("text:", "")
        blob = TextBlob(text)
        lan = blob.detect_language()
        if lan != 'en':
            sentp = blob.translate(to="en")
        else:
            sentp = blob.translate(to="fa")
        sent = self.sender.sendMessage(str(sentp))
        self._editor = telepot.helper.Editor(self.bot, sent)
        self._edit_msg_ident = telepot.message_identifier(sent)
项目:grovebot    作者:mrsofia    | 项目源码 | 文件源码
def save_link(msg):
    entry = Link.create(
        user=msg.get('from').get('username'),
        message=msg.get('text'),
        time=unix_time_to_python_time(msg.get('date')),
        link=get_link(msg)
    )
    entry.save()


# This dictionary keeps track of how fire a track is.
# The key is the message_identifier of the message containing the link, the value is a list
# of the message_identifier of the fuego display and a list of IDs that have sent fuegos.
项目:grovebot    作者:mrsofia    | 项目源码 | 文件源码
def get_fuego(msg):
    callback_data = str(telepot.message_identifier(msg))
    markup = InlineKeyboardMarkup(inline_keyboard=[
        [InlineKeyboardButton(text='up-fuego \U0001f525', callback_data=callback_data)]
    ])
    user = get_user_identifier(msg)
    bot_msg = bot.sendMessage(msg["chat"]["id"], user +
                              ' with the new hotness!\n', reply_markup=markup)
    fuego_count[callback_data] = [telepot.message_identifier(bot_msg), [], []]
项目:archiveis-tg    作者:raku-cat    | 项目源码 | 文件源码
def on_callback_query(msg):
    query_id, chat_id, query_data = telepot.glance(msg, flavor='callback_query')
#    print(msg)
#    print(query_data)
    print('Recieved query ' + query_id)
    url = msg['message']['reply_to_message']['text'].split(' ')[1]
    msg_idf = telepot.message_identifier(msg['message'])
    callback_text = ''
    global delay
    if query_data == 'save':
        if delay != '':
            if datetime.datetime.now() > delay:
                r = requests.get('https://archive.fo/')
                html = r.text
                soup = BeautifulSoup(html, 'lxml')
                submitid = soup.find('input').get('value')
                headers = { 'User-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36' }
                values = { 'submitid': submitid, 'url': url, 'anyway': '1' }
                r = requests.post('https://archive.fo/submit/', data=values, headers=headers)
                uri = r.text
                archive_uri = uri.split('"')[1]
                delay = datetime.datetime.now() + datetime.timedelta(minutes=3)
                if 'archive.fo' in archive_uri:
                    pass
                else:
                    callback_text = 'Something went wrong, let @raku_cat know'
            else:
                callback_text = 'Saving on cooldown, please try again in a few miniutes.'
    else:
        uri = msg['message']['text']
        foo, keyboard = link_handler(url)
        dt = uri.split('/')[3]
        dt = datetime.datetime.strptime(dt, '%Y%m%d%H%M%S')
        timegate = 'https://archive.fo/timegate/'
        mc = MementoClient(timegate_uri=timegate, check_native_timegate=False)
        if query_data == 'back':
            try:
                archive_uri = mc.get_memento_info(url, dt).get('mementos').get('prev').get('uri')[0]
            except AttributeError:
                callback_text = 'No older archives or something went wrong.'
        elif query_data == 'next':
            try:
               archive_uri = mc.get_memento_info(uri, dt).get('mementos').get('next').get('uri')[0]
            except AttributeError:
               callback_text = 'No newer archives or something went wrong.'
    try:
        bot.editMessageText(msg_idf, archive_uri)
    except:
        pass
    try:
        bot.editMessageText(msg_idf, archive_uri, reply_markup=keyboard)
    except:
        pass
    bot.answerCallbackQuery(query_id, text=callback_text)
    print('Responding to callback ' + query_id)
项目:pockebot    作者:Fillll    | 项目源码 | 文件源码
def on_chat_message(self, msg):
        content_type, chat_type, self.request_chat_id = telepot.glance(msg)
        self.mongo.chat_id = self.request_chat_id
        self.store_contacts(msg)
        self.known_user = self.is_user_known()
        self.__debug_print('>')
        # self.__debug_print(msg)

        if self.waiting_for_menu_action is True:
            await self._cancel_last()
        self.waiting_for_menu_action = False

        any_commands = self.has_command(msg)

        if 'text' not in msg:
            msg['text'] = '±notext±'

        if chat_type == 'private':

            keyboard = {'hide_keyboard': True}
            to_send_msg = self.say('pocket_error')
            self.visit_time += 1
            inbox = msg['text']

            if any_commands and (self.known_user or (not self.known_user and inbox != '/start Done' and inbox != '/start')):
                to_send_msg, keyboard = self.process_command(inbox)
            else:
                if self.known_user:
                    urls, tags = self.get_urls_and_tags(msg)
                    if len(urls) > 0 or len(tags) > 0:
                        to_send_msg, keyboard = await self.add(urls, tags, inbox)
                        if len(urls) > 0 and self.audio is True:
                            filename = self.need_audio()
                            if filename is not None:
                                f = open(join('audio', filename), 'rb')
                                await self.sender.sendVoice(f, reply_markup=keyboard)
                    else:
                        self.messages.append(msg)
                        to_send_msg, keyboard = self.say('nothing'), {'hide_keyboard': True}
                else:
                    to_send_msg = self.make_authorization()

            # Send message. Always update keyboard and always `Markdown` mode. Be careful messages
            # with `_` in text are dagerous.
            sent = await self.sender.sendMessage(to_send_msg, reply_markup=keyboard, parse_mode='Markdown')
            self._editor = telepot.aio.helper.Editor(self.bot, sent)
            self._edit_msg_ident = telepot.message_identifier(sent)