当前位置: 首页>>代码示例>>Python>>正文


Python telepot.flavor函数代码示例

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


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

示例1: 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

示例2: handle

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

	if flavor == 'normal':
		bot.sendMessage(chat_id,"Ok")
		print 'Normal message'

	elif flavor == 'inline_query':
		query_id, from_id, query_string = telepot.glance(msg, flavor='inline_query')
		print from_id
		if len(query_string)>=3:
			filelist=find(query_string) 

			#print filelist
			articles=[]
			id=0
			for filename in filelist:
				articles.append(InlineQueryResultArticle(id=filename, title=os.path.splitext(filename)[0], message_text=os.path.splitext(filename)[0]))
				id+=1
			
			print articles
			bot.answerInlineQuery(query_id, articles)

	elif flavor == 'chosen_inline_result':
		print  "chosen_inline_result"
		result_id, from_id, query_string = telepot.glance(msg, flavor='chosen_inline_result')
		print result_id
		print from_id
		f = open("mp3/"+ result_id, 'rb')
		#bot.sendDocument(from_id,f)
		bot.sendMessage(from_id,"Ok")
开发者ID:tanzilli,项目名称:TanzoLab,代码行数:31,代码来源:inline.py

示例3: handle

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

    # normal message
    if flavor == "normal":
        content_type, chat_type, chat_id = telepot.glance(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.glance(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.glance(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:salejovg,项目名称:telepot,代码行数:29,代码来源:webhook_flask_skeleton.py

示例4: 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

示例5: callback_function

def callback_function(msg):
    flavor = telepot.flavor(msg)
    if flavor == 'callback_query':
        print "callback!!"
    elif flavor == 'chat':
        print "normal message"
        return
开发者ID:yewsiang,项目名称:botmother,代码行数:7,代码来源:NUSQuestionBot.py

示例6: handle_msg

def handle_msg(msg):
    flavor = telepot.flavor(msg)
    # print(flavor)
    pprint(msg)
    if flavor == "normal":
        content_type, chat_type, chat_id = telepot.glance(msg, flavor)
        if content_type != "text":
            return
        msgText = msg["text"].strip()
        for plugin in arconfig.plugins:
            scan = scanRegex(plugin.regex, msgText)
            if scan is not None:
                ans = plugin.handler(bot, scan, msg, flavor)
                if ans is not None:
                    bot.sendMessage(chat_id, ans, reply_to_message_id=msg["message_id"], parse_mode="Markdown",
                                    disable_web_page_preview=False)
                    # print(content_type, chat_type, chat_id)

    elif flavor == "inline_query":
        query_id, from_id, query_string = telepot.glance(msg, flavor)
        for plugin in arconfig.plugins:
            groups = scanRegex(plugin.regexInline, query_string)
            if groups:
                ans = plugin.handler(bot, groups, msg, flavor)
                if ans is not None:
                    bot.answerInlineQuery(query_id, ans)
开发者ID:AstonishedByTheLackOfCake,项目名称:arcueidbot,代码行数:26,代码来源: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.glance(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:Semenka,项目名称:Courier_bot,代码行数:26,代码来源:test27_updates.py

示例8: 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),
                   InlineQueryResultArticle(
                       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'}]
        """"           
        gifs = [InlineQueryResultGif(
                    id='ghi', gif_url='http://www.animalstown.com/animals/g/gnu/coloring-pages/gnu-color-page-6.gif', thumb_url='http://www.animalstown.com/animals/g/gnu/coloring-pages/gnu-color-page-6.gif'),
                {'type': 'gif',
                    'id': 'jkl', 'gif_url': 'http://img2.colorirgratis.com/gnu-na-savana-africana_49d5b597bc78d-p.gif', 'thumb_url': 'http://img2.colorirgratis.com/gnu-na-savana-africana_49d5b597bc78d-p.gif'}]
        """
#                   InlineQueryResultVideo(
#                       id='jkl', video_url='', mime_type='')

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

        bot.answerInlineQuery(query_id, results, cache_time=20, is_personal=True, next_offset='5')
    else:
        raise telepot.BadFlavor(msg)
开发者ID:stamsarger,项目名称:telepot,代码行数:35,代码来源:test27_inline.py

示例9: 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

示例10: handle

    def handle(self, msg):
        flavor = telepot.flavor(msg)
        if flavor != "chat":
            return

        text, chat_id = None, None

        try:
            content_type, chat_type, chat_id = telepot.glance(msg)
            text = msg['text']
        except:
            return
        else:
            if content_type != "text":
                return

        if text == '/start':
            show_keyboard = {'keyboard': [['/server', '/password']]}
            bot.sendMessage(chat_id, 'Server or Password? http://www.vpnbook.com/#pptpvpn', reply_markup=show_keyboard)

        elif text == '/server':
            for server in SERVERS:
                bot.sendMessage(chat_id, server)

        elif text == '/password':
            with urllib.request.urlopen("http://www.vpnbook.com") as url:
            	html = str(url.read())
            
            pwd = self.find_between(html, "Password: ", "</strong>")
            bot.sendMessage(chat_id, pwd)
开发者ID:mfkaptan,项目名称:vpnbook-telegram-bot,代码行数:30,代码来源:bot.py

示例11: handle

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

    # normal message
    if flavor == 'normal':
        content_type, chat_type, chat_id = telepot.glance(msg)
        print 'Normal Message:', content_type, chat_type, chat_id,
        content = msg['text']
        if containsKeyword(content):
            bot.sendMessage(chat_id, content)
            responseImg = random.choice(os.listdir("./Images/"))
            responsefile = open("./Images/" + responseImg, 'rb')
            bot.sendPhoto(chat_id, responsefile)
            # Do your stuff according to `content_type` ...

    # inline query - need `/setinline`
    elif flavor == 'inline_query':
        query_id, from_id, query_string = telepot.glance(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.glance(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:misleadingTitle,项目名称:ProvaBot,代码行数:35,代码来源:MembroBot.py

示例12: handle

def handle(msg):

    print("Got message: " + str(msg))
    flavor = telepot.flavor(msg)

    # The message is chat. Easy enough.
    if flavor == "chat":
        # Get the Message Content Information from the Message.
        content_type, chat_type, chat_id = telepot.glance(msg)

        # This message is a chat event (sent by a user).
        if content_type == 'text':
            # Is this a command?
            if AwooUtils.isCommand(msg):
                # Parse some information from the message, and get it ready.
                cmd, params = AwooUtils.parseCommand(msg['text'])
                user_id = AwooUtils.getUserID(msg)
                username = AwooUtils.getUsername(msg)

                # Create the Arguments packet. Commands may pick and choose what parameters
                # they want to use from this.
                args = {'chat_id': chat_id,
                        'params': params,
                        'user_id': user_id,
                        'chat_type': chat_type,
                        'username': username,
                        'message': msg}
                try:
                    # Run a command from the CommandManager, if it exists
                    COMMANDS.execute(BOT, cmd, args)

                except Exception:
                    e = sys.exc_info()[0]
                    # Report the fact that the command failed to run, and notify the Developers.
                    BOT.sendMessage(chat_id,
                                    "[Error] Could not run command. The developers have been notified and are being beaten savagely for their mistake.")
                    for i in SUPERUSERS:
                        BOT.sendMessage(i,
                                        r"\[DEV] Internal Error. Trace:\n\n```" + traceback.format_exc(e) + "```",
                                        "Markdown")
                    # Print the stack trace.
                    traceback.print_exc()

        # A new Chat Member has been added!
        elif content_type == 'new_chat_member':
            AwooChat.newUserWatchdog(msg, chat_id)
            
        elif content_type == 'left_chat_member':
            if msg['left_chat_participant']['id'] == AwooUtils.getBotID():
                # Debug
                for i in SUPERUSERS:
                    BOT.sendMessage(i, "WolfBot was kicked from chat " + str(msg['chat']['title']))
                PREFS.purgeChat(msg['chat']['id'])

        # Check if the title exists.
        elif content_type == 'new_chat_title':
            AwooChat.titleWatchdog(msg)
开发者ID:KazWolfe,项目名称:WolfBot,代码行数:57,代码来源:AwooCore.py

示例13: handle

def handle(msg):
    if telepot.flavor(msg) == 'callback_query':
        logger.info("Callback query processing:")
        logger.info(msg)
        logger.info(' by ' + str(msg['from']['id']))
        user = User.objects.get(telegram_id=msg['from']['id'])
        callbacks[msg['data'].split('_')[0]].handle(msg, user)
    elif telepot.flavor(msg) == 'chat' and telepot.glance(msg)[0] == 'text':
        content_type, chat_type, chat_id = telepot.glance(msg)
        logger.info("Message processing:")
        logger.info(msg)
        logger.info(content_type + ' by ' + str(msg['from']['id']))
        try:
            user = User.objects.get(telegram_id=msg['from']['id'])
        except User.DoesNotExist:
            User.create(telegram_id=msg['from']['id'])
        else:
            user.get_state().handle(user, msg['text'])
开发者ID:spbgti,项目名称:spbgti-tools-bot,代码行数:18,代码来源:bot.py

示例14: __init__

    def __init__(self, seed_tuple, timeout, flavors='all'):
        bot, initial_msg, seed = seed_tuple
        super(UserHandler, self).__init__(bot, seed, initial_msg['from']['id'])
        self.listener.set_options(timeout=timeout)

        if flavors == 'all':
            self.listener.capture(from__id=self.user_id)
        else:
            self.listener.capture(_=lambda msg: telepot.flavor(msg) in flavors, from__id=self.user_id)
开发者ID:jlbmdm,项目名称:telepot,代码行数:9,代码来源:helper.py

示例15: handle

 def handle(self, msg):
     try:
         my_logger.debug("COMMAND: " + str(msg))
         flavor = telepot.flavor(msg)
         if flavor == 'chat':
             content_type, chat_type, chat_id = telepot.glance(msg)
             my_logger.info("Chat message: " + content_type + " - Type: " + chat_type + " - ID: " + str(chat_id) + " - Command: " + msg['text'])
             # verifico se l'utente da cui ho ricevuto il comando è censito
             user_exist = False
             for u in MyIPCameraBot_config.users:
                 if u is None:
                     break
                 if u['telegram_id'] == str(chat_id):
                     user_exist = True
                     my_logger.debug("Check userID " + u['telegram_id'] + ": user exist...")
             # se l'utente non è censito, abortisco
             # questo controllo è per evitare che le risposte dei messaggi
             # vadano a richiedenti non abilitati
             if user_exist == False:
                 my_logger.info("User NOT exist!!!")
                 return None
             # seleziono il tipo di comando da elaborare
             if msg['text'] == '/help':
                 self.__comm_help(chat_id)
             elif msg['text'] == '/start':
                 self.__comm_help(chat_id)
             elif msg['text'] == '/jpg':
                 self.__comm_jpg(chat_id)
             elif msg['text'] == '/status':
                 self.__comm_status(chat_id)
             elif msg['text'] == '/motion':
                 self.__comm_motion(chat_id)
             elif msg['text'] == 'Motion Detection OFF':
                 self.__comm_motion_detection(chat_id, msg["from"]["first_name"], 0)
             elif msg['text'] == 'Motion Detection ON':
                 self.__comm_motion_detection(chat_id, msg["from"]["first_name"], 1)
             elif msg['text'] == '/night':
                 self.__comm_night(chat_id)
             elif msg['text'] == 'IR Automatic':
                 self.__comm_night_IR(chat_id, 0)
             elif msg['text'] == 'IR On':
                 self.__comm_night_IR(chat_id, 2)
             elif msg['text'] == 'IR Off':
                 self.__comm_night_IR(chat_id, 3)
             elif msg['text'] == '/rep':
                 self.__comm_rep(chat_id)
             elif msg['text'] == 'Clear repository':
                 self.__comm_rep_clear(chat_id)
             elif msg['text'] == 'Cancel':
                 self.__comm_rep_cancel(chat_id)
             else:
                 self.__comm_nonCapisco(chat_id)
         else:
             raise telepot.BadFlavor(msg)
     except:
         my_logger.exception("Unable to parse command: " + str(sys.exc_info()[0]))
开发者ID:alexscarcella,项目名称:ScarcellaBot_CCTV,代码行数:56,代码来源:MyIPCameraBot.py


注:本文中的telepot.flavor函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。