예제 #1
0
파일: emodia.py 프로젝트: miragshin/telepot
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
파일: test3.py 프로젝트: miragshin/telepot
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
파일: emodi.py 프로젝트: miragshin/telepot
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)