示例#1
0
def deal_with_msg(msg, s, client):
    if msg['MsgType'] == 'Text':
        content = msg['Content']
        # Plugins should be added in order as ('name', function)
        pluginOrder = [('vote', vote), ('autoreply', autoreply)]
        getReply = False
        for plugin in pluginOrder:
            if plugin[0] in pluginList['msgdealers']:
                r = plugin[1](content, client.storageClass,
                              msg['FromUserName'])
                if r:
                    send_msg(client, msg['FromUserName'], r)
                    getReply = True
                    break
        if not getReply:
            client.send_msg(
                msg['FromUserName'],
                '\n'.join(tuling.get_response(msg['Content']))
                if TULING else 'I received: %s' % msg['Content'])
        out.print_line('%s: %s' %
                       (s.find_nickname(msg['FromUserName']), msg['Content']))
    elif msg['MsgType'] == 'Map':
        client.send_msg(msg['FromUserName'], 'You are there!')
        out.print_line('%s is at %s' %
                       (s.find_nickname(msg['FromUserName']), msg['Content']))
    elif msg['MsgType'] == 'Picture':
        client.send_msg(msg['FromUserName'], 'Picture received')
        out.print_line('%s sent a picture [%s]' %
                       (s.find_nickname(msg['FromUserName']), msg['Content']))
    elif msg['MsgType'] == 'Recording':
        client.send_msg(msg['FromUserName'], 'Nice Voice!')
        out.print_line('%s sent a recording' %
                       (s.find_nickname(msg['FromUserName'])))
    elif msg['MsgType'] == 'Card':
        client.send_msg(msg['FromUserName'], 'Greeting, %s!' % msg['Content'])
        out.print_line('%s sent a business card of [%s]' %
                       (s.find_nickname(msg['FromUserName']), msg['Content']))
    elif msg['MsgType'] == 'Sharing':
        client.send_msg(msg['FromUserName'], '"%s" is good!' % msg['Content'])
        out.print_line('%s sent a web about [%s]' %
                       (s.find_nickname(msg['FromUserName']), msg['Content']))
    elif msg['MsgType'] == 'Attachment':
        client.send_msg(msg['FromUserName'], '"%s" received' % msg['Content'])
        out.print_line('%s sent an attachment: [%s]' %
                       (s.find_nickname(msg['FromUserName']), msg['Location']))
    elif msg['MsgType'] == 'Video':
        client.send_msg(msg['FromUserName'], 'I received a video')
        out.print_line('%s sent a video [%s]' %
                       (s.find_nickname(msg['FromUserName']), msg['Content']))
    elif msg['MsgType'] == 'Note':
        out.print_line('Notification: %s' % (msg['Content']))
    else:
        pass  #out.print_line(str(msg)
示例#2
0
文件: run.py 项目: heilian/ItChat
 def text_reply(msg):
     # print msg
     # 实例化入队类
     inqueue=MsgInQueue(queue)
     # 消息入队
     inqueue.putmsgqueue(msg)
     nickname = itchat.__client.storageClass.nickName
     if msg['isAt'] or '@%s'%(nickname) in msg['Content']:
         try:
             import plugin.tuling as tuling
             r = tuling.get_response(msg['Content'].replace('@%s'%(nickname),'').strip())
             itchat.send(u'\u2005%s' % (r), msg['FromUserName'])
         except        Exception, e:
             print e
