Merge remote-tracking branch 'origin/main'

# Conflicts:
#	package.json
This commit is contained in:
linyuchen
2024-04-24 21:04:34 +08:00
62 changed files with 134 additions and 77 deletions

View File

@@ -19,25 +19,25 @@ interface Response {
}
export default class GetFriendMsgHistory extends BaseAction<Payload, Response> {
actionName = ActionName.GetFriendMsgHistory;
actionName = ActionName.GetFriendMsgHistory;
protected async _handle(payload: Payload): Promise<Response> {
let uid = getUidByUin(payload.user_id.toString())
if (!uid) {
throw `记录${payload.user_id}不存在`;
}
const startMsgId = (await dbUtil.getMsgByShortId(payload.message_seq))?.msgId || '0';
let friend = await getFriend(uid);
let historyResult = (await NTQQMsgApi.getMsgHistory({
chatType: friend ? ChatType.friend : ChatType.temp,
peerUid: uid
}, startMsgId, parseInt(payload.count?.toString()) || 20));
console.log(historyResult);
const msgList = historyResult.msgList;
await Promise.all(msgList.map(async msg => {
msg.id = await dbUtil.addMsg(msg);
}));
const ob11MsgList = await Promise.all(msgList.map(msg => OB11Constructor.message(msg)));
return { 'messages': ob11MsgList };
protected async _handle(payload: Payload): Promise<Response> {
const uid = getUidByUin(payload.user_id.toString());
if (!uid) {
throw `记录${payload.user_id}不存在`;
}
const startMsgId = (await dbUtil.getMsgByShortId(payload.message_seq))?.msgId || '0';
const friend = await getFriend(uid);
const historyResult = (await NTQQMsgApi.getMsgHistory({
chatType: friend ? ChatType.friend : ChatType.temp,
peerUid: uid
}, startMsgId, parseInt(payload.count?.toString()) || 20));
console.log(historyResult);
const msgList = historyResult.msgList;
await Promise.all(msgList.map(async msg => {
msg.id = await dbUtil.addMsg(msg);
}));
const ob11MsgList = await Promise.all(msgList.map(msg => OB11Constructor.message(msg)));
return { 'messages': ob11MsgList };
}
}

View File

@@ -34,7 +34,7 @@ import SetGroupAdmin from './group/SetGroupAdmin';
import SetGroupCard from './group/SetGroupCard';
import GetImage from './file/GetImage';
import GetRecord from './file/GetRecord';
import GoCQHTTPMarkMsgAsRead from './msg/MarkMsgAsRead';
import { MarkGroupMsgAsRead, MarkPrivateMsgAsRead } from './msg/MarkMsgAsRead';
import CleanCache from './system/CleanCache';
import GoCQHTTPUploadGroupFile from './go-cqhttp/UploadGroupFile';
import { GetConfigAction, SetConfigAction } from '@/onebot11/action/extends/Config';
@@ -86,7 +86,8 @@ export const actionHandlers = [
new GoCQHTTPGetStrangerInfo(),
new GoCQHTTPDownloadFile(),
new GetGuildList(),
new GoCQHTTPMarkMsgAsRead(),
new MarkGroupMsgAsRead(),
new MarkPrivateMsgAsRead(),
new GoCQHTTPUploadGroupFile(),
new GoCQHTTPGetGroupMsgHistory(),
new GoCQHTTGetForwardMsgAction(),

View File

@@ -1,14 +1,41 @@
import { ChatType, Peer, RawMessage, SendMessageElement } from '@/core/qqnt/entities';
import BaseAction from '../BaseAction';
import { ActionName } from '../types';
import { NTQQMsgApi } from '@/core/qqnt/apis';
import { getFriend, getUidByUin } from '@/common/data';
interface Payload{
message_id: number
interface Payload {
uin: string,
}
export default class GoCQHTTPMarkMsgAsRead extends BaseAction<Payload, null>{
actionName = ActionName.GoCQHTTP_MarkMsgAsRead;
class MarkMsgAsRead extends BaseAction<Payload, null> {
ReqChatType = 0;
protected async _handle(payload: Payload): Promise<null> {
let uid: string | undefined = payload.uin;
if (this.ReqChatType != ChatType.group) {
uid = getUidByUin(payload.uin.toString());
if (!uid) {
throw `记录${payload.uin}不存在`;
}
const friend = await getFriend(uid);
this.ReqChatType = friend ? ChatType.friend : ChatType.temp;//重写
}
// 获取UID 组装Peer
// GuildId: string 留空
const ReqPeer: Peer = { chatType: this.ReqChatType, peerUid: uid, guildId: '' };
// 调用API
const ret = await NTQQMsgApi.setMsgRead(ReqPeer);
if (ret.result != 0) {
throw ('设置已读失败');
}
return null;
}
}
export class MarkPrivateMsgAsRead extends MarkMsgAsRead {
actionName = ActionName.MarkPrivateMsgAsRead;
ReqChatType = ChatType.friend;
}
export class MarkGroupMsgAsRead extends MarkMsgAsRead {
actionName = ActionName.MarkGroupMsgAsRead;
ReqChatType = ChatType.group;
}

View File

@@ -56,7 +56,8 @@ export enum ActionName {
GoCQHTTP_SendPrivateForwardMsg = 'send_private_forward_msg',
GoCQHTTP_GetStrangerInfo = 'get_stranger_info',
GetGuildList = 'get_guild_list',
GoCQHTTP_MarkMsgAsRead = 'mark_msg_as_read',
MarkPrivateMsgAsRead = 'mark_private_msg_as_read',
MarkGroupMsgAsRead = 'mark_group_msg_as_read',
GoCQHTTP_UploadGroupFile = 'upload_group_file',
GoCQHTTP_DownloadFile = 'download_file',
GoCQHTTP_GetGroupMsgHistory = 'get_group_msg_history',

View File

@@ -67,6 +67,11 @@ class Config implements OB11Config {
Object.assign(this, jsonData);
// eslint-disable-next-line
} catch (e) {
if (e instanceof SyntaxError) {
console.error(`配置文件 ${ob11ConfigPath} 格式错误,请检查配置文件:`, e.message);
}else{
console.error(`读取配置文件 ${ob11ConfigPath} 时发生错误:`, e.message);
}
}
return this;
}

View File

@@ -1 +1 @@
export const version = '1.0.3';
export const version = '1.1.2';