Fix config

This commit is contained in:
Changhua
2022-09-27 22:19:49 +08:00
parent bd0bfa07a3
commit 7ecc534a0f
2 changed files with 8 additions and 5 deletions

10
main.py
View File

@@ -13,7 +13,8 @@ class Robot(BaseRobot):
"""
def __init__(self, sdk: WxSDK, config: Config) -> None:
super().__init__(sdk, config)
super().__init__(sdk)
self.config = config
def processMsg(self, msg) -> None:
"""当接收到消息的时候,会调用本方法。如果不实现本方法,则打印原始消息。
@@ -23,9 +24,12 @@ class Robot(BaseRobot):
# 如果在群里被 @,回复发信人:“收到你的消息了!” 并 @他
if self.isGroupChat(msg): # 是群消息
if msg.roomId not in self.config.GROUPS: # 不在配置的响应的群列表里,忽略
return
if self.isAt(msg): # 被@
if msg.roomId in self.config.GROUPS: # 在配置的响应的群列表里
self.sendTextMsg(msg.roomId, "收到你的消息了!", msg.wxId)
rsp = "你@我干嘛?"
self.sendTextMsg(msg.roomId, rsp, msg.wxId)
# 非群聊信息
elif msg.type == 37: # 好友请求

View File

@@ -13,9 +13,8 @@ class BaseRobot(Job):
机器人基类。用户需要实现 `processMsg` 方法以个性化处理消息。
"""
def __init__(self, sdk, config) -> None:
def __init__(self, sdk) -> None:
self.sdk = sdk
self.config = config
self.LOG = logging.getLogger("Robot")
def onMsg(self, msg) -> int: