當前位置: 首頁>>代碼示例>>Python>>正文


Python telepot.glance方法代碼示例

本文整理匯總了Python中telepot.glance方法的典型用法代碼示例。如果您正苦於以下問題:Python telepot.glance方法的具體用法?Python telepot.glance怎麽用?Python telepot.glance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在telepot的用法示例。


在下文中一共展示了telepot.glance方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: chat_handler

# 需要導入模塊: import telepot [as 別名]
# 或者: from telepot import glance [as 別名]
def chat_handler(self, msg):
		content_type, chat_type, chat_id = telepot.glance(msg)
		
		if content_type != "text":
			return

		# Authentication
		if chat_id != self.chat_id:
			if msg["text"] == BOT_TOKEN:
				self.register_chat(chat_id)
				self.bot.sendMessage(chat_id, "Authenticated.")
			else:
				self.bot.sendMessage(chat_id, "Not authenticated. Send me this bot token to authenticate this chat.")
				return

		replies = self.get_chat_replies(msg)

		for reply in replies:
			messsage, keyboard = reply
			self.bot.sendMessage(self.chat_id, messsage, reply_markup=keyboard) 
開發者ID:stephancill,項目名稱:mcafee2cash,代碼行數:22,代碼來源:telegram.py

示例2: on_chat_message

# 需要導入模塊: import telepot [as 別名]
# 或者: from telepot import glance [as 別名]
def on_chat_message(self, msg):
        # If the data sent is not test, return an error
        content_type, chat_type, chat_id = telepot.glance(msg)

        if content_type != 'text':
            self.sender.sendMessage("I don't understand you. "
                                    "Please type 'help' for options",
                                    reply_markup=KEYBOARD)
            return

        # Make the commands case insensitive
        command = msg['text'].lower()
        if command not in COMMANDS:
            self.sender.sendMessage("I don't understand you. "
                                    "Please type 'help' for options",
                                    reply_markup=KEYBOARD)
            return

        message = COMMANDS[command]()
        self.sender.sendMessage(message, reply_markup=KEYBOARD) 
開發者ID:PacktPublishing,項目名稱:Python-Automation-Cookbook,代碼行數:22,代碼來源:telegram_bot_custom_keyboard.py

示例3: on_chat_message

# 需要導入模塊: import telepot [as 別名]
# 或者: from telepot import glance [as 別名]
def on_chat_message(self, msg):
        # If the data sent is not test, return an error
        content_type, chat_type, chat_id = telepot.glance(msg)

        if content_type != 'text':
            self.sender.sendMessage("I don't understand you. "
                                    "Please type 'help' for options")
            return

        # Make the commands case insensitive
        command = msg['text'].lower()
        if command not in COMMANDS:
            self.sender.sendMessage("I don't understand you. "
                                    "Please type 'help' for options")
            return

        message = COMMANDS[command]()
        self.sender.sendMessage(message) 
開發者ID:PacktPublishing,項目名稱:Python-Automation-Cookbook,代碼行數:20,代碼來源:telegram_bot.py

示例4: on_callback_query

# 需要導入模塊: import telepot [as 別名]
# 或者: from telepot import glance [as 別名]
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 
開發者ID:Fillll,項目名稱:pockebot,代碼行數:21,代碼來源:main_app.py

示例5: on_inline_query

# 需要導入模塊: import telepot [as 別名]
# 或者: from telepot import glance [as 別名]
def on_inline_query(message):
    query_id, from_id, query = telepot.glance(message, flavor='inline_query')
    global plugins

    @asyncio.coroutine
    def get_inline():
        for plugin in plugins:
            if 'inline_query' in plugin:
                for pattern in plugin['inline_patterns']:
                    if re.search(pattern, query, re.IGNORECASE|re.MULTILINE):
                        matches = re.findall(pattern, query, re.IGNORECASE)
                        return_values = yield from plugin['inline_query'](message, matches[0], from_id, 0)
                        if return_values:
                            return {'results': return_values, 'cache_time': 0}
                        break
        return []
    try:
        answerer.answer(message, get_inline)

    except:
        pass 
開發者ID:siyanew,項目名稱:Siarobo,代碼行數:23,代碼來源:bot.py

示例6: inline

