本文整理汇总了Python中itchat.send_msg方法的典型用法代码示例。如果您正苦于以下问题:Python itchat.send_msg方法的具体用法?Python itchat.send_msg怎么用?Python itchat.send_msg使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类itchat
的用法示例。
在下文中一共展示了itchat.send_msg方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: monitorMsg
# 需要导入模块: import itchat [as 别名]
# 或者: from itchat import send_msg [as 别名]
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)
示例2: group_join_note
# 需要导入模块: import itchat [as 别名]
# 或者: from itchat import send_msg [as 别名]
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 )
示例3: SendText2ChatRoom
# 需要导入模块: import itchat [as 别名]
# 或者: from itchat import send_msg [as 别名]
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')
示例4: information
# 需要导入模块: import itchat [as 别名]
# 或者: from itchat import send_msg [as 别名]
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)
示例5: send_text
# 需要导入模块: import itchat [as 别名]
# 或者: from itchat import send_msg [as 别名]
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
示例6: t_send
# 需要导入模块: import itchat [as 别名]
# 或者: from itchat import send_msg [as 别名]
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
示例7: get_note
# 需要导入模块: import itchat [as 别名]
# 或者: from itchat import send_msg [as 别名]
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'])
示例8: text_reply
# 需要导入模块: import itchat [as 别名]
# 或者: from itchat import send_msg [as 别名]
def text_reply(msg):
itchat.send_msg(u'Hi,我是一个智能机器人,能帮助您自动化的管理微信群,把我拉入群,我就可以开始为你工作啦', msg['FromUserName'])
示例9: add_friend
# 需要导入模块: import itchat [as 别名]
# 或者: from itchat import send_msg [as 别名]
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)