mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
refactor: uin - > uid
This commit is contained in:
parent
4b616299cf
commit
9a502cdf6f
@ -11,22 +11,22 @@ interface OB11GroupRequestNotify {
|
||||
flag: string
|
||||
}
|
||||
|
||||
export default class GetGroupAddRequest extends BaseAction<null, OB11GroupRequestNotify[]> {
|
||||
export default class GetGroupAddRequest extends BaseAction<null, OB11GroupRequestNotify[] | null> {
|
||||
actionName = ActionName.GetGroupIgnoreAddRequest;
|
||||
|
||||
protected async _handle(payload: null): Promise<OB11GroupRequestNotify[]> {
|
||||
protected async _handle(payload: null): Promise<OB11GroupRequestNotify[] | null> {
|
||||
const data = await NTQQGroupApi.getGroupIgnoreNotifies();
|
||||
// log(data);
|
||||
const notifies: GroupNotify[] = data.notifies.filter(notify => notify.status === GroupNotifyStatus.WAIT_HANDLE);
|
||||
const returnData: OB11GroupRequestNotify[] = [];
|
||||
for (const notify of notifies) {
|
||||
const uin = uid2UinMap[notify.user1.uid] || (await NTQQUserApi.getUserDetailInfo(notify.user1.uid))?.uin;
|
||||
returnData.push({
|
||||
group_id: parseInt(notify.group.groupCode),
|
||||
user_id: parseInt(uin),
|
||||
flag: notify.seq
|
||||
});
|
||||
}
|
||||
return returnData;
|
||||
// const notifies: GroupNotify[] = data.notifies.filter(notify => notify.status === GroupNotifyStatus.WAIT_HANDLE);
|
||||
// const returnData: OB11GroupRequestNotify[] = [];
|
||||
// for (const notify of notifies) {
|
||||
// const uin = uid2UinMap[notify.user1.uid] || (await NTQQUserApi.getUserDetailInfo(notify.user1.uid))?.uin;
|
||||
// returnData.push({
|
||||
// group_id: parseInt(notify.group.groupCode),
|
||||
// user_id: parseInt(uin),
|
||||
// flag: notify.seq
|
||||
// });
|
||||
// }
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,8 @@
|
||||
import BaseAction from '../BaseAction';
|
||||
import { OB11User } from '../../types';
|
||||
import { getUidByUin, uid2UinMap } from '@/core/data';
|
||||
import { OB11Constructor } from '../../constructor';
|
||||
import { ActionName } from '../types';
|
||||
import { NTQQUserApi } from '@/core/apis/user';
|
||||
import { log, logDebug } from '@/common/utils/log';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
|
||||
const SchemaData = {
|
||||
@ -23,10 +21,11 @@ export default class GoCQHTTPGetStrangerInfo extends BaseAction<Payload, OB11Use
|
||||
protected async _handle(payload: Payload): Promise<OB11User> {
|
||||
const user_id = payload.user_id.toString();
|
||||
//logDebug('uidMaps', uidMaps);
|
||||
const uid = getUidByUin(user_id);
|
||||
if (!uid) {
|
||||
throw new Error('查无此人');
|
||||
}
|
||||
return OB11Constructor.stranger(await NTQQUserApi.getUserDetailInfo(uid));
|
||||
// const uid = getUidByUin(user_id);
|
||||
// if (!uid) {
|
||||
// throw new Error('查无此人');
|
||||
// }
|
||||
// !!!!!!!!!!!!!!!需要重构
|
||||
return OB11Constructor.stranger(await NTQQUserApi.getUserDetailInfo((await NTQQUserApi.getUidByUin(user_id))!));
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,7 @@
|
||||
import BaseAction from '../BaseAction';
|
||||
import { NTQQMsgApi } from '@/core/apis';
|
||||
import { NTQQMsgApi, NTQQUserApi } from '@/core/apis';
|
||||
import { ChatType, Peer } from '@/core/entities';
|
||||
import { dbUtil } from '@/common/utils/db';
|
||||
import { getUidByUin } from '@/core/data';
|
||||
import { ActionName } from '../types';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
|
||||
@ -21,7 +20,7 @@ type Payload = FromSchema<typeof SchemaData>;
|
||||
class ForwardSingleMsg extends BaseAction<Payload, null> {
|
||||
protected async getTargetPeer(payload: Payload): Promise<Peer> {
|
||||
if (payload.user_id) {
|
||||
const peerUid = getUidByUin(payload.user_id.toString());
|
||||
const peerUid = await NTQQUserApi.getUidByUin(payload.user_id.toString());
|
||||
if (!peerUid) {
|
||||
throw new Error(`无法找到私聊对象${payload.user_id}`);
|
||||
}
|
||||
|
@ -1,15 +1,15 @@
|
||||
import { ChatType, Peer } from '@/core/entities';
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { NTQQMsgApi } from '@/core/apis';
|
||||
import { getFriend, getUidByUin } from '@/core/data';
|
||||
import { NTQQMsgApi, NTQQUserApi } from '@/core/apis';
|
||||
import { getFriend } from '@/core/data';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
user_id: { type: [ 'number' , 'string' ] },
|
||||
group_id: { type: [ 'number' , 'string' ] }
|
||||
user_id: { type: ['number', 'string'] },
|
||||
group_id: { type: ['number', 'string'] }
|
||||
}
|
||||
} as const satisfies JSONSchema;
|
||||
|
||||
@ -18,12 +18,12 @@ type PlayloadType = FromSchema<typeof SchemaData>;
|
||||
class MarkMsgAsRead extends BaseAction<PlayloadType, null> {
|
||||
async getPeer(payload: PlayloadType): Promise<Peer> {
|
||||
if (payload.user_id) {
|
||||
const peerUid = getUidByUin(payload.user_id.toString());
|
||||
const peerUid = await NTQQUserApi.getUidByUin(payload.user_id.toString());
|
||||
if (!peerUid) {
|
||||
throw `私聊${payload.user_id}不存在`;
|
||||
}
|
||||
const friend = await getFriend(peerUid);
|
||||
return { chatType: friend ? ChatType.friend: ChatType.temp, peerUid };
|
||||
return { chatType: friend ? ChatType.friend : ChatType.temp, peerUid };
|
||||
}
|
||||
if (!payload.group_id) {
|
||||
throw '缺少参数 group_id 或 user_id';
|
||||
@ -50,11 +50,11 @@ export class MarkGroupMsgAsRead extends MarkMsgAsRead {
|
||||
}
|
||||
|
||||
|
||||
interface Payload{
|
||||
interface Payload {
|
||||
message_id: number
|
||||
}
|
||||
|
||||
export class GoCQHTTPMarkMsgAsRead extends BaseAction<Payload, null>{
|
||||
export class GoCQHTTPMarkMsgAsRead extends BaseAction<Payload, null> {
|
||||
actionName = ActionName.GoCQHTTP_MarkMsgAsRead;
|
||||
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
|
@ -7,9 +7,9 @@ import {
|
||||
OB11PostSendMsg
|
||||
} from '@/onebot11/types';
|
||||
import { ActionName, BaseCheckResult } from '@/onebot11/action/types';
|
||||
import { getFriend, getGroup, getUidByUin } from '@/core/data';
|
||||
import { getFriend, getGroup } from '@/core/data';
|
||||
import { dbUtil } from '@/common/utils/db';
|
||||
import { ChatType, ElementType, Group, NTQQMsgApi, Peer, SendMessageElement, } from '@/core';
|
||||
import { ChatType, ElementType, Group, NTQQMsgApi, NTQQUserApi, Peer, SendMessageElement, } from '@/core';
|
||||
import fs from 'node:fs';
|
||||
import { logDebug, logError } from '@/common/utils/log';
|
||||
import { decodeCQCode } from '@/onebot11/cqcode';
|
||||
@ -93,7 +93,8 @@ async function createContext(payload: OB11PostSendMsg): Promise<{
|
||||
const friend = await getFriend(payload.user_id.toString());
|
||||
if (!friend) {
|
||||
if (ALLOW_SEND_TEMP_MSG) {
|
||||
const tempUid = getUidByUin(payload.user_id.toString());
|
||||
//const tempUid = getUidByUin(payload.user_id.toString());
|
||||
const tempUid = await NTQQUserApi.getUidByUin(payload.user_id.toString());
|
||||
if (tempUid) return {
|
||||
peer: {
|
||||
chatType: ChatType.temp,
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { NTQQUserApi } from '@/core/apis';
|
||||
import BaseAction from '../BaseAction';
|
||||
import { getFriend, getUidByUin, uid2UinMap } from '@/core/data';
|
||||
import { getFriend } from '@/core/data';
|
||||
import { ActionName } from '../types';
|
||||
import { log, logDebug } from '@/common/utils/log';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
@ -8,7 +8,7 @@ import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
user_id: { type: [ 'number' , 'string' ] },
|
||||
user_id: { type: ['number', 'string'] },
|
||||
times: { type: 'number' }
|
||||
},
|
||||
required: ['user_id', 'times']
|
||||
@ -26,7 +26,7 @@ export default class SendLike extends BaseAction<Payload, null> {
|
||||
const friend = await getFriend(qq);
|
||||
let uid: string;
|
||||
if (!friend) {
|
||||
uid = getUidByUin(qq) || '';
|
||||
uid = await NTQQUserApi.getUidByUin(qq) || '';
|
||||
} else {
|
||||
uid = friend.uid;
|
||||
}
|
||||
|
@ -338,7 +338,7 @@ export class OB11Constructor {
|
||||
deleteGroup(msg.peerUid);
|
||||
NTQQGroupApi.quitGroup(msg.peerUid).then();
|
||||
try {
|
||||
const adminUin = (await getGroupMember(msg.peerUid, groupElement.adminUid))?.uin || (await NTQQUserApi.getUserDetailInfo(groupElement.adminUid))?.uin;
|
||||
const adminUin = (await getGroupMember(msg.peerUid, groupElement.adminUid))?.uin || (await NTQQUserApi.getUidByUin(groupElement.adminUid));
|
||||
if (adminUin) {
|
||||
return new OB11GroupDecreaseEvent(parseInt(msg.peerUid), parseInt(selfInfo.uin), parseInt(adminUin), 'kick_me');
|
||||
}
|
||||
|
@ -424,18 +424,18 @@ export class NapCatOnebot11 {
|
||||
} else if (notify.type == GroupNotifyTypes.MEMBER_EXIT || notify.type == GroupNotifyTypes.KICK_MEMBER) {
|
||||
logDebug('有成员退出通知', notify);
|
||||
try {
|
||||
const member1 = await NTQQUserApi.getUserDetailInfo(notify.user1.uid);
|
||||
let operatorId = member1.uin;
|
||||
const member1Uin = (await NTQQUserApi.getUinByUid(notify.user1.uid))!;
|
||||
let operatorId = member1Uin;
|
||||
let subType: GroupDecreaseSubType = 'leave';
|
||||
if (notify.user2.uid) {
|
||||
// 是被踢的
|
||||
const member2 = await getGroupMember(notify.group.groupCode, notify.user2.uid);
|
||||
if (member2) {
|
||||
operatorId = member2.uin;
|
||||
const member2Uin = await NTQQUserApi.getUinByUid(notify.user2.uid);
|
||||
if (member2Uin) {
|
||||
operatorId = member2Uin;
|
||||
}
|
||||
subType = 'kick';
|
||||
}
|
||||
const groupDecreaseEvent = new OB11GroupDecreaseEvent(parseInt(notify.group.groupCode), parseInt(member1.uin), parseInt(operatorId), subType);
|
||||
const groupDecreaseEvent = new OB11GroupDecreaseEvent(parseInt(notify.group.groupCode), parseInt(member1Uin), parseInt(operatorId), subType);
|
||||
postOB11Event(groupDecreaseEvent, true);
|
||||
} catch (e: any) {
|
||||
logError('获取群通知的成员信息失败', notify, e.stack.toString());
|
||||
@ -463,7 +463,7 @@ export class NapCatOnebot11 {
|
||||
groupInviteEvent.group_id = parseInt(notify.group.groupCode);
|
||||
let user_id = (await getFriend(notify.user2.uid))?.uin;
|
||||
if (!user_id) {
|
||||
user_id = (await NTQQUserApi.getUserDetailInfo(notify.user2.uid))?.uin;
|
||||
user_id = (await NTQQUserApi.getUinByUid(notify.user2.uid)) || '';
|
||||
}
|
||||
groupInviteEvent.user_id = parseInt(user_id);
|
||||
groupInviteEvent.sub_type = 'invite';
|
||||
@ -520,8 +520,8 @@ export class NapCatOnebot11 {
|
||||
friendRequests[flag] = req;
|
||||
const friendRequestEvent = new OB11FriendRequestEvent();
|
||||
try {
|
||||
const requester = await NTQQUserApi.getUserDetailInfo(req.friendUid);
|
||||
friendRequestEvent.user_id = parseInt(requester.uin);
|
||||
const requesterUin = await NTQQUserApi.getUinByUid(req.friendUid);
|
||||
friendRequestEvent.user_id = parseInt(requesterUin!);
|
||||
} catch (e) {
|
||||
logDebug('获取加好友者QQ号失败', e);
|
||||
}
|
||||
|
@ -12,8 +12,8 @@ import { OB11FriendRequestEvent } from '../event/request/OB11FriendRequest';
|
||||
import { OB11GroupRequestEvent } from '../event/request/OB11GroupRequest';
|
||||
import { isNull } from '@/common/utils/helper';
|
||||
import { dbUtil } from '@/common/utils/db';
|
||||
import { friendRequests, getGroup, getUidByUin, groupNotifies, selfInfo } from '@/core/data';
|
||||
import { NTQQFriendApi, NTQQGroupApi, NTQQMsgApi } from '@/core/apis';
|
||||
import { friendRequests, getGroup, groupNotifies, selfInfo } from '@/core/data';
|
||||
import { NTQQFriendApi, NTQQGroupApi, NTQQUserApi } from '@/core/apis';
|
||||
import createSendElements from '../action/msg/SendMsg/create-send-elements';
|
||||
|
||||
export type QuickActionEvent = OB11Message | OB11BaseMetaEvent | OB11BaseNoticeEvent
|
||||
@ -129,7 +129,7 @@ async function handleMsg(msg: OB11Message, quickAction: QuickAction) {
|
||||
const reply = quickAction.reply;
|
||||
const peer: Peer = {
|
||||
chatType: ChatType.friend,
|
||||
peerUid: getUidByUin(msg.user_id.toString()) as string
|
||||
peerUid: await NTQQUserApi.getUidByUin(msg.user_id.toString()) as string
|
||||
};
|
||||
if (msg.message_type == 'private') {
|
||||
if (msg.sub_type === 'group') {
|
||||
|
Loading…
x
Reference in New Issue
Block a user