示例#3
0
文件: robot.py 项目: NolanZhao/ItChat
def deal_with_msg(msg, s, client):
    if msg['MsgType'] == 'Text':
        content = msg['Content']
        # Plugins should be added in order as ('name', function)
        pluginOrder = [('vote', vote), ('autoreply', autoreply)]
        getReply = False
        for plugin in pluginOrder:
            if plugin[0] in pluginList['msgdealers']:
                r = plugin[1](content, client.storageClass, msg['FromUserName'])
                if r:
                    send_msg(client, msg['FromUserName'], r)
                    getReply = True
                    break
        if not getReply:
            client.send_msg(msg['FromUserName'],
                    '\n'.join(tuling.get_response(msg['Content'])) if TULING else 'I received: %s'%msg['Content'])
        out.print_line('%s: %s'%(s.find_nickname(msg['FromUserName']), msg['Content']))
    elif msg['MsgType'] == 'Map':
        client.send_msg(msg['FromUserName'], 'You are there!')
        out.print_line('%s is at %s'%(s.find_nickname(msg['FromUserName']), msg['Content']))
    elif msg['MsgType'] == 'Picture':
        client.send_msg(msg['FromUserName'], 'Picture received')
        out.print_line('%s sent a picture [%s]'%(s.find_nickname(msg['FromUserName']), msg['Content']))
    elif msg['MsgType'] == 'Recording':
        client.send_msg(msg['FromUserName'], 'Nice Voice!')
        out.print_line('%s sent a recording'%(s.find_nickname(msg['FromUserName'])))
    elif msg['MsgType'] == 'Card':
        client.send_msg(msg['FromUserName'], 'Greeting, %s!'%msg['Content'])
        out.print_line('%s sent a business card of [%s]'%(s.find_nickname(msg['FromUserName']), msg['Content']))
    elif msg['MsgType'] == 'Sharing':
        client.send_msg(msg['FromUserName'], '"%s" is good!'%msg['Content'])
        out.print_line('%s sent a web about [%s]'%(s.find_nickname(msg['FromUserName']), msg['Content']))
    elif msg['MsgType'] == 'Attachment':
        client.send_msg(msg['FromUserName'], '"%s" received'%msg['Content'])
        out.print_line('%s sent an attachment: [%s]'%(s.find_nickname(msg['FromUserName']), msg['Location']))
    elif msg['MsgType'] == 'Video':
        client.send_msg(msg['FromUserName'], 'I received a video')
        out.print_line('%s sent a video [%s]'%(s.find_nickname(msg['FromUserName']), msg['Content']))
    elif msg['MsgType'] == 'Note':
        out.print_line('Notification: %s'%(msg['Content']))
    else:
        pass#out.print_line(str(msg)
示例#4
0
def deal_with_msg(msg, s, client):
    if msg['MsgType'] == 'Text':
        content = msg['Content']
        # test vote first
        r = vote(client.storageClass, msg['FromUserName'], content)
        if r: send_msg(client, msg['FromUserName'], r); return
        # test user's autoreply
        r = autoreply(content)
        if r: send_msg(client, msg['FromUserName'], r); return
        # no plugin matched
        client.send_msg(msg['FromUserName'],
                '\n'.join(tuling.get_response(msg['Content'], 'ItChat')) if TULING else 'I received: %s'%msg['Content'])
        out.print_line('%s: %s'%(s.find_nickname(msg['FromUserName']), msg['Content']))
    elif msg['MsgType'] == 'Map':
        client.send_msg(msg['FromUserName'], 'You are there!')
        out.print_line('%s is at %s'%(s.find_nickname(msg['FromUserName']), msg['Content']))
    elif msg['MsgType'] == 'Picture':
        client.send_msg(msg['FromUserName'], 'Picture received')
        out.print_line('%s sent a picture [%s]'%(s.find_nickname(msg['FromUserName']), msg['Content']))
    elif msg['MsgType'] == 'Recording':
        client.send_msg(msg['FromUserName'], 'Nice Voice!')
        out.print_line('%s sent a recording'%(s.find_nickname(msg['FromUserName'])))
    elif msg['MsgType'] == 'Card':
        client.send_msg(msg['FromUserName'], 'Greeting, %s!'%msg['Content'])
        out.print_line('%s sent a business card of [%s]'%(s.find_nickname(msg['FromUserName']), msg['Content']))
    elif msg['MsgType'] == 'Sharing':
        client.send_msg(msg['FromUserName'], '"%s" is good!'%msg['Content'])
        out.print_line('%s sent a web about [%s]'%(s.find_nickname(msg['FromUserName']), msg['Content']))
    elif msg['MsgType'] == 'Attachment':
        client.send_msg(msg['FromUserName'], '"%s" received'%msg['Content'])
        out.print_line('%s sent an attachment: [%s]'%(s.find_nickname(msg['FromUserName']), msg['Location']))
    elif msg['MsgType'] == 'Video':
        client.send_msg(msg['FromUserName'], 'I received a video')
        out.print_line('%s sent a video [%s]'%(s.find_nickname(msg['FromUserName']), msg['Content']))
    elif msg['MsgType'] == 'Note':
        out.print_line('Notification: %s'%(msg['Content']))
    else:
        pass#out.print_line(str(msg)
示例#5
0
# load plugin list
try:
    pluginListDir = 'pluginlist.json'
    with open(pluginListDir) as f: pluginList = json.loads(f.read())
except:
    pluginList = []
    sys_print('WARN', 'There is something wrong with the format of your pluginlist.json')

# Test tuling.py
if 'tuling' in pluginList:
    try:
        pluginList.remove('tuling')
        import plugin.tuling as tuling
        try:
            tuling.get_response('Hi', 'LittleCoder')
            pluginList.append('tuling')
            sys_print('SUCC', 'Tuling')
        except:
            sys_print('WARN', 'Your key for tuling robot can\'t be used now, change one in plugin/config/tuling.json')
            sys_print('~~~~', 'You can get it from http://www.tuling123.com/')
    except:
        sys_print('WARN', 'There is something wrong with the format of your plugin/config/tuling.json')

# Test QRCode.py
if 'QRCode' in pluginList:
    try:
        import plugin.QRCode as QRCode
        sys_print('SUCC', 'Command line QRCode')
    except:
        sys_print('INFO', 'Command line QRCode loaded failed, if you want to use this, you need to run `pip install Image`')
示例#6
0
文件: robot.py 项目: artistlin/ItChat
#coding=utf8
import itchat.out as out
import itchat.log as log
from PluginTest import *

try:
    import plugin.tuling as tuling
    tuling.get_response('Hi', 'LittleCoder')
    TULING = True
except:
    TULING = False

PRINT_ON_CMD = True

def send_msg(client, toUserName, msg):
    if len(msg) > 5:
        if msg[:5] == '@fil@':
            try:
                with open(msg[5:]): pass
                client.send_file(msg[5:], toUserName)
            except:
                log.log('Send file %s failed'%msg[5:], False)
        elif msg[:5] == '@img@':
            try:
                with open(msg[5:]): pass
                client.send_image(msg[5:], toUserName)
            except:
                log.log('Send image %s failed'%msg[5:], False)
        elif msg[:5] == '@msg@':
            client.send_msg(toUserName, msg[:5])
        else:
示例#7
0
文件: robot.py 项目: NolanZhao/ItChat
#coding=utf8
import itchat.out as out
import itchat.log as log
from PluginTest import *

try:
    import plugin.tuling as tuling
    tuling.get_response('Hi', 'LittleCoder')
    TULING = True
except:
    TULING = False

def send_msg(client, toUserName, msg):
    if len(msg) > 5:
        if msg[:5] == '@fil@':
            try:
                with open(msg[5:]): pass
                client.send_file(msg[5:], toUserName)
            except:
                log.log('Send %s failed'%msg[5:], False)
        elif msg[:5] == '@msg@':
            client.send_msg(toUserName, msg[:5])
        else:
            client.send_msg(toUserName, msg)
    else:
        client.send_msg(toUserName, msg)

def deal_with_msg(msg, s, client):
    if msg['MsgType'] == 'Text':
        content = msg['Content']
        # Plugins should be added in order as ('name', function)