Skip to content

Commit

Permalink
🐛 修复群组入群与退群提示
Browse files Browse the repository at this point in the history
  • Loading branch information
HibiKier committed Jan 22, 2025
1 parent f8e6503 commit d682892
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
group_decrease_handle = on_notice(
priority=1,
block=False,
rule=notice_rule([GroupMemberDecreaseEvent, GroupMemberIncreaseEvent]),
rule=notice_rule([GroupMemberDecreaseEvent, GroupDecreaseNoticeEvent]),
)
"""群员减少处理"""
add_group = on_request(priority=1, block=False)
Expand Down
34 changes: 20 additions & 14 deletions zhenxun/builtin_plugins/platform/qq/group_handle/data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import random

from nonebot.adapters import Bot
from nonebot.exception import ActionFailed
from nonebot_plugin_alconna import At, UniMessage
from nonebot_plugin_uninfo import Uninfo
import ujson as json
Expand Down Expand Up @@ -54,7 +55,7 @@ async def __handle_add_group(
if plugin_list := await PluginInfo.filter(default_status=False).all():
for plugin in plugin_list:
block_plugin += f"<{plugin.module},"
group_info = await bot.get_group_info(group_id=group_id)
group_info = await bot.get_group_info(group_id=group_id, no_cache=True)
await GroupConsole.create(
group_id=group_info["group_id"],
group_name=group_info["group_name"],
Expand Down Expand Up @@ -215,17 +216,14 @@ async def __send_welcome_message(cls, session: Uninfo, user_id: str):
msg_list.insert(0, At("user", user_id))
logger.info("发送群欢迎消息...", "入群检测", session=session)
if msg_list:
await MessageUtils.build_message(msg_list).send() # type: ignore
else:
image = DEFAULT_IMAGE_PATH / random.choice(
os.listdir(DEFAULT_IMAGE_PATH)
)
await MessageUtils.build_message(
[
"新人快跑啊!!本群现状↓(快使用自定义群欢迎消息!)",
image,
]
).send()
await MessageUtils.build_message(msg_list).finish() # type: ignore
image = DEFAULT_IMAGE_PATH / random.choice(os.listdir(DEFAULT_IMAGE_PATH))
await MessageUtils.build_message(
[
"新人快跑啊!!本群现状↓(快使用自定义群欢迎消息!)",
image,
]
).send()

@classmethod
async def add_user(cls, session: Uninfo, bot: Bot, user_id: str, group_id: str):
Expand All @@ -237,11 +235,19 @@ async def add_user(cls, session: Uninfo, bot: Bot, user_id: str, group_id: str):
group_id: 群组id
"""
join_time = datetime.now()
user_info = await bot.get_group_member_info(group_id=group_id, user_id=user_id)
try:
user_info = await bot.get_group_member_info(
group_id=group_id, user_id=user_id, no_cache=True
)
except ActionFailed:
user_info = {"user_id": user_id, "group_id": group_id, "nickname": ""}
await GroupInfoUser.update_or_create(
user_id=str(user_info["user_id"]),
group_id=str(user_info["group_id"]),
defaults={"user_name": user_info["nickname"], "user_join_time": join_time},
defaults={
"user_name": user_info["nickname"],
"user_join_time": join_time,
},
)
logger.info(f"用户{user_info['user_id']} 所属{user_info['group_id']} 更新成功")
if not await CommonUtils.task_is_block(
Expand Down

0 comments on commit d682892

Please sign in to comment.