当前位置: 首页>>代码示例>>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;未经允许,请勿转载。