Fix: Add validation for user_id='all' in group member actions

Add early validation to reject user_id='all' with clear error messages in:
- GetGroupMemberInfo
- SetGroupKick
- SetGroupAdmin
- SetGroupBan
- SetGroupCard

This prevents "Uin2Uid Error: 用户ID all 不存在" when receiving @all mentions.

Co-authored-by: sj817 <74231782+sj817@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2025-11-07 10:19:06 +00:00
parent 8e8fc471ed
commit f3b9f1916f
5 changed files with 21 additions and 0 deletions

View File

@ -41,6 +41,11 @@ class GetGroupMemberInfo extends OneBotAction<Payload, OB11GroupMember> {
}
async _handle (payload: Payload) {
// Handle special case of 'all' which is used for @all mentions
if (payload.user_id === 'all') {
throw new Error('无法获取全体成员的信息user_id 不能为 "all"');
}
const isNocache = this.parseBoolean(payload.no_cache ?? true);
const uid = await this.getUid(payload.user_id);
const member = await this.getGroupMemberInfo(payload, uid, isNocache);

View File

@ -16,6 +16,10 @@ export default class SetGroupAdmin extends OneBotAction<Payload, null> {
override payloadSchema = SchemaData;
async _handle (payload: Payload): Promise<null> {
if (payload.user_id === 'all') {
throw new Error('无法设置全体成员为管理员user_id 不能为 "all"');
}
const enable = typeof payload.enable === 'string' ? payload.enable === 'true' : !!payload.enable;
const uid = await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString());
if (!uid) throw new Error('get Uid Error');

View File

@ -14,6 +14,10 @@ export default class SetGroupBan extends OneBotAction<Payload, null> {
override actionName = ActionName.SetGroupBan;
override payloadSchema = SchemaData;
async _handle (payload: Payload): Promise<null> {
if (payload.user_id === 'all') {
throw new Error('无法禁言全体成员,请使用 set_group_whole_banuser_id 不能为 "all"');
}
const uid = await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString());
if (!uid) throw new Error('uid error');
const member_role = (await this.core.apis.GroupApi.getGroupMemberEx(payload.group_id.toString(), uid, true))?.role;

View File

@ -15,6 +15,10 @@ export default class SetGroupCard extends OneBotAction<Payload, null> {
override payloadSchema = SchemaData;
async _handle (payload: Payload): Promise<null> {
if (payload.user_id === 'all') {
throw new Error('无法设置全体成员的群名片user_id 不能为 "all"');
}
const member = await this.core.apis.GroupApi.getGroupMember(payload.group_id.toString(), payload.user_id.toString());
if (member) await this.core.apis.GroupApi.setMemberCard(payload.group_id.toString(), member.uid, payload.card || '');
return null;

View File

@ -15,6 +15,10 @@ export default class SetGroupKick extends OneBotAction<Payload, null> {
override payloadSchema = SchemaData;
async _handle (payload: Payload): Promise<null> {
if (payload.user_id === 'all') {
throw new Error('无法踢出全体成员user_id 不能为 "all"');
}
const rejectReq = payload.reject_add_request?.toString() === 'true';
const uid = await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString());
if (!uid) throw new Error('get Uid Error');