示例#1
0
def handle(msg):
    content_type, chat_type, chat_id = telepot.glance2(msg)
    m = telepot.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)
示例#2
0
文件: app.py 项目: vasua/verycruelbot
    def on_message(self, msg):
        content_type, chat_type, chat_id = telepot.glance2(msg)
        m = telepot.namedtuple(msg, 'Message')

        if chat_id < 0:
            # public chat
            if not self.reply_to_kek(content_type, m):
                self.reply_to_badgay(content_type, m)
        else:
            # private conversation
            self.reply_to_badgay(content_type, m)
示例#3
0
def examine(result, type):
    try:
        print('Examining %s ......' % type)

        nt = telepot.namedtuple(result, type)
        assert equivalent(result, nt), 'Not equivalent:::::::::::::::\n%s\n::::::::::::::::\n%s' % (result, nt)

        if type == 'Message':
            print('Message glance2: %s' % str(telepot.glance2(result, long=True)))

        pprint.pprint(result)
        pprint.pprint(nt)
        print()
    except AssertionError:
        traceback.print_exc()
        answer = input('Do you want to continue? [y] ')
        if answer != 'y':
            exit(1)
def examine(result, type):
    try:
        print 'Examining %s ......' % type

        nt = telepot.namedtuple(result, type)
        assert equivalent(result, nt), 'Not equivalent:::::::::::::::\n%s\n::::::::::::::::\n%s' % (result, nt)

        if type == 'Message':
            print 'Message glance2: %s' % str(telepot.glance2(result, long=True))

        pprint.pprint(result)
        pprint.pprint(nt)
        print
    except AssertionError:
        traceback.print_exc()
        answer = raw_input('Do you want to continue? [y] ')
        if answer != 'y':
            exit(1)
示例#5
0
def handle(msg):
    content_type, chat_type, chat_id = telepot.glance2(msg)
    m = telepot.namedtuple(msg, 'Message')

    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)
示例#6
0
def handle(msg):
    content_type, chat_type, chat_id = telepot.glance2(msg)
    m = telepot.namedtuple(msg, 'Message')

    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)
示例#7
0
def handle(msg):
    content_type, chat_type, chat_id = telepot.glance2(msg)
    m = telepot.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)