Skip to content

Commit 37a9598

Browse files
committed
feat: support at everywhere
1 parent d9ef5a6 commit 37a9598

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

channel/wechat/wechat_channel.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
"""
66

77
import os
8+
import re
89
import requests
910
import io
1011
import time
12+
from common.singleton import singleton
1113
from lib import itchat
1214
import json
1315
from lib.itchat.content import *
@@ -68,11 +70,11 @@ def wrapper(self, msg):
6870
return func(self, msg)
6971
return wrapper
7072

71-
73+
@singleton
7274
class WechatChannel(Channel):
7375
def __init__(self):
74-
self.userName = None
75-
self.nickName = None
76+
self.user_id = None
77+
self.name = None
7678
self.receivedMsgs = ExpiredDict(60*60*24)
7779

7880
def startup(self):
@@ -90,9 +92,9 @@ def startup(self):
9092
itchat.auto_login(enableCmdQR=2, hotReload=hotReload)
9193
else:
9294
raise e
93-
self.userName = itchat.instance.storageClass.userName
94-
self.nickName = itchat.instance.storageClass.nickName
95-
logger.info("Wechat login success, username: {}, nickname: {}".format(self.userName, self.nickName))
95+
self.user_id = itchat.instance.storageClass.userName
96+
self.name = itchat.instance.storageClass.nickName
97+
logger.info("Wechat login success, user_id: {}, nickname: {}".format(self.user_id, self.name))
9698
# start message listener
9799
itchat.run()
98100

@@ -160,17 +162,12 @@ def handle_group(self, msg):
160162
group_id = msg['User'].get('UserName', None)
161163
if not group_name:
162164
return ""
163-
origin_content = msg['Content']
164-
content = msg['Content']
165-
content_list = content.split(' ', 1)
166-
context_special_list = content.split('\u2005', 1)
167-
if len(context_special_list) == 2:
168-
content = context_special_list[1]
169-
elif len(content_list) == 2:
170-
content = content_list[1]
165+
content = msg.content
171166
if "」\n- - - - - - - - - - - - - - -" in content:
172167
logger.debug("[WX]reference query skipped")
173168
return ""
169+
pattern = f'@{self.name}(\u2005|\u0020)'
170+
content = re.sub(pattern, r'', content)
174171

175172
config = conf()
176173
group_name_white_list = config.get('group_name_white_list', [])

0 commit comments

Comments
 (0)