本文整理匯總了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)