• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python telepot.glance2函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中telepot.glance2函数的典型用法代码示例。如果您正苦于以下问题:Python glance2函数的具体用法?Python glance2怎么用?Python glance2使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了glance2函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: handle

def handle(msg):
    flavor = telepot.flavor(msg)

    # normal message
    if flavor == "normal":
        content_type, chat_type, chat_id = telepot.glance2(msg)
        print("Normal Message:", content_type, chat_type, chat_id)

        # Do your stuff according to `content_type` ...

    # inline query - need `/setinline`
    elif flavor == "inline_query":
        query_id, from_id, query_string = telepot.glance2(msg, flavor=flavor)
        print("Inline Query:", query_id, from_id, query_string)

        # Compose your own answers
        articles = [{"type": "article", "id": "abc", "title": "ABC", "message_text": "Good morning"}]

        yield from bot.answerInlineQuery(query_id, articles)

    # chosen inline result - need `/setinlinefeedback`
    elif flavor == "chosen_inline_result":
        result_id, from_id, query_string = telepot.glance2(msg, flavor=flavor)
        print("Chosen Inline Result:", result_id, from_id, query_string)

        # Remember the chosen answer to do better next time

    else:
        raise telepot.BadFlavor(msg)
开发者ID:August85,项目名称:telepot,代码行数:29,代码来源:webhook_aiohttp_skeletona.py


示例2: handle

def handle(msg):
    flavor = telepot.flavor(msg)

    # a normal message
    if flavor == 'normal':
        content_type, chat_type, chat_id = telepot.glance2(msg)
        print content_type, chat_type, chat_id

        # Do your stuff according to `content_type` ...

    # an inline query - only AFTER `/setinline` has been done for the bot.
    elif flavor == 'inline_query':
        query_id, from_id, query_string = telepot.glance2(msg, flavor=flavor)
        print 'Inline Query:', query_id, from_id, query_string

        # Compose your own answers
        articles = [{'type': 'article',
                        'id': 'abc', 'title': 'ABC', 'message_text': 'Good morning'}]

        bot.answerInlineQuery(query_id, articles)

    # a chosen inline result - only AFTER `/setinlinefeedback` has been done for the bot.
    elif flavor == 'chosen_inline_result':
        result_id, from_id, query_string = telepot.glance2(msg, flavor=flavor)
        print 'Chosen Inline Result:', result_id, from_id, query_string

        # Remember the chosen answer to do better next time

    else:
        raise telepot.BadFlavor(msg)
开发者ID:jlbmdm,项目名称:telepot,代码行数:30,代码来源:skeleton.py


示例3: handle

    def handle(self, msg):
        flavor = telepot.flavor(msg)

        # normal message
        if flavor == 'normal':
            content_type, chat_type, chat_id = telepot.glance2(msg)
            print('Normal Message:', content_type, chat_type, chat_id)

            # Do your stuff according to `content_type` ...

        # inline query - need `/setinline`
        elif flavor == 'inline_query':
            query_id, from_id, query_string = telepot.glance2(msg, flavor=flavor)
            print('Inline Query:', query_id, from_id, query_string)

            # Compose your own answers
            articles = [{'type': 'article',
                            'id': 'abc', 'title': 'ABC', 'message_text': 'Good morning'}]

            bot.answerInlineQuery(query_id, articles)

        # chosen inline result - need `/setinlinefeedback`
        elif flavor == 'chosen_inline_result':
            result_id, from_id, query_string = telepot.glance2(msg, flavor=flavor)
            print('Chosen Inline Result:', result_id, from_id, query_string)

            # Remember the chosen answer to do better next time

        else:
            raise telepot.BadFlavor(msg)
开发者ID:August85,项目名称:telepot,代码行数:30,代码来源:skeleton_extend.py


示例4: answer

def answer(msg):
    flavor = telepot.flavor(msg)

    if flavor == "inline_query":
        query_id, from_id, query = telepot.glance2(msg, flavor=flavor)

        if from_id != USER_ID:
            print "Unauthorized user:", from_id
            return

        examine(msg, "InlineQuery")

        articles = [
            InlineQueryResultArticle(
                id="abc", title="HK", message_text="Hong Kong", url="https://www.google.com", hide_url=True
            ),
            {"type": "article", "id": "def", "title": "SZ", "message_text": "Shenzhen", "url": "https://www.yahoo.com"},
        ]

        photos = [
            InlineQueryResultPhoto(
                id="123",
                photo_url="https://core.telegram.org/file/811140934/1/tbDSLHSaijc/fdcc7b6d5fb3354adf",
                thumb_url="https://core.telegram.org/file/811140934/1/tbDSLHSaijc/fdcc7b6d5fb3354adf",
            ),
            {
                "type": "photo",
                "id": "345",
                "photo_url": "https://core.telegram.org/file/811140184/1/5YJxx-rostA/ad3f74094485fb97bd",
                "thumb_url": "https://core.telegram.org/file/811140184/1/5YJxx-rostA/ad3f74094485fb97bd",
                "caption": "Caption",
                "title": "Title",
                "message_text": "Message Text",
            },
        ]

        results = random.choice([articles, photos])

        bot.answerInlineQuery(query_id, results)

    elif flavor == "chosen_inline_result":
        result_id, from_id, query = telepot.glance2(msg, flavor=flavor)

        if from_id != USER_ID:
            print "Unauthorized user:", from_id
            return

        examine(msg, "ChosenInlineResult")

        print "Chosen inline query:"
        pprint.pprint(msg)

    else:
        raise telepot.BadFlavor(msg)
开发者ID:jlbmdm,项目名称:telepot,代码行数:54,代码来源:test27_inline.py


示例5: handle

    def handle(self, msg):
        flavor = telepot.flavor(msg)

        # a normal message
        if flavor == 'normal':
            content_type, chat_type, chat_id = telepot.glance2(msg)
            print(content_type, chat_type, chat_id)

            # Do your stuff according to `content_type` ...

        # an inline query - possible only AFTER `/setinline` has been done for the bot.
        elif flavor == 'inline_query':
            query_id, from_id, query_string = telepot.glance2(msg, flavor=flavor)
            print(query_id, from_id, query_string)
开发者ID:stamsarger,项目名称:telepot,代码行数:14,代码来源:skeleton_extend.py


示例6: handle

def handle(msg):
    flavor = telepot.flavor(msg)
    # normal message
    if flavor == 'normal':
        content_type, chat_type, chat_id = telepot.glance2(msg)
        print('Normal Message:', content_type, chat_type, chat_id)
        command = msg['text']
        if command == '/start':
        	start(chat_id)
        elif command == '/eagles':
        	news_command_handler(chat_id, 'eagles')
        elif command == '/flyers':
        	news_command_handler(chat_id, 'flyers')
        elif command == '/sixers':
        	news_command_handler(chat_id, 'sixers')
        elif command == '/phillies':
        	news_command_handler(chat_id, 'phillies')
        elif command == '/help':
        	help(chat_id)
        elif command == '/settings':
        	settings(chat_id)
        else:
        	unknown(chat_id)

        return('Message sent')

        # Do your stuff according to `content_type` ...

    # inline query - need `/setinline`
    elif flavor == 'inline_query':
        query_id, from_id, query_string = telepot.glance2(msg, flavor=flavor)
        print('Inline Query:', query_id, from_id, query_string)

        # Compose your own answers
        articles = [{'type': 'article',
                        'id': 'abc', 'title': 'ABC', 'message_text': 'Good morning'}]

        bot.answerInlineQuery(query_id, articles)

    # chosen inline result - need `/setinlinefeedback`
    elif flavor == 'chosen_inline_result':
        result_id, from_id, query_string = telepot.glance2(msg, flavor=flavor)
        print('Chosen Inline Result:', result_id, from_id, query_string)

        # Remember the chosen answer to do better next time

    else:
        raise telepot.BadFlavor(msg)
开发者ID:mamcmanus,项目名称:PhillyBot,代码行数:48,代码来源:philly_bot.py


示例7: see_every_content_types

def see_every_content_types(msg):
    global expected_content_type, content_type_iterator

    flavor = telepot.flavor(msg)

    if flavor == "normal":
        content_type, chat_type, chat_id = telepot.glance2(msg)
        from_id = msg["from"]["id"]

        if chat_id != USER_ID and from_id != USER_ID:
            print "Unauthorized user:", chat_id, from_id
            return

        examine(msg, "Message")
        try:
            if content_type == expected_content_type:
                expected_content_type = content_type_iterator.next()
                bot.sendMessage(chat_id, "Please give me a %s." % expected_content_type)
            else:
                bot.sendMessage(
                    chat_id,
                    "It is not a %s. Please give me a %s, please." % (expected_content_type, expected_content_type),
                )
        except StopIteration:
            # reply to sender because I am kicked from group already
            bot.sendMessage(from_id, "Thank you. I am done.")

    else:
        raise telepot.BadFlavor(msg)
开发者ID:stamsarger,项目名称:telepot,代码行数:29,代码来源:test27_updates.py


示例8: handle

def handle(msg):
    content_type, chat_type, chat_id = telepot.glance2(msg)
    m = telepot.namedtuple.namedtuple(msg, 'Message')

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

    if content_type == 'text':
        if msg['text'] == '/start':
            yield from bot.sendMessage(chat_id,  # Welcome message
                                       "You send me an Emoji"
                                       "\nI give you the Unicode"
                                       "\n\nOn Python 2, remember to prepend a 'u' to unicode strings,"
                                       "e.g. \U0001f604 is u'\\U0001f604'")
            return

        reply = ''

        # For long messages, only return the first 10 characters.
        if len(msg['text']) > 10:
            reply = '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')

        logger.info('>>> %s', reply)
        yield from bot.sendMessage(chat_id, reply)
