mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-02-06 21:10:23 +00:00
NapCatQQ
This commit is contained in:
24
src/onebot11/action/group/GetGroupInfo.ts
Normal file
24
src/onebot11/action/group/GetGroupInfo.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { getGroup } from '@/common/data';
|
||||
import { OB11Group } from '../../types';
|
||||
import { OB11Constructor } from '../../constructor';
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
|
||||
interface PayloadType {
|
||||
group_id: number
|
||||
}
|
||||
|
||||
class GetGroupInfo extends BaseAction<PayloadType, OB11Group> {
|
||||
actionName = ActionName.GetGroupInfo;
|
||||
|
||||
protected async _handle(payload: PayloadType) {
|
||||
const group = await getGroup(payload.group_id.toString());
|
||||
if (group) {
|
||||
return OB11Constructor.group(group);
|
||||
} else {
|
||||
throw `群${payload.group_id}不存在`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default GetGroupInfo;
|
||||
20
src/onebot11/action/group/GetGroupList.ts
Normal file
20
src/onebot11/action/group/GetGroupList.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { OB11Group } from '../../types';
|
||||
import { OB11Constructor } from '../../constructor';
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { groups } from '@/common/data';
|
||||
|
||||
|
||||
class GetGroupList extends BaseAction<null, OB11Group[]> {
|
||||
actionName = ActionName.GetGroupList;
|
||||
|
||||
protected async _handle(payload: null) {
|
||||
// if (groups.length === 0) {
|
||||
// const groups = await NTQQGroupApi.getGroups(true)
|
||||
// log("get groups", groups)
|
||||
// }
|
||||
return OB11Constructor.groups(Array.from(groups.values()));
|
||||
}
|
||||
}
|
||||
|
||||
export default GetGroupList;
|
||||
38
src/onebot11/action/group/GetGroupMemberInfo.ts
Normal file
38
src/onebot11/action/group/GetGroupMemberInfo.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { OB11GroupMember } from '../../types';
|
||||
import { getGroupMember } from '../../../common/data';
|
||||
import { OB11Constructor } from '../../constructor';
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { NTQQUserApi } from '@/core/qqnt/apis/user';
|
||||
import { log } from '../../../common/utils/log';
|
||||
import { isNull } from '../../../common/utils/helper';
|
||||
|
||||
|
||||
export interface PayloadType {
|
||||
group_id: number;
|
||||
user_id: number;
|
||||
}
|
||||
|
||||
class GetGroupMemberInfo extends BaseAction<PayloadType, OB11GroupMember> {
|
||||
actionName = ActionName.GetGroupMemberInfo;
|
||||
|
||||
protected async _handle(payload: PayloadType) {
|
||||
const member = await getGroupMember(payload.group_id.toString(), payload.user_id.toString());
|
||||
// log(member);
|
||||
if (member) {
|
||||
log('获取群成员详细信息');
|
||||
try {
|
||||
const info = (await NTQQUserApi.getUserDetailInfo(member.uid));
|
||||
log('群成员详细信息结果', info);
|
||||
Object.assign(member, info);
|
||||
} catch (e) {
|
||||
log('获取群成员详细信息失败, 只能返回基础信息', e);
|
||||
}
|
||||
return OB11Constructor.groupMember(payload.group_id.toString(), member);
|
||||
} else {
|
||||
throw (`群成员${payload.user_id}不存在`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default GetGroupMemberInfo;
|
||||
26
src/onebot11/action/group/GetGroupMemberList.ts
Normal file
26
src/onebot11/action/group/GetGroupMemberList.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { getGroup } from '@/common/data';
|
||||
import { OB11GroupMember } from '../../types';
|
||||
import { OB11Constructor } from '../../constructor';
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { napCatCore } from '@/core';
|
||||
|
||||
export interface PayloadType {
|
||||
group_id: number
|
||||
}
|
||||
|
||||
|
||||
class GetGroupMemberList extends BaseAction<PayloadType, OB11GroupMember[]> {
|
||||
actionName = ActionName.GetGroupMemberList;
|
||||
|
||||
protected async _handle(payload: PayloadType) {
|
||||
const group = await getGroup(payload.group_id.toString());
|
||||
if (group) {
|
||||
return OB11Constructor.groupMembers(group);
|
||||
} else {
|
||||
throw (`群${payload.group_id}不存在`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default GetGroupMemberList;
|
||||
10
src/onebot11/action/group/GetGuildList.ts
Normal file
10
src/onebot11/action/group/GetGuildList.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
|
||||
export default class GetGuildList extends BaseAction<null, null> {
|
||||
actionName = ActionName.GetGuildList;
|
||||
|
||||
protected async _handle(payload: null): Promise<null> {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
16
src/onebot11/action/group/SendGroupMsg.ts
Normal file
16
src/onebot11/action/group/SendGroupMsg.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import SendMsg from '../msg/SendMsg';
|
||||
import { ActionName, BaseCheckResult } from '../types';
|
||||
import { OB11PostSendMsg } from '../../types';
|
||||
|
||||
|
||||
class SendGroupMsg extends SendMsg {
|
||||
actionName = ActionName.SendGroupMsg;
|
||||
|
||||
protected async check(payload: OB11PostSendMsg): Promise<BaseCheckResult> {
|
||||
delete payload.user_id;
|
||||
payload.message_type = 'group';
|
||||
return super.check(payload);
|
||||
}
|
||||
}
|
||||
|
||||
export default SendGroupMsg;
|
||||
31
src/onebot11/action/group/SetGroupAddRequest.ts
Normal file
31
src/onebot11/action/group/SetGroupAddRequest.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import BaseAction from '../BaseAction';
|
||||
import { GroupRequestOperateTypes } from '@/core/qqnt/entities';
|
||||
import { ActionName } from '../types';
|
||||
import { NTQQGroupApi } from '@/core/qqnt/apis/group';
|
||||
import { groupNotifies } from '@/common/data';
|
||||
|
||||
interface Payload {
|
||||
flag: string,
|
||||
// sub_type: "add" | "invite",
|
||||
// type: "add" | "invite"
|
||||
approve: boolean,
|
||||
reason: string
|
||||
}
|
||||
|
||||
export default class SetGroupAddRequest extends BaseAction<Payload, null> {
|
||||
actionName = ActionName.SetGroupAddRequest;
|
||||
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
const flag = payload.flag.toString();
|
||||
const approve = payload.approve.toString() === 'true';
|
||||
const notify = groupNotifies[flag];
|
||||
if (!notify) {
|
||||
throw `${flag}对应的加群通知不存在`;
|
||||
}
|
||||
await NTQQGroupApi.handleGroupRequest(notify,
|
||||
approve ? GroupRequestOperateTypes.approve : GroupRequestOperateTypes.reject,
|
||||
payload.reason
|
||||
);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
25
src/onebot11/action/group/SetGroupAdmin.ts
Normal file
25
src/onebot11/action/group/SetGroupAdmin.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import BaseAction from '../BaseAction';
|
||||
import { getGroupMember } from '@/common/data';
|
||||
import { GroupMemberRole } from '@/core/qqnt/entities';
|
||||
import { ActionName } from '../types';
|
||||
import { NTQQGroupApi } from '@/core/qqnt/apis/group';
|
||||
|
||||
interface Payload {
|
||||
group_id: number,
|
||||
user_id: number,
|
||||
enable: boolean
|
||||
}
|
||||
|
||||
export default class SetGroupAdmin extends BaseAction<Payload, null> {
|
||||
actionName = ActionName.SetGroupAdmin;
|
||||
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
const member = await getGroupMember(payload.group_id, payload.user_id);
|
||||
const enable = payload.enable.toString() === 'true';
|
||||
if (!member) {
|
||||
throw `群成员${payload.user_id}不存在`;
|
||||
}
|
||||
await NTQQGroupApi.setMemberRole(payload.group_id.toString(), member.uid, enable ? GroupMemberRole.admin : GroupMemberRole.normal);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
24
src/onebot11/action/group/SetGroupBan.ts
Normal file
24
src/onebot11/action/group/SetGroupBan.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import BaseAction from '../BaseAction';
|
||||
import { getGroupMember } from '../../../common/data';
|
||||
import { ActionName } from '../types';
|
||||
import { NTQQGroupApi } from '@/core/qqnt/apis/group';
|
||||
|
||||
interface Payload {
|
||||
group_id: number,
|
||||
user_id: number,
|
||||
duration: number
|
||||
}
|
||||
|
||||
export default class SetGroupBan extends BaseAction<Payload, null> {
|
||||
actionName = ActionName.SetGroupBan;
|
||||
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
const member = await getGroupMember(payload.group_id, payload.user_id);
|
||||
if (!member) {
|
||||
throw `群成员${payload.user_id}不存在`;
|
||||
}
|
||||
await NTQQGroupApi.banMember(payload.group_id.toString(),
|
||||
[{ uid: member.uid, timeStamp: parseInt(payload.duration.toString()) }]);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
23
src/onebot11/action/group/SetGroupCard.ts
Normal file
23
src/onebot11/action/group/SetGroupCard.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import BaseAction from '../BaseAction';
|
||||
import { getGroupMember } from '../../../common/data';
|
||||
import { ActionName } from '../types';
|
||||
import { NTQQGroupApi } from '@/core/qqnt/apis/group';
|
||||
|
||||
interface Payload {
|
||||
group_id: number,
|
||||
user_id: number,
|
||||
card: string
|
||||
}
|
||||
|
||||
export default class SetGroupCard extends BaseAction<Payload, null> {
|
||||
actionName = ActionName.SetGroupCard;
|
||||
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
const member = await getGroupMember(payload.group_id, payload.user_id);
|
||||
if (!member) {
|
||||
throw `群成员${payload.user_id}不存在`;
|
||||
}
|
||||
await NTQQGroupApi.setMemberCard(payload.group_id.toString(), member.uid, payload.card || '');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
23
src/onebot11/action/group/SetGroupKick.ts
Normal file
23
src/onebot11/action/group/SetGroupKick.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import BaseAction from '../BaseAction';
|
||||
import { getGroupMember } from '../../../common/data';
|
||||
import { ActionName } from '../types';
|
||||
import { NTQQGroupApi } from '@/core/qqnt/apis/group';
|
||||
|
||||
interface Payload {
|
||||
group_id: number,
|
||||
user_id: number,
|
||||
reject_add_request: boolean
|
||||
}
|
||||
|
||||
export default class SetGroupKick extends BaseAction<Payload, null> {
|
||||
actionName = ActionName.SetGroupKick;
|
||||
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
const member = await getGroupMember(payload.group_id, payload.user_id);
|
||||
if (!member) {
|
||||
throw `群成员${payload.user_id}不存在`;
|
||||
}
|
||||
await NTQQGroupApi.kickMember(payload.group_id.toString(), [member.uid], !!payload.reject_add_request);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
22
src/onebot11/action/group/SetGroupLeave.ts
Normal file
22
src/onebot11/action/group/SetGroupLeave.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { NTQQGroupApi } from '@/core/qqnt/apis/group';
|
||||
import { log } from '../../../common/utils/log';
|
||||
|
||||
interface Payload {
|
||||
group_id: number,
|
||||
is_dismiss: boolean
|
||||
}
|
||||
|
||||
export default class SetGroupLeave extends BaseAction<Payload, any> {
|
||||
actionName = ActionName.SetGroupLeave;
|
||||
|
||||
protected async _handle(payload: Payload): Promise<any> {
|
||||
try {
|
||||
await NTQQGroupApi.quitGroup(payload.group_id.toString());
|
||||
} catch (e) {
|
||||
log('退群失败', e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
18
src/onebot11/action/group/SetGroupName.ts
Normal file
18
src/onebot11/action/group/SetGroupName.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { NTQQGroupApi } from '@/core/qqnt/apis/group';
|
||||
|
||||
interface Payload {
|
||||
group_id: number,
|
||||
group_name: string
|
||||
}
|
||||
|
||||
export default class SetGroupName extends BaseAction<Payload, null> {
|
||||
actionName = ActionName.SetGroupName;
|
||||
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
|
||||
await NTQQGroupApi.setGroupName(payload.group_id.toString(), payload.group_name);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
18
src/onebot11/action/group/SetGroupWholeBan.ts
Normal file
18
src/onebot11/action/group/SetGroupWholeBan.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { NTQQGroupApi } from '@/core/qqnt/apis/group';
|
||||
|
||||
interface Payload {
|
||||
group_id: number,
|
||||
enable: boolean
|
||||
}
|
||||
|
||||
export default class SetGroupWholeBan extends BaseAction<Payload, null> {
|
||||
actionName = ActionName.SetGroupWholeBan;
|
||||
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
const enable = payload.enable.toString() === 'true';
|
||||
await NTQQGroupApi.banGroup(payload.group_id.toString(), enable);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user