Skip to content

Commit cb6c90c

Browse files
author
Zhishan Zhang
committed
fix fuzz match problem and add a sample config
1 parent b819b10 commit cb6c90c

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

config.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
version: 4.91
2+
match_mode: fuzz
3+
work_mode:
4+
- black_persons
5+
- white_groups
6+
- white_publics
7+
white_persons:
8+
- libai
9+
white_groups:
10+
- testsyou
11+
- 经典
12+
white_publics:
13+
- 银行
14+
- 微信
15+
black_persons:
16+
- nopp

efb_filter_middleware/__init__.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def __init__(self, instance_id: str = None):
6464
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
6565
hdlr.setFormatter(formatter)
6666
self.logger.addHandler(hdlr)
67-
self.logger.setLevel(logging.DEBUG)
67+
self.logger.setLevel(logging.ERROR)
6868

6969
def process_message(self, message: EFBMsg) -> Optional[EFBMsg]:
7070
config = yaml.load(open(utils.get_config_path(self.middleware_id), encoding ="UTF-8"))
@@ -85,22 +85,24 @@ def process_message(self, message: EFBMsg) -> Optional[EFBMsg]:
8585
def black_match(self, from_, from_alias, configs):
8686
if self.match_mode == "fuzz":
8787
for config in configs:
88-
if from_ in config or from_alias in config:
88+
if config in from_ or config in from_alias:
8989
return False
9090
return True
91-
else:
91+
92+
else:
9293
if from_ in configs or from_alias in configs:
9394
return False
9495
else:
9596
return True
97+
9698

9799
def white_match(self, from_, from_alias, configs):
98-
if self.match_mode == "fuzz":
100+
if self.match_mode == "fuzz":
99101
for config in configs:
100-
if from_ in config or from_alias in config:
102+
if config in from_ or config in from_alias:
101103
return True
102104
return False
103-
else:
105+
else:
104106
if from_ in configs or from_alias in configs:
105107
return True
106108
else:
@@ -113,7 +115,7 @@ def is_keep_message(self, work_mode: WorkMode, message: EFBMsg, configs: list) -
113115
# self.logger.debug("Received message from person: %s--%s", from_person, from_alias)
114116
self.logger.debug("Received message from myself: %s", message.author.is_self)
115117
self.logger.debug("Received message from chat: %s--%s", message.chat.chat_alias, message.chat.chat_name)
116-
118+
self.logger.debug("Rktke: %s", self.match_mode)
117119
if message.chat.chat_type.value == "Group":
118120
self.logger.debug("Received message from group: %s--%s", message.author.group.chat_alias, message.author.group.chat_name)
119121
from_ = message.author.group.chat_name
@@ -131,11 +133,13 @@ def is_keep_message(self, work_mode: WorkMode, message: EFBMsg, configs: list) -
131133
from_alias = from_
132134
if message.chat.vendor_specific is not None and message.chat.vendor_specific['is_mp']:
133135
if work_mode is WorkMode.black_public:
136+
self.logger.debug("Receive work black public")
134137
return self.black_match(from_, from_alias, configs)
135138
if work_mode is WorkMode.white_public:
136139
return self.white_match(from_, from_alias, configs)
137140
else:
138141
if work_mode is WorkMode.black_person:
142+
self.logger.debug("Receive work black person")
139143
return self.black_match(from_, from_alias, configs)
140144
if work_mode is WorkMode.white_person:
141145
return self.white_match(from_, from_alias, configs)

efb_filter_middleware/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.3.0"
1+
__version__ = "0.3.1"

0 commit comments

Comments
 (0)