开发者ID:stamsarger,项目名称:telepot,代码行数:33,代码来源:emodia.py


示例9: handle

def handle(msg):
	global user_state
# 	pprint.pprint(msg)
	content_type, chat_type, chat_id = telepot.glance2(msg)
	validUser = False

	# Only respond valid users
	for user in user_ids:
		if chat_id == user:
			validUser = True
		
	if validUser == False:
		return

	# Ignore non-text message
	if content_type != 'text':
		return

	command = msg['text'].strip().lower().split()

	if command[0] == '/start':
		showMainKeyboard(chat_id, user_state)
	elif command[0] == '/close':
		hide_keyboard = {'hide_keyboard': True}
		bot.sendMessage(chat_id, 'Closing light control', reply_markup=hide_keyboard)
	else:
		lights(chat_id, command[0])
开发者ID:davidgannerud,项目名称:telegram-tellstick,代码行数:27,代码来源:telegramtellstick.py


示例10: on_message

    def on_message(self, msg):
        content_type, chat_type, chat_id = telepot.glance2(msg)

        if content_type != 'text':
            self.sender.sendMessage('Give me two numbers, please.')
            return

        try:
            m = msg['text'].strip().split()
            m1 = int(m[0])
            m2 = int(m[1])
            if len(m) > 2:
                raise ValueError
        except :
            self.sender.sendMessage('Give two numbers correctly, please.')
            return

        # check the guess against the answer ...
        if m1 * m2 != self._answer:
            # give a descriptive hint
            hint = self._hint(self._answer, m1, m2)
            self.sender.sendMessage(hint)
        else:
            self.sender.sendMessage('Correct!')
            self.close()
开发者ID:nsreehari,项目名称:bots,代码行数:25,代码来源:factors.py


示例11: insertBirthday

def insertBirthday(msg):
	# Parse info from message
	content_type, chat_type, chat_id = telepot.glance2(msg)

	# Open BD of the group
	birthdayBD = shelve.open("BD" + str(chat_id))

	# Stores user name
	userName = msg['from']['first_name'] + " " + msg['from']['last_name']

	# Stores original message
	command = msg['text'].split(' ')

	if(len(command) == 3):
		try:
			day = int(command[1])
			month = int(command[2])
		except TypeError:
			print("Can't convert string to int")
			return 0

		if(day > 0 and day <= 31 and month > 0 and month <= 12):
			birthdayBD[str(msg['from']['id'])] = [userName, day, month]
			birthdayBD.close()
			bot.sendMessage(chat_id, "Birthday stored.")
			updateScheduler()
	else:
		bot.sendMessage(chat_id, "Bad formating, try again using '/bday dd mm' \ndd = day \nmm = month ")

	return 0
开发者ID:faellacurcio,项目名称:Osob_bot,代码行数:30,代码来源:app.py


示例12: handle_message

def handle_message(msg):
    global active, bigrams, trigrams, weight, aB, aT, aW, mB, mT, mW, tB, tT, tW
    msg_type, chat_type, chat_id = telepot.glance2(msg)
    if msg_type != 'text':
        return
    input = msg['text']
    reply_id = chat_id
    if "/changebot_first" in input and active!='first':
        bigrams, trigrams, weight = aB, aT, aW
        active = 'first'
        print "first loaded"
        bot.sendMessage(reply_id, "first bot here")

    elif "/changebot_second" in input and active!='second':
        bigrams, trigrams, weight = mB, mT, mW
        active = 'second'
        print "second loaded"
        bot.sendMessage(reply_id, "second bot here")

    elif "/changebot_third" in input and active!='third':
        bigrams, trigrams, weight = tB, tT, tW
        active = 'third'
        print "third loaded"
        bot.sendMessage(reply_id, "third bot here")

    else:
        try:
            bot.sendMessage(reply_id, genSentence(input, weight, bigrams, trigrams))
        except:
            bot.sendMessage(reply_id, "U WOT M8?")
开发者ID:AWilcke,项目名称:uAI,代码行数:30,代码来源:smallbot.py


示例13: handle

def handle(msg):
	content_type, chat_type, chat_id = telepot.glance2(msg)
	
	chat_id = msg['chat']['id']
	command = msg['text']

	if '@' in command:
		command, botname = command.split('@')
	
	command = command.replace("/", "")
        
        if command == "start":
            bot.sendMessage(chat_id, "Send /rrr to see if the RRR summerbar is currently open.\nAlso don't slap pandas  

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python delegate.create_open函数代码示例发布时间:2022-05-27
下一篇:
Python telepot.glance函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap