mirror of
https://github.com/zhayujie/chatgpt-on-wechat.git
synced 2026-06-02 00:57:41 +08:00
adding features: 退群提醒
后面还打算想办法加用户自己退出的提醒,目前版本是可以在群主(且群主/管理员自己是bot)踢人时候发出提醒
This commit is contained in:
@@ -16,6 +16,8 @@ class ContextType(Enum):
|
|||||||
JOIN_GROUP = 20 # 加入群聊
|
JOIN_GROUP = 20 # 加入群聊
|
||||||
PATPAT = 21 # 拍了拍
|
PATPAT = 21 # 拍了拍
|
||||||
FUNCTION = 22 # 函数调用
|
FUNCTION = 22 # 函数调用
|
||||||
|
EXIT_GROUP = 23 #退出
|
||||||
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|||||||
@@ -170,7 +170,7 @@ class WechatChannel(ChatChannel):
|
|||||||
logger.debug("[WX]receive voice for group msg: {}".format(cmsg.content))
|
logger.debug("[WX]receive voice for group msg: {}".format(cmsg.content))
|
||||||
elif cmsg.ctype == ContextType.IMAGE:
|
elif cmsg.ctype == ContextType.IMAGE:
|
||||||
logger.debug("[WX]receive image for group msg: {}".format(cmsg.content))
|
logger.debug("[WX]receive image for group msg: {}".format(cmsg.content))
|
||||||
elif cmsg.ctype in [ContextType.JOIN_GROUP, ContextType.PATPAT, ContextType.ACCEPT_FRIEND]:
|
elif cmsg.ctype in [ContextType.JOIN_GROUP, ContextType.PATPAT, ContextType.ACCEPT_FRIEND, ContextType.EXIT_GROUP]:
|
||||||
logger.debug("[WX]receive note msg: {}".format(cmsg.content))
|
logger.debug("[WX]receive note msg: {}".format(cmsg.content))
|
||||||
elif cmsg.ctype == ContextType.TEXT:
|
elif cmsg.ctype == ContextType.TEXT:
|
||||||
# logger.debug("[WX]receive group msg: {}, cmsg={}".format(json.dumps(cmsg._rawmsg, ensure_ascii=False), cmsg))
|
# logger.debug("[WX]receive group msg: {}, cmsg={}".format(json.dumps(cmsg._rawmsg, ensure_ascii=False), cmsg))
|
||||||
|
|||||||
@@ -27,13 +27,21 @@ class WechatMessage(ChatMessage):
|
|||||||
self._prepare_fn = lambda: itchat_msg.download(self.content)
|
self._prepare_fn = lambda: itchat_msg.download(self.content)
|
||||||
elif itchat_msg["Type"] == NOTE and itchat_msg["MsgType"] == 10000:
|
elif itchat_msg["Type"] == NOTE and itchat_msg["MsgType"] == 10000:
|
||||||
if is_group and ("加入群聊" in itchat_msg["Content"] or "加入了群聊" in itchat_msg["Content"]):
|
if is_group and ("加入群聊" in itchat_msg["Content"] or "加入了群聊" in itchat_msg["Content"]):
|
||||||
self.ctype = ContextType.JOIN_GROUP
|
|
||||||
self.content = itchat_msg["Content"]
|
|
||||||
# 这里只能得到nickname, actual_user_id还是机器人的id
|
# 这里只能得到nickname, actual_user_id还是机器人的id
|
||||||
if "加入了群聊" in itchat_msg["Content"]:
|
if "加入了群聊" in itchat_msg["Content"]:
|
||||||
|
self.ctype = ContextType.JOIN_GROUP
|
||||||
|
self.content = itchat_msg["Content"]
|
||||||
self.actual_user_nickname = re.findall(r"\"(.*?)\"", itchat_msg["Content"])[-1]
|
self.actual_user_nickname = re.findall(r"\"(.*?)\"", itchat_msg["Content"])[-1]
|
||||||
elif "加入群聊" in itchat_msg["Content"]:
|
elif "加入群聊" in itchat_msg["Content"]:
|
||||||
|
self.ctype = ContextType.JOIN_GROUP
|
||||||
|
self.content = itchat_msg["Content"]
|
||||||
self.actual_user_nickname = re.findall(r"\"(.*?)\"", itchat_msg["Content"])[0]
|
self.actual_user_nickname = re.findall(r"\"(.*?)\"", itchat_msg["Content"])[0]
|
||||||
|
|
||||||
|
elif is_group and ("移出了群聊" in itchat_msg["Content"]):
|
||||||
|
self.ctype = ContextType.EXIT_GROUP
|
||||||
|
self.content = itchat_msg["Content"]
|
||||||
|
self.actual_user_nickname = re.findall(r"\"(.*?)\"", itchat_msg["Content"])[0]
|
||||||
|
|
||||||
elif "你已添加了" in itchat_msg["Content"]: #通过好友请求
|
elif "你已添加了" in itchat_msg["Content"]: #通过好友请求
|
||||||
self.ctype = ContextType.ACCEPT_FRIEND
|
self.ctype = ContextType.ACCEPT_FRIEND
|
||||||
self.content = itchat_msg["Content"]
|
self.content = itchat_msg["Content"]
|
||||||
@@ -90,5 +98,5 @@ class WechatMessage(ChatMessage):
|
|||||||
if self.is_group:
|
if self.is_group:
|
||||||
self.is_at = itchat_msg["IsAt"]
|
self.is_at = itchat_msg["IsAt"]
|
||||||
self.actual_user_id = itchat_msg["ActualUserName"]
|
self.actual_user_id = itchat_msg["ActualUserName"]
|
||||||
if self.ctype not in [ContextType.JOIN_GROUP, ContextType.PATPAT]:
|
if self.ctype not in [ContextType.JOIN_GROUP, ContextType.PATPAT, ContextType.EXIT_GROUP]:
|
||||||
self.actual_user_nickname = itchat_msg["ActualNickName"]
|
self.actual_user_nickname = itchat_msg["ActualNickName"]
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ class Hello(Plugin):
|
|||||||
ContextType.TEXT,
|
ContextType.TEXT,
|
||||||
ContextType.JOIN_GROUP,
|
ContextType.JOIN_GROUP,
|
||||||
ContextType.PATPAT,
|
ContextType.PATPAT,
|
||||||
|
ContextType.EXIT_GROUP
|
||||||
]:
|
]:
|
||||||
return
|
return
|
||||||
if e_context["context"].type == ContextType.JOIN_GROUP:
|
if e_context["context"].type == ContextType.JOIN_GROUP:
|
||||||
@@ -47,6 +48,13 @@ class Hello(Plugin):
|
|||||||
e_context.action = EventAction.BREAK # 事件结束,进入默认处理逻辑
|
e_context.action = EventAction.BREAK # 事件结束,进入默认处理逻辑
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if e_context["context"].type == ContextType.EXIT_GROUP:
|
||||||
|
e_context["context"].type = ContextType.TEXT
|
||||||
|
msg: ChatMessage = e_context["context"]["msg"]
|
||||||
|
e_context["context"].content = f'请你随机使用一种风格跟其他群用户说他违反规则"{msg.actual_user_nickname}"退出群聊。'
|
||||||
|
e_context.action = EventAction.BREAK # 事件结束,进入默认处理逻辑
|
||||||
|
return
|
||||||
|
|
||||||
if e_context["context"].type == ContextType.PATPAT:
|
if e_context["context"].type == ContextType.PATPAT:
|
||||||
e_context["context"].type = ContextType.TEXT
|
e_context["context"].type = ContextType.TEXT
|
||||||
msg: ChatMessage = e_context["context"]["msg"]
|
msg: ChatMessage = e_context["context"]["msg"]
|
||||||
|
|||||||
Reference in New Issue
Block a user