|
1 | | -from nonebot import get_plugin_config, logger |
| 1 | +from nonebot import get_plugin_config, logger |
2 | 2 | from nonebot.adapters.onebot.v11 import ( |
3 | 3 | Bot, |
4 | 4 | MessageEvent, |
|
24 | 24 |
|
25 | 25 | config = get_plugin_config(Config) |
26 | 26 |
|
| 27 | +def is_group_allowed(group_id) -> bool: |
| 28 | + if len(config.allow_group_list) == 0: |
| 29 | + return True |
| 30 | + return str(group_id) in {str(item) for item in config.allow_group_list} |
| 31 | + |
27 | 32 | # 定义日志配置 |
28 | 33 |
|
29 | 34 | class ChatBot: |
@@ -72,7 +77,7 @@ async def handle_message(self, event: MessageEvent, bot: Bot) -> None: |
72 | 77 | else: |
73 | 78 | #白名单处理逻辑 |
74 | 79 | if len(config.allow_group_list) != 0 : |
75 | | - if event.group_id not in config.allow_group_list: |
| 80 | + if not is_group_allowed(event.group_id): |
76 | 81 | return |
77 | 82 |
|
78 | 83 | user_info = UserInfo( |
@@ -135,7 +140,7 @@ async def handle_group_announcement(self, event: MessageEvent, bot: Bot) -> None |
135 | 140 | self.bot = bot # 更新 bot 实例 |
136 | 141 | #白名单处理逻辑 |
137 | 142 | if len(config.allow_group_list) != 0 : |
138 | | - if event.group_id not in config.allow_group_list: |
| 143 | + if not is_group_allowed(event.group_id): |
139 | 144 | return |
140 | 145 |
|
141 | 146 | message_content = "" |
@@ -195,7 +200,7 @@ async def handle_notice(self, event: NoticeEvent, bot: Bot) -> None: |
195 | 200 |
|
196 | 201 | #白名单处理逻辑 |
197 | 202 | if len(config.allow_group_list) != 0 : |
198 | | - if event.group_id not in config.allow_group_list: |
| 203 | + if not is_group_allowed(event.group_id): |
199 | 204 | return |
200 | 205 |
|
201 | 206 | nickname = (await bot.get_login_info())["nickname"] |
@@ -266,7 +271,7 @@ async def handle_image_message(self, event: MessageEvent, bot: Bot) -> None: |
266 | 271 |
|
267 | 272 | #白名单处理逻辑 |
268 | 273 | if len(config.allow_group_list) != 0 : |
269 | | - if event.group_id not in config.allow_group_list: |
| 274 | + if not is_group_allowed(event.group_id): |
270 | 275 | return |
271 | 276 |
|
272 | 277 |
|
@@ -374,7 +379,7 @@ async def handle_reply_message(self, event: MessageEvent, bot: Bot) -> None: |
374 | 379 | else: |
375 | 380 | #白名单处理逻辑 |
376 | 381 | if len(config.allow_group_list) != 0 : |
377 | | - if event.group_id not in config.allow_group_list: |
| 382 | + if not is_group_allowed(event.group_id): |
378 | 383 | return |
379 | 384 |
|
380 | 385 | user_info = UserInfo( |
@@ -417,7 +422,7 @@ async def handle_forward_message(self, event: MessageEvent, bot: Bot) -> None: |
417 | 422 |
|
418 | 423 | #白名单处理逻辑 |
419 | 424 | if len(config.allow_group_list) != 0 : |
420 | | - if event.group_id not in config.allow_group_list: |
| 425 | + if not is_group_allowed(event.group_id): |
421 | 426 | return |
422 | 427 |
|
423 | 428 |
|
|
0 commit comments