Impl auto accept new friend request
This commit is contained in:
12
main.py
12
main.py
@@ -1,6 +1,7 @@
|
|||||||
#! /usr/bin/env python3
|
#! /usr/bin/env python3
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import re
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import robot.sdk.wcferry as WxSDK
|
import robot.sdk.wcferry as WxSDK
|
||||||
@@ -17,12 +18,23 @@ class Robot(BaseRobot):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
self.printRawMsg(msg) # 打印信息
|
self.printRawMsg(msg) # 打印信息
|
||||||
|
|
||||||
# 如果在群里被 @,回复发信人:“收到你的消息了!” 并 @他
|
# 如果在群里被 @,回复发信人:“收到你的消息了!” 并 @他
|
||||||
if self.isGroupChat(msg): # 是群消息
|
if self.isGroupChat(msg): # 是群消息
|
||||||
if self.isAt(msg): # 被@
|
if self.isAt(msg): # 被@
|
||||||
if msg.roomId in self.config.GROUPS: # 在配置的响应的群列表里
|
if msg.roomId in self.config.GROUPS: # 在配置的响应的群列表里
|
||||||
self.sendTextMsg(msg.roomId, "收到你的消息了!", msg.wxId)
|
self.sendTextMsg(msg.roomId, "收到你的消息了!", msg.wxId)
|
||||||
|
|
||||||
|
# 非群聊信息
|
||||||
|
elif msg.type == 37: # 好友请求
|
||||||
|
self.autoAcceptFriendRequest(msg)
|
||||||
|
|
||||||
|
elif msg.type == 10000: # 系统信息
|
||||||
|
nickName = re.findall(r"你已添加了(.*),现在可以开始聊天了。", msg.content)
|
||||||
|
if nickName:
|
||||||
|
# 添加了好友,更新好友列表
|
||||||
|
self.allContacts[msg.wxId] = nickName
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
robot = Robot(WxSDK, Config())
|
robot = Robot(WxSDK, Config())
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import re
|
import re
|
||||||
import logging
|
import logging
|
||||||
|
import xml.etree.ElementTree as ET
|
||||||
|
|
||||||
|
|
||||||
class BaseRobot(object):
|
class BaseRobot(object):
|
||||||
@@ -72,5 +73,15 @@ class BaseRobot(object):
|
|||||||
contacts = self.sdk.WxExecDbQuery("MicroMsg.db", "SELECT UserName, NickName FROM Contact;")
|
contacts = self.sdk.WxExecDbQuery("MicroMsg.db", "SELECT UserName, NickName FROM Contact;")
|
||||||
return {contact["UserName"]: contact["NickName"] for contact in contacts}
|
return {contact["UserName"]: contact["NickName"] for contact in contacts}
|
||||||
|
|
||||||
|
def autoAcceptFriendRequest(self, msg):
|
||||||
|
try:
|
||||||
|
xml = ET.fromstring(msg.content)
|
||||||
|
v3 = xml.attrib["encryptusername"]
|
||||||
|
v4 = xml.attrib["ticket"]
|
||||||
|
self.sdk.WxAcceptNewFriend(v3, v4)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
self.LOG.error(f"同意好友出错:{e}")
|
||||||
|
|
||||||
def processMsg(self, msg) -> None:
|
def processMsg(self, msg) -> None:
|
||||||
raise NotImplementedError("Method [processMsg] should be implemented.")
|
raise NotImplementedError("Method [processMsg] should be implemented.")
|
||||||
|
|||||||
Reference in New Issue
Block a user