chore: 解耦代码

This commit is contained in:
手瓜一十雪
2024-08-22 13:39:53 +08:00
parent d44b589e55
commit b4e9d61871
5 changed files with 91 additions and 87 deletions

View File

@@ -1,6 +1,7 @@
import { NapCatCore } from '@/core';
import { GrayTipElement, NapCatCore } from '@/core';
import { NapCatOneBot11Adapter } from '@/onebot';
import { OB11FriendPokeEvent } from '../event/notice/OB11PokeEvent';
export class OneBotFriendApi {
obContext: NapCatOneBot11Adapter;
@@ -10,4 +11,22 @@ export class OneBotFriendApi {
this.obContext = obContext;
this.coreContext = coreContext;
}
//使用前预先判断 busiId 1061
async parsePrivatePokeEvent(grayTipElement: GrayTipElement) {
const NTQQUserApi = this.coreContext.apis.UserApi;
const json = JSON.parse(grayTipElement.jsonGrayTipElement.jsonStr);
let pokedetail: any[] = json.items;
//筛选item带有uid的元素
pokedetail = pokedetail.filter(item => item.uid);
//console.log("[NapCat] 群拍一拍 群:", pokedetail, parseInt(msg.peerUid), " ", await NTQQUserApi.getUinByUid(pokedetail[0].uid), "拍了拍", await NTQQUserApi.getUinByUid(pokedetail[1].uid));
if (pokedetail.length == 2) {
return new OB11FriendPokeEvent(
this.coreContext,
parseInt((await NTQQUserApi.getUinByUidV2(pokedetail[0].uid))!),
parseInt((await NTQQUserApi.getUinByUidV2(pokedetail[1].uid))!),
pokedetail
);
}
return undefined;
}
}

View File

@@ -1,6 +1,7 @@
import { NapCatCore } from '@/core';
import { GrayTipElement, NapCatCore } from '@/core';
import { NapCatOneBot11Adapter } from '@/onebot';
import { OB11GroupBanEvent } from '../event/notice/OB11GroupBanEvent';
import { OB11GroupIncreaseEvent } from '../event/notice/OB11GroupIncreaseEvent';
export class OneBotGroupApi {
obContext: NapCatOneBot11Adapter;
@@ -10,4 +11,52 @@ export class OneBotGroupApi {
this.obContext = obContext;
this.coreContext = coreContext;
}
async parseGroupBanEvent(GroupCode: string, grayTipElement: GrayTipElement) {
const groupElement = grayTipElement?.groupElement;
const NTQQGroupApi = this.coreContext.apis.GroupApi;
if (!groupElement?.shutUp) return undefined;
const memberUid = groupElement.shutUp!.member.uid;
const adminUid = groupElement.shutUp!.admin.uid;
let memberUin: string = '';
let duration = parseInt(groupElement.shutUp!.duration);
const subType: 'ban' | 'lift_ban' = duration > 0 ? 'ban' : 'lift_ban';
if (memberUid) {
memberUin = (await NTQQGroupApi.getGroupMember(GroupCode, memberUid))?.uin || '';
} else {
memberUin = '0'; // 0表示全员禁言
if (duration > 0) {
duration = -1;
}
}
const adminUin = (await NTQQGroupApi.getGroupMember(GroupCode, adminUid))?.uin;
if (memberUin && adminUin) {
return new OB11GroupBanEvent(
this.coreContext,
parseInt(GroupCode),
parseInt(memberUin),
parseInt(adminUin),
duration,
subType
);
}
return undefined;
}
async parseGroupMemberIncreaseEvent(GroupCode: string, grayTipElement: GrayTipElement) {
const NTQQGroupApi = this.coreContext.apis.GroupApi;
let groupElement = grayTipElement?.groupElement;
if (!groupElement) return undefined;
const member = await NTQQGroupApi.getGroupMember(GroupCode, groupElement.memberUid);
const memberUin = member?.uin;
const adminMember = await NTQQGroupApi.getGroupMember(GroupCode, groupElement.adminUid);
if (memberUin) {
const operatorUin = adminMember?.uin || memberUin;
return new OB11GroupIncreaseEvent(
this.coreContext,
parseInt(GroupCode),
parseInt(memberUin),
parseInt(operatorUin)
);
}
return undefined;
}
}