NapCatQQ source snapshot
This commit is contained in:
commit
f954252a34
1111 files changed
+139867
No files matched your search
@@ -0,0 +1,50 @@
|
||||
import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/napcat-onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
|
||||
export const GetCookiesPayloadSchema = Type.Object({
|
||||
domain: Type.String({ description: '需要获取 cookies 的域名' }),
|
||||
});
|
||||
|
||||
export type GetCookiesPayload = Static<typeof GetCookiesPayloadSchema>;
|
||||
|
||||
export const GetCookiesReturnSchema = Type.Object({
|
||||
cookies: Type.String({ description: 'Cookies' }),
|
||||
bkn: Type.String({ description: 'CSRF Token' }),
|
||||
});
|
||||
|
||||
export type GetCookiesResponse = Static<typeof GetCookiesReturnSchema>;
|
||||
|
||||
export class GetCookies extends OneBotAction<GetCookiesPayload, GetCookiesResponse> {
|
||||
override actionName = ActionName.GetCookies;
|
||||
override payloadSchema = GetCookiesPayloadSchema;
|
||||
override returnSchema = GetCookiesReturnSchema;
|
||||
override actionSummary = '获取 Cookies';
|
||||
override actionDescription = '获取指定域名的 Cookies';
|
||||
override actionTags = ['用户接口'];
|
||||
override payloadExample = {
|
||||
domain: 'qun.qq.com',
|
||||
};
|
||||
|
||||
override returnExample = {
|
||||
cookies: 'uin=o123456789; skey=@abc12345;',
|
||||
bkn: '123456789',
|
||||
};
|
||||
|
||||
async _handle (payload: GetCookiesPayload) {
|
||||
const cookiesObject = await this.core.apis.UserApi.getCookies(payload.domain);
|
||||
// 把获取到的cookiesObject转换成 k=v; 格式字符串拼接在一起
|
||||
const cookies = Object.entries(cookiesObject).map(([key, value]) => `${key}=${value}`).join('; ');
|
||||
let bkn = '';
|
||||
if (payload.domain.includes('qzone.qq.com')) {
|
||||
if (cookiesObject?.['p_skey']) {
|
||||
bkn = this.core.apis.WebApi.getBknFromPSKey(cookiesObject['p_skey']);
|
||||
} else {
|
||||
bkn = cookiesObject?.['skey'] ? this.core.apis.WebApi.getBknFromCookie(cookiesObject) : '';
|
||||
}
|
||||
} else {
|
||||
bkn = cookiesObject?.['skey'] ? this.core.apis.WebApi.getBknFromCookie(cookiesObject) : '';
|
||||
}
|
||||
return { cookies, bkn };
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import { OB11Construct } from '@/napcat-onebot/helper/data';
|
||||
import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/napcat-onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { OB11UserSchema } from '../schemas';
|
||||
import { UserActionsExamples } from '@/napcat-onebot/action/example/UserActionsExamples';
|
||||
|
||||
const PayloadSchema = Type.Object({
|
||||
no_cache: Type.Optional(Type.Union([Type.Boolean(), Type.String()], { description: '是否不使用缓存' })),
|
||||
});
|
||||
|
||||
type PayloadType = Static<typeof PayloadSchema>;
|
||||
|
||||
const ReturnSchema = Type.Array(OB11UserSchema, { description: '好友列表' });
|
||||
|
||||
type ReturnType = Static<typeof ReturnSchema>;
|
||||
|
||||
export default class GetFriendList extends OneBotAction<PayloadType, ReturnType> {
|
||||
override actionName = ActionName.GetFriendList;
|
||||
override payloadSchema = PayloadSchema;
|
||||
override returnSchema = ReturnSchema;
|
||||
override actionSummary = '获取好友列表';
|
||||
override actionDescription = '获取当前帐号的好友列表';
|
||||
override actionTags = ['用户接口'];
|
||||
override payloadExample = UserActionsExamples.GetFriendList.payload;
|
||||
override returnExample = UserActionsExamples.GetFriendList.response;
|
||||
|
||||
async _handle (_payload: PayloadType) {
|
||||
const buddyMap = await this.core.apis.FriendApi.getBuddyV2SimpleInfoMap();
|
||||
const isNocache = typeof _payload.no_cache === 'string' ? _payload.no_cache === 'true' : !!_payload.no_cache;
|
||||
await Promise.all(
|
||||
Array.from(buddyMap.values()).map(async (buddyInfo) => {
|
||||
try {
|
||||
const userDetail = await this.core.apis.UserApi.getUserDetailInfo(buddyInfo.coreInfo.uid, isNocache);
|
||||
const data = buddyMap.get(buddyInfo.coreInfo.uid);
|
||||
if (data) {
|
||||
data.qqLevel = userDetail.qqLevel;
|
||||
}
|
||||
} catch (error) {
|
||||
this.core.context.logger.logError('获取好友详细信息失败', error);
|
||||
}
|
||||
})
|
||||
);
|
||||
return OB11Construct.friends(Array.from(buddyMap.values()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/napcat-onebot/action/router';
|
||||
import { NetworkAdapterConfig } from '@/napcat-onebot/config/config';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
|
||||
export const GetRecentContactPayloadSchema = Type.Object({
|
||||
count: Type.Union([Type.Number(), Type.String()], { default: 10, description: '获取的数量' }),
|
||||
});
|
||||
|
||||
export type GetRecentContactPayload = Static<typeof GetRecentContactPayloadSchema>;
|
||||
|
||||
export const GetRecentContactReturnSchema = Type.Array(Type.Object({
|
||||
lastestMsg: Type.Any({ description: '最后一条消息' }),
|
||||
peerUin: Type.String({ description: '对象QQ' }),
|
||||
remark: Type.String({ description: '备注' }),
|
||||
msgTime: Type.String({ description: '消息时间' }),
|
||||
chatType: Type.Number({ description: '聊天类型' }),
|
||||
msgId: Type.String({ description: '消息ID' }),
|
||||
sendNickName: Type.String({ description: '发送者昵称' }),
|
||||
sendMemberName: Type.String({ description: '发送者群名片' }),
|
||||
peerName: Type.String({ description: '对象名称' }),
|
||||
}), { description: '最近会话列表' });
|
||||
|
||||
export type GetRecentContactReturn = Static<typeof GetRecentContactReturnSchema>;
|
||||
|
||||
export default class GetRecentContact extends OneBotAction<GetRecentContactPayload, GetRecentContactReturn> {
|
||||
override actionName = ActionName.GetRecentContact;
|
||||
override payloadSchema = GetRecentContactPayloadSchema;
|
||||
override returnSchema = GetRecentContactReturnSchema;
|
||||
override actionSummary = '获取最近会话';
|
||||
override actionDescription = '获取最近会话';
|
||||
override actionTags = ['用户接口'];
|
||||
override payloadExample = {
|
||||
count: 10,
|
||||
};
|
||||
|
||||
override returnExample = [
|
||||
{
|
||||
peerUin: '123456',
|
||||
peerName: '测试',
|
||||
msgTime: '1734567890',
|
||||
msgId: '12345',
|
||||
lastestMsg: {},
|
||||
},
|
||||
];
|
||||
|
||||
async _handle (payload: GetRecentContactPayload, _adapter: string, config: NetworkAdapterConfig): Promise<GetRecentContactReturn> {
|
||||
const ret = await this.core.apis.UserApi.getRecentContactListSnapShot(+payload.count);
|
||||
// 烘焙消息
|
||||
const results = await Promise.all(ret.info.changedList.map(async (t) => {
|
||||
const FastMsg = await this.core.apis.MsgApi.getMsgsByMsgId({ chatType: t.chatType, peerUid: t.peerUid }, [t.msgId]);
|
||||
if (FastMsg.msgList.length > 0 && FastMsg.msgList[0]) {
|
||||
// 扩展ret.info.changedList
|
||||
const lastestMsg = await this.obContext.apis.MsgApi.parseMessage(FastMsg.msgList[0], config.messagePostFormat);
|
||||
return {
|
||||
lastestMsg,
|
||||
peerUin: t.peerUin,
|
||||
remark: String(t.remark ?? ''),
|
||||
msgTime: t.msgTime,
|
||||
chatType: t.chatType,
|
||||
msgId: t.msgId,
|
||||
sendNickName: String(t.sendNickName ?? ''),
|
||||
sendMemberName: String(t.sendMemberName ?? ''),
|
||||
peerName: String(t.peerName ?? ''),
|
||||
};
|
||||
}
|
||||
return {
|
||||
lastestMsg: undefined,
|
||||
peerUin: t.peerUin,
|
||||
remark: String(t.remark ?? ''),
|
||||
msgTime: t.msgTime,
|
||||
chatType: t.chatType,
|
||||
msgId: t.msgId,
|
||||
sendNickName: String(t.sendNickName ?? ''),
|
||||
sendMemberName: String(t.sendMemberName ?? ''),
|
||||
peerName: String(t.peerName ?? ''),
|
||||
};
|
||||
}));
|
||||
return results;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/napcat-onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
export const SendLikePayloadSchema = Type.Object({
|
||||
user_id: Type.String({ description: '对方 QQ 号' }),
|
||||
times: Type.Union([Type.Number(), Type.String()], { default: 1, description: '点赞次数' }),
|
||||
});
|
||||
|
||||
export type SendLikePayload = Static<typeof SendLikePayloadSchema>;
|
||||
|
||||
export default class SendLike extends OneBotAction<SendLikePayload, void> {
|
||||
override actionName = ActionName.SendLike;
|
||||
override payloadSchema = SendLikePayloadSchema;
|
||||
override returnSchema = Type.Null();
|
||||
override actionSummary = '点赞';
|
||||
override actionDescription = '给指定用户点赞';
|
||||
override actionTags = ['用户接口'];
|
||||
override payloadExample = {
|
||||
user_id: '123456',
|
||||
times: 10,
|
||||
};
|
||||
|
||||
override returnExample = {};
|
||||
override errorExamples = [
|
||||
{ code: 1400, description: '点赞失败(频率过快或用户不存在)' },
|
||||
];
|
||||
|
||||
async _handle (payload: SendLikePayload): Promise<void> {
|
||||
const qq = payload.user_id.toString();
|
||||
const uid: string = await this.core.apis.UserApi.getUidByUinV2(qq) ?? '';
|
||||
const result = await this.core.apis.UserApi.like(uid, +payload.times);
|
||||
if (result.result !== 0) {
|
||||
throw new Error(`点赞失败 ${result.errMsg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/napcat-onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
|
||||
export const SetFriendAddRequestPayloadSchema = Type.Object({
|
||||
flag: Type.String({ description: '加好友请求的 flag (需从上报中获取)' }),
|
||||
approve: Type.Optional(Type.Union([Type.String(), Type.Boolean()], { description: '是否同意请求' })),
|
||||
remark: Type.Optional(Type.String({ description: '添加后的好友备注' })),
|
||||
});
|
||||
|
||||
export type SetFriendAddRequestPayload = Static<typeof SetFriendAddRequestPayloadSchema>;
|
||||
|
||||
export default class SetFriendAddRequest extends OneBotAction<SetFriendAddRequestPayload, void> {
|
||||
override actionName = ActionName.SetFriendAddRequest;
|
||||
override payloadSchema = SetFriendAddRequestPayloadSchema;
|
||||
override returnSchema = Type.Null();
|
||||
override actionSummary = '处理加好友请求';
|
||||
override actionDescription = '同意或拒绝加好友请求';
|
||||
override actionTags = ['用户接口'];
|
||||
override payloadExample = {
|
||||
flag: 'flag_12345',
|
||||
approve: true,
|
||||
remark: '新朋友',
|
||||
};
|
||||
|
||||
override returnExample = {};
|
||||
|
||||
async _handle (payload: SetFriendAddRequestPayload): Promise<void> {
|
||||
const approve = payload.approve?.toString() !== 'false';
|
||||
const notify = (await this.core.apis.FriendApi.getBuddyReq()).buddyReqs.find(e => e.reqTime === payload.flag.toString());
|
||||
if (!notify) {
|
||||
throw new Error('No such request');
|
||||
}
|
||||
await this.core.apis.FriendApi.handleFriendRequest(notify, approve);
|
||||
if (payload.remark) {
|
||||
await this.core.apis.FriendApi.setBuddyRemark(notify.friendUid, payload.remark);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/napcat-onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
|
||||
export const SetFriendRemarkPayloadSchema = Type.Object({
|
||||
user_id: Type.String({ description: '对方 QQ 号' }),
|
||||
remark: Type.String({ description: '备注内容' }),
|
||||
});
|
||||
|
||||
export type SetFriendRemarkPayload = Static<typeof SetFriendRemarkPayloadSchema>;
|
||||
|
||||
export default class SetFriendRemark extends OneBotAction<SetFriendRemarkPayload, void> {
|
||||
override actionName = ActionName.SetFriendRemark;
|
||||
override payloadSchema = SetFriendRemarkPayloadSchema;
|
||||
override returnSchema = Type.Null();
|
||||
override actionSummary = '设置好友备注';
|
||||
override actionDescription = '设置好友备注';
|
||||
override actionTags = ['用户接口'];
|
||||
override payloadExample = {
|
||||
user_id: '123456',
|
||||
remark: '测试备注',
|
||||
};
|
||||
|
||||
override returnExample = null;
|
||||
override errorExamples = [
|
||||
{ code: 1400, description: '备注设置失败(好友不存在或非法输入)' },
|
||||
];
|
||||
|
||||
async _handle (payload: SetFriendRemarkPayload): Promise<void> {
|
||||
const friendUid = await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString());
|
||||
const is_friend = await this.core.apis.FriendApi.isBuddy(friendUid);
|
||||
if (!is_friend) {
|
||||
throw new Error(`用户 ${payload.user_id} 不是好友`);
|
||||
}
|
||||
await this.core.apis.FriendApi.setBuddyRemark(friendUid, payload.remark);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user