mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-07-25 05:46:13 +00:00
当微信群有at消息时删除第一个at已达到能激活管理员模式
This commit is contained in:
@@ -62,20 +62,38 @@ class GewechatMessageConverter(adapter.MessageConverter):
|
|||||||
bot_account_id: str
|
bot_account_id: str
|
||||||
) -> platform_message.MessageChain:
|
) -> platform_message.MessageChain:
|
||||||
|
|
||||||
|
|
||||||
|
# print(message)
|
||||||
|
|
||||||
if message["Data"]["MsgType"] == 1:
|
if message["Data"]["MsgType"] == 1:
|
||||||
# 检查消息开头,如果有 wxid_sbitaz0mt65n22:\n 则删掉
|
# 检查消息开头,如果有 wxid_sbitaz0mt65n22:\n 则删掉
|
||||||
regex = re.compile(r"^wxid_.*:")
|
regex = re.compile(r"^wxid_.*:")
|
||||||
|
# print(message)
|
||||||
|
|
||||||
line_split = message["Data"]["Content"]["string"].split("\n")
|
line_split = message["Data"]["Content"]["string"].split("\n")
|
||||||
|
|
||||||
if len(line_split) > 0 and regex.match(line_split[0]):
|
if len(line_split) > 0 and regex.match(line_split[0]):
|
||||||
message["Data"]["Content"]["string"] = "\n".join(line_split[1:])
|
message["Data"]["Content"]["string"] = "\n".join(line_split[1:])
|
||||||
|
# 获取机器人在群内信息
|
||||||
at_string = f'@{bot_account_id}'
|
# bot_room_datas = bot.get_chatroom_member_detail(
|
||||||
|
# self.config["app_id"],
|
||||||
|
# message['Data']['FromUserName']['string'],
|
||||||
|
# [message['Data']["ToUserName"]['string']]
|
||||||
|
# )['data']
|
||||||
|
# print(bot_room_datas)
|
||||||
|
# # 拿到机器人在群内名称
|
||||||
|
# at_string = ''
|
||||||
|
# for bot_data in bot_room_datas:
|
||||||
|
# bot_room_name = bot_data['nickName']
|
||||||
|
# at_string += f"@{bot_room_name}"
|
||||||
|
# 正则表达式模式,匹配'@'后跟任意数量的非空白字符
|
||||||
|
pattern = r'@\S+'
|
||||||
|
# at_string = f"@{bot_account_id}"
|
||||||
content_list = []
|
content_list = []
|
||||||
if at_string in message["Data"]["Content"]["string"]:
|
if '@' in message["Data"]["Content"]["string"]:
|
||||||
content_list.append(platform_message.At(target=bot_account_id))
|
content_list.append(platform_message.At(target=bot_account_id))
|
||||||
content_list.append(platform_message.Plain(message["Data"]["Content"]["string"].replace(at_string, "", 1)))
|
# print(re.sub(pattern, '', message["Data"]["Content"]["string"]))
|
||||||
|
content_list.append(platform_message.Plain(re.sub(pattern, '', message["Data"]["Content"]["string"])))
|
||||||
else:
|
else:
|
||||||
content_list = [platform_message.Plain(message["Data"]["Content"]["string"])]
|
content_list = [platform_message.Plain(message["Data"]["Content"]["string"])]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user