# 需要導入模塊: import telepot [as 別名]
# 或者: from telepot import glance [as 別名]
def inline(message, matches, chat_id, step):
    query_id, from_id, query = telepot.glance(message, flavor='inline_query')
    response = requests.get(query)
    soup = BeautifulSoup(response.text, "html.parser")
    image = soup.find("meta", {"property": "og:image"})
    video = soup.find("meta", {"property": "og:video"})
    if video:
        width = soup.find("meta", {"property": "og:video:width"})
        height = soup.find("meta", {"property": "og:video:height"})
        return [InlineQueryResultVideo(
            id=str(uuid.uuid4()), description='Instagram Video', title="Instagram Video", mime_type="video/mp4",
            thumb_url=image['content'], video_url=video['content'], video_width=int(width['content']),
            video_height=int(height['content']))]
    elif image:
        return [InlineQueryResultPhoto(
            id=str(uuid.uuid4()), title="Instagram Photo",
            photo_url=image['content'], photo_width=300, photo_height=300,
            thumb_url=image['content'])]
    else:
        return [InlineQueryResultArticle(
            id=str(uuid.uuid4()), title='Error', description="Not Found",
            input_message_content=InputTextMessageContent(message_text="Error\nNot Found", parse_mode="Markdown"),
            thumb_url="http://siyanew.com/bots/custom.jpg")] 
開發者ID:siyanew,項目名稱:Siarobo,代碼行數:25,代碼來源:instagram.py

示例7: on_callback_query

# 需要導入模塊: import telepot [as 別名]
# 或者: from telepot import glance [as 別名]
def on_callback_query(message):
    try:
        if not 'game_short_name' in message:
            query_id, from_id, data = telepot.glance(message, flavor='callback_query')
            for plugin in plugins:
                if 'callback' in plugin:
                    for pattern in plugin['callback_patterns']:
                        if re.search(pattern, data, re.IGNORECASE | re.MULTILINE):
                            matches = re.findall(pattern, data, re.IGNORECASE)
                            return_value = yield from plugin['callback'](message, matches[0],
                                                                     message['message']['chat']['id'])
                            if return_value:
                                yield from sender(return_value)
                            break
    except Exception as e:
        print(e) 
開發者ID:MOHAMADKHOSHNAVA,項目名稱:spntaBot,代碼行數:18,代碼來源:bot.py

示例8: on_inline_query

# 需要導入模塊: import telepot [as 別名]
# 或者: from telepot import glance [as 別名]
def on_inline_query(message):
    query_id, from_id, query = telepot.glance(message, flavor='inline_query')
    global plugins

    @asyncio.coroutine
    def get_inline():
        for plugin in plugins:
            if 'inline_query' in plugin:
                for pattern in plugin['inline_patterns']:
                    if re.search(pattern, query, re.IGNORECASE | re.MULTILINE):
                        matches = re.findall(pattern, query, re.IGNORECASE)
                        return_values = yield from plugin['inline_query'](message, matches[0], from_id, 0)
                        if return_values:
                            return {'results': return_values, 'cache_time': 0}
                        break
        return []

    try:
        answerer.answer(message, get_inline)

    except:
        pass 
開發者ID:MOHAMADKHOSHNAVA,項目名稱:spntaBot,代碼行數:24,代碼來源:bot.py

示例9: handle

# 需要導入模塊: import telepot [as 別名]
# 或者: from telepot import glance [as 別名]
def handle(msg):
    content_type, chat_type, chat_id = telepot.glance(msg)
    print 'Chat Message:', content_type, chat_type, chat_id

    if content_type == 'text':
        text = msg['text']
        print 'Text:', text

        if text.startswith('/start'):
            try:
                command, payload = text.split(' ')

                print 'Payload:', payload
                print 'User ID:', key_id_map[payload]
                print 'chat_id:', chat_id

            except ValueError:
                print 'No payload, or more than one chunk of payload'

            except KeyError:
                print 'Invalid key, no corresponding User ID' 
開發者ID:nickoala,項目名稱:telepot,代碼行數:23,代碼來源:flask_deeplinking.py

示例10: send_invoice

# 需要導入模塊: import telepot [as 別名]
# 或者: from telepot import glance [as 別名]
def send_invoice(seed_tuple):
    msg = seed_tuple[1]

    content_type, chat_type, chat_id = telepot.glance(msg)

    if content_type == 'text':
        sent = bot.sendInvoice(
                   chat_id, "Nick's Hand Cream", "Keep a man's hand like a woman's",
                   payload='a-string-identifying-related-payment-messages-tuvwxyz',
                   provider_token=PAYMENT_PROVIDER_TOKEN,
                   start_parameter='abc',
                   currency='HKD', prices=[
                       LabeledPrice(label='One Case', amount=987),
                       LabeledPrice(label='Package', amount=12)],
                   need_shipping_address=True, is_flexible=True)  # required for shipping query

        print('Invoice sent:')
        pprint(sent) 
開發者ID:nickoala,項目名稱:telepot,代碼行數:20,代碼來源:payment.py

示例11: send_invoice

# 需要導入模塊: import telepot [as 別名]
# 或者: from telepot import glance [as 別名]
def send_invoice(seed_tuple):
    msg = seed_tuple[1]

    content_type, chat_type, chat_id = telepot.glance(msg)

    if content_type == 'text':
        sent = await bot.sendInvoice(
                   chat_id, "Nick's Hand Cream", "Keep a man's hand like a woman's",
                   payload='a-string-identifying-related-payment-messages-tuvwxyz',
                   provider_token=PAYMENT_PROVIDER_TOKEN,
                   start_parameter='abc',
                   currency='HKD', prices=[
                       LabeledPrice(label='One Case', amount=987),
                       LabeledPrice(label='Package', amount=12)],
                   need_shipping_address=True, is_flexible=True)  # required for shipping query

        print('Invoice sent:')
        pprint(sent) 
開發者ID:nickoala,項目名稱:telepot,代碼行數:20,代碼來源:paymenta.py

示例12: on_chat_message

# 需要導入模塊: import telepot [as 別名]
# 或者: from telepot import glance [as 別名]
def on_chat_message(self, msg):
        content_type, chat_type, chat_id = telepot.glance(msg)
        self.sender.sendMessage(
            'Press START to do some math ...',
            reply_markup=InlineKeyboardMarkup(
                inline_keyboard=[[
                    InlineKeyboardButton(text='START', callback_data='start'),
                ]]
            )
        )
        self.close()  # let Quizzer take over 
開發者ID:nickoala,項目名稱:telepot,代碼行數:13,代碼來源:quiz.py

示例13: on_chat_message

# 需要導入模塊: import telepot [as 別名]
# 或者: from telepot import glance [as 別名]
def on_chat_message(self, msg):
        content_type, chat_type, chat_id = glance(msg)
        await self.sender.sendMessage(
            'Press START to do some math ...',
            reply_markup=InlineKeyboardMarkup(
                inline_keyboard=[[
                    InlineKeyboardButton(text='START', callback_data='start'),
                ]]
            )
        )
        self.close()  # let Quizzer take over 
開發者ID:nickoala,項目名稱:telepot,代碼行數:13,代碼來源:quiza.py

示例14: handle

# 需要導入模塊: import telepot [as 別名]
# 或者: from telepot import glance [as 別名]
def handle(msg):
    content_type, chat_type, chat_id = telepot.glance(msg)
    m = telepot.namedtuple.Message(**msg)

    if chat_id < 0:
        # group message
        print 'Received a %s from %s, by %s' % (content_type, m.chat, m.from_)
    else:
        # private message
        print 'Received a %s from %s' % (content_type, m.chat)  # m.chat == m.from_

    if content_type == 'text':
        reply = ''

        # For long messages, only return the first 10 characters.
        if len(msg['text']) > 10:
            reply = u'First 10 characters:\n'

        # Length-checking and substring-extraction may work differently
        # depending on Python versions and platforms. See above.

        reply += msg['text'][:10].encode('unicode-escape').decode('ascii')
        bot.sendMessage(chat_id, reply) 
開發者ID:nickoala,項目名稱:telepot,代碼行數:25,代碼來源:emodi.py

示例15: on_callback_query

# 需要導入模塊: import telepot [as 別名]
# 或者: from telepot import glance [as 別名]
def on_callback_query(msg):
    query_id, from_id, data = telepot.glance(msg, flavor='callback_query')
    print('Callback query:', query_id, from_id, data)

    if data == 'notification':
        await bot.answerCallbackQuery(query_id, text='Notification at top of screen')
    elif data == 'alert':
        await bot.answerCallbackQuery(query_id, text='Alert!', show_alert=True)
    elif data == 'edit':
        global message_with_inline_keyboard

        if message_with_inline_keyboard:
            msg_idf = telepot.message_identifier(message_with_inline_keyboard)
            await bot.editMessageText(msg_idf, 'NEW MESSAGE HERE!!!!!')
        else:
            await bot.answerCallbackQuery(query_id, text='No previous message to edit') 
開發者ID:nickoala,項目名稱:telepot,代碼行數:18,代碼來源:skeletona_route.py


注:本文中的telepot.glance方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。