Python itchat.send_msg() Examples

The following are 9 code examples of itchat.send_msg(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module itchat , or try the search function .
Example #1
Source File: antiWithdrawal.py    From WechatHelper with MIT License 6 votes vote down vote up
def monitorMsg(msg):
		if '撤回了一条消息' in msg['Content']:
			recall_msg_id = re.search("\<msgid\>(.*?)\<\/msgid\>", msg['Content']).group(1)
			recall_msg = MSGINFO.get(recall_msg_id)
			print('[Recall]: %s' % recall_msg)
			if len(recall_msg_id) < 11:
				itchat.send_file(FACEPACKAGE, toUserName='filehelper')
			else:
				prompt = '+++' + recall_msg.get('msg_from') + '撤回了一条消息+++\n' \
							'--消息类型:' + recall_msg.get('msg_type') + '\n' \
							'--接收时间:' + recall_msg.get('msg_receive_time') + '\n' \
							'--消息内容:' + recall_msg.get('msg_content')
				if recall_msg['msg_type'] == 'Sharing':
					prompt += '\n链接:' + recall_msg.get('msg_link')
				itchat.send_msg(prompt, toUserName='filehelper')
				if recall_msg['msg_type'] == 'Attachment' or recall_msg['msg_type'] == "Video" or recall_msg['msg_type'] == 'Picture' or recall_msg['msg_type'] == 'Recording':
					file = '@fil@%s' % (recall_msg['msg_content'])
					itchat.send(msg=file, toUserName='filehelper')
					os.remove(recall_msg['msg_content'])
				MSGINFO.pop(recall_msg_id) 
Example #2
Source File: syncgroupchat.py    From All-About-Redis with Creative Commons Zero v1.0 Universal 6 votes vote down vote up
def group_join_note(msg):
   global inviter,invitee
   chatroom_name =""
   # 消息来自于哪个群聊
   chatroom_id = msg['FromUserName']
   for c in chatrooms:
       if( c['UserName'] == chatroom_id):
           chatroom_name = c['NickName']        

   if u'邀请' in msg['Content'] or u'invited' in msg['Content']:
       str = msg['Content'];
       pos_start = str.find('"')
       pos_end = str.find('"',pos_start+1)
       inviter = str[pos_start+1:pos_end]
       rpos_start = str.rfind('"')
       rpos_end = str.rfind('"',0, rpos_start)
       invitee = str[(rpos_end+1) : rpos_start]
#       main_logger.info(msg)
   for item in chatrooms:
       if not item['UserName'] == chatroom_id:
           itchat.send_msg(u"%s 群新来一位朋友 %s, 让我们欢迎他/她吧!" % (chatroom_name,invitee), item['UserName'])
       else:
           itchat.send_msg(u"@%s\u2005欢迎来到本群[微笑],感谢@%s \u2005邀请!方便的话做个简单自我介绍,再把群名片改为 名字@公司~ 最后看下群公告,谢谢!" % (invitee,inviter), chatroom_id ) 
Example #3
Source File: wechat.py    From anack with GNU General Public License v3.0 6 votes vote down vote up
def SendText2ChatRoom(context, name):
    '''
    @ 发送消息到特定群聊内
    @ 备注:1.确定该群聊存在(可调用PrintChatRoomList查看)
    @      2.切记把群聊加入通讯录,否则只能显示活跃的前几个群聊
    '''
    itchat.get_chatrooms(update=True)
    iRoom = itchat.search_chatrooms(name)
    for room in iRoom:
        if room['NickName'] == name:
            userName = room['UserName']
            break
    try:
        itchat.send_msg(context, userName)
    except:
        print('warning: no this chatrooms') 
Example #4
Source File: 28 PythonCheHui.py    From Python-Spider with Apache License 2.0 5 votes vote down vote up
def information(msg):
    # 这里如果这里的msg['Content']中包含消息撤回和id,就执行下面的语句
    if '撤回了一条消息' in msg['Content']:
        # 在返回的content查找撤回的消息的id
        old_msg_id = re.search("\<msgid\>(.*?)\<\/msgid\>", msg['Content']).group(1)
        # 获取到消息原文
        old_msg = msg_information.get(old_msg_id)
        # 如果发送的是表情包
        if len(old_msg_id)<11:
            # 发送撤回的提示给文件助手
            itchat.send_file(face_bug,toUserName='filehelper')
        # 把暂时存储的信息可以删除掉,也可以选择不删除
        # os.remove(face_bug)
        else:
            msg_body = old_msg.get('group_name') + old_msg.get('msg_from') +"\n" + old_msg.get('msg_time_rec') \
                + "撤回了:" + "\n" + r"" + old_msg.get('msg_content')
            
            # 如果是分享的文件被撤回了,那么就将分享的url加在msg_body中发送给文件助手
            if old_msg['msg_type'] == "Sharing":
                msg_body += "\n链接是:" + old_msg.get('msg_share_url')
            print msg_body
            # 将撤回消息发给文件助手
            itchat.send_msg(msg_body, toUserName='filehelper')
            
            # 有文件的话也要将文件发送回去
            if old_msg["msg_type"] == "Picture" \
                or old_msg["msg_type"] == "Recording" \
                or old_msg["msg_type"] == "Video" \
                or old_msg["msg_type"] == "Attachment":
                file = '@fil@%s' % (old_msg['msg_content'])
                itchat.send(msg=file, toUserName='filehelper')
                # 把暂时存储的信息可以删除掉,也可以选择不删除
                os.remove(old_msg['msg_content'])
            # 删除字典旧消息
    msg_information.pop(old_msg_id) 
Example #5
Source File: wechat_utils.py    From Neural-Headline-Generator-CN with GNU General Public License v3.0 5 votes vote down vote up
def send_text(text):
    #send text msgs to 'filehelper'
    #给文件助手发送文本信息
    try:
        itchat.send_msg(msg=text,toUserName='filehelper')
        return
    except (ConnectionError,NotImplementedError,KeyError):
        traceback.print_exc()
        print('\nConection error,failed to send the message!\n')
        return
    else:
        return 
Example #6
Source File: wechat_utils.py    From Neural-Headline-Generator-CN with GNU General Public License v3.0 5 votes vote down vote up
def t_send(self,msg,toUserName='filehelper'):
        try:
            itchat.send_msg(msg=msg,toUserName=toUserName)
            return
        except (ConnectionError,NotImplementedError,KeyError):
            traceback.print_exc()
            print('\nConection error,failed to send the message!\n')
            return
        else:
            return 
Example #7
Source File: main.py    From weixinqunzhushou with Apache License 2.0 5 votes vote down vote up
def get_note(msg):
    msg['_id'] = msg['MsgId']
    db.msg_history.insert(msg)
    if u'邀请' in msg['Content'] or u'invited' in msg['Content']:
        pos1 = msg['Content'].rfind('"')
        pos2 = msg['Content'].rfind('"', 0, pos1)
        nick_name = msg['Content'][(pos2+1): pos1]
        itchat.send_msg(u'@%s 欢迎来到本群,我是群主的机器人助手[微笑]' % nick_name, msg['FromUserName']) 
Example #8
Source File: main.py    From weixinqunzhushou with Apache License 2.0 5 votes vote down vote up
def text_reply(msg):
    itchat.send_msg(u'Hi,我是一个智能机器人,能帮助您自动化的管理微信群,把我拉入群,我就可以开始为你工作啦', msg['FromUserName']) 
Example #9
Source File: main.py    From weixinqunzhushou with Apache License 2.0 5 votes vote down vote up
def add_friend(msg):
    itchat.add_friend(**msg['Text'])  # 该操作会自动将新好友的消息录入,不需要重载通讯录
    user_info = itchat.search_friends(userName=msg['RecommendInfo']['UserName'])
    itchat.send_msg(u'Hi,我是一个智能机器人,能帮助您自动化的管理微信群,把我拉入群,我就可以开始为你工作啦', user_info['UserName'])
    upsert_user(user_info)