mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
Compare commits
24 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
911841401a | ||
![]() |
4c6bd3df0b | ||
![]() |
c5932bcd98 | ||
![]() |
3abc9f2ae0 | ||
![]() |
e716c28e9a | ||
![]() |
9209ae766c | ||
![]() |
af8cf1882c | ||
![]() |
d93193c7fd | ||
![]() |
8a2245e2ec | ||
![]() |
1e144a1377 | ||
![]() |
8a44086419 | ||
![]() |
133719f96a | ||
![]() |
75c92a68bd | ||
![]() |
90820cf74d | ||
![]() |
f149594e23 | ||
![]() |
60e0c9e4ba | ||
![]() |
1a6739ffab | ||
![]() |
d8e31985af | ||
![]() |
c313fcd491 | ||
![]() |
f42727c8ad | ||
![]() |
17d9c48e68 | ||
![]() |
54179cb686 | ||
![]() |
c9a5ee69cf | ||
![]() |
e348103e84 |
@@ -6,7 +6,7 @@ const external = ["silk-wasm", "ws",
|
|||||||
"module-error", "catering", "node-gyp-build"];
|
"module-error", "catering", "node-gyp-build"];
|
||||||
|
|
||||||
function genCpModule(module: string) {
|
function genCpModule(module: string) {
|
||||||
return { src: `./node_modules/${module}`, dest: `dist/node_modules/${module}`, flatten: false }
|
return {src: `./node_modules/${module}`, dest: `dist/node_modules/${module}`, flatten: false}
|
||||||
}
|
}
|
||||||
|
|
||||||
let config = {
|
let config = {
|
||||||
@@ -16,20 +16,24 @@ let config = {
|
|||||||
emptyOutDir: true,
|
emptyOutDir: true,
|
||||||
lib: {
|
lib: {
|
||||||
formats: ["cjs"],
|
formats: ["cjs"],
|
||||||
entry: { "main": "src/main/main.ts" },
|
entry: {"main": "src/main/main.ts"},
|
||||||
},
|
},
|
||||||
rollupOptions: {
|
rollupOptions: {
|
||||||
external,
|
external,
|
||||||
input: "src/main/main.ts",
|
input: "src/main/main.ts",
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
resolve:{
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
'./lib-cov/fluent-ffmpeg': './lib/fluent-ffmpeg'
|
'./lib-cov/fluent-ffmpeg': './lib/fluent-ffmpeg'
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
plugins: [cp({ targets: [...external.map(genCpModule),
|
plugins: [cp({
|
||||||
{ src: './manifest.json', dest: 'dist' }, {src: './icon.jpg', dest: 'dist' }]
|
targets: [
|
||||||
|
...external.map(genCpModule),
|
||||||
|
{src: './manifest.json', dest: 'dist'}, {src: './icon.jpg', dest: 'dist'},
|
||||||
|
{src: './src/ntqqapi/external/ccpoke/poke-win32-x64.node', dest: 'dist/main/ccpoke/'},
|
||||||
|
]
|
||||||
})]
|
})]
|
||||||
},
|
},
|
||||||
preload: {
|
preload: {
|
||||||
@@ -39,15 +43,14 @@ let config = {
|
|||||||
emptyOutDir: true,
|
emptyOutDir: true,
|
||||||
lib: {
|
lib: {
|
||||||
formats: ["cjs"],
|
formats: ["cjs"],
|
||||||
entry: { "preload": "src/preload.ts" },
|
entry: {"preload": "src/preload.ts"},
|
||||||
},
|
},
|
||||||
rollupOptions: {
|
rollupOptions: {
|
||||||
// external: externalAll,
|
// external: externalAll,
|
||||||
input: "src/preload.ts",
|
input: "src/preload.ts",
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
resolve:{
|
resolve: {}
|
||||||
}
|
|
||||||
},
|
},
|
||||||
renderer: {
|
renderer: {
|
||||||
// vite config options
|
// vite config options
|
||||||
@@ -56,15 +59,14 @@ let config = {
|
|||||||
emptyOutDir: true,
|
emptyOutDir: true,
|
||||||
lib: {
|
lib: {
|
||||||
formats: ["es"],
|
formats: ["es"],
|
||||||
entry: { "renderer": "src/renderer/index.ts" },
|
entry: {"renderer": "src/renderer/index.ts"},
|
||||||
},
|
},
|
||||||
rollupOptions: {
|
rollupOptions: {
|
||||||
// external: externalAll,
|
// external: externalAll,
|
||||||
input: "src/renderer/index.ts",
|
input: "src/renderer/index.ts",
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
resolve:{
|
resolve: {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"manifest_version": 4,
|
"manifest_version": 4,
|
||||||
"type": "extension",
|
"type": "extension",
|
||||||
"name": "LLOneBot v3.15.0",
|
"name": "LLOneBot v3.16.1",
|
||||||
"slug": "LLOneBot",
|
"slug": "LLOneBot",
|
||||||
"description": "LiteLoaderQQNT的OneBotApi,不支持商店在线更新",
|
"description": "LiteLoaderQQNT的OneBotApi,不支持商店在线更新",
|
||||||
"version": "3.15.0",
|
"version": "3.16.1",
|
||||||
"icon": "./icon.jpg",
|
"icon": "./icon.jpg",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
|
13
package-lock.json
generated
13
package-lock.json
generated
@@ -13,6 +13,7 @@
|
|||||||
"file-type": "^19.0.0",
|
"file-type": "^19.0.0",
|
||||||
"fluent-ffmpeg": "^2.1.2",
|
"fluent-ffmpeg": "^2.1.2",
|
||||||
"level": "^8.0.1",
|
"level": "^8.0.1",
|
||||||
|
"node-stream-zip": "^1.15.0",
|
||||||
"silk-wasm": "^3.2.3",
|
"silk-wasm": "^3.2.3",
|
||||||
"utf-8-validate": "^6.0.3",
|
"utf-8-validate": "^6.0.3",
|
||||||
"uuid": "^9.0.1",
|
"uuid": "^9.0.1",
|
||||||
@@ -4930,6 +4931,18 @@
|
|||||||
"integrity": "sha512-y10wOWt8yZpqXmOgRo77WaHEmhYQYGNA6y421PKsKYWEK8aW+cqAphborZDhqfyKrbZEN92CN1X2KbafY2s7Yw==",
|
"integrity": "sha512-y10wOWt8yZpqXmOgRo77WaHEmhYQYGNA6y421PKsKYWEK8aW+cqAphborZDhqfyKrbZEN92CN1X2KbafY2s7Yw==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"node_modules/node-stream-zip": {
|
||||||
|
"version": "1.15.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/node-stream-zip/-/node-stream-zip-1.15.0.tgz",
|
||||||
|
"integrity": "sha512-LN4fydt9TqhZhThkZIVQnF9cwjU3qmUH9h78Mx/K7d3VvfRqqwthLwJEUOEL0QPZ0XQmNN7be5Ggit5+4dq3Bw==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.12.0"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"type": "github",
|
||||||
|
"url": "https://github.com/sponsors/antelle"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/normalize-url": {
|
"node_modules/normalize-url": {
|
||||||
"version": "6.1.0",
|
"version": "6.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-6.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-6.1.0.tgz",
|
||||||
|
@@ -18,6 +18,7 @@
|
|||||||
"file-type": "^19.0.0",
|
"file-type": "^19.0.0",
|
||||||
"fluent-ffmpeg": "^2.1.2",
|
"fluent-ffmpeg": "^2.1.2",
|
||||||
"level": "^8.0.1",
|
"level": "^8.0.1",
|
||||||
|
"node-stream-zip": "^1.15.0",
|
||||||
"silk-wasm": "^3.2.3",
|
"silk-wasm": "^3.2.3",
|
||||||
"utf-8-validate": "^6.0.3",
|
"utf-8-validate": "^6.0.3",
|
||||||
"uuid": "^9.0.1",
|
"uuid": "^9.0.1",
|
||||||
|
@@ -2,4 +2,6 @@ export const CHANNEL_GET_CONFIG = 'llonebot_get_config'
|
|||||||
export const CHANNEL_SET_CONFIG = 'llonebot_set_config'
|
export const CHANNEL_SET_CONFIG = 'llonebot_set_config'
|
||||||
export const CHANNEL_LOG = 'llonebot_log'
|
export const CHANNEL_LOG = 'llonebot_log'
|
||||||
export const CHANNEL_ERROR = 'llonebot_error'
|
export const CHANNEL_ERROR = 'llonebot_error'
|
||||||
|
export const CHANNEL_UPDATE = 'llonebot_update'
|
||||||
|
export const CHANNEL_CHECKVERSION = 'llonebot_checkversion'
|
||||||
export const CHANNEL_SELECT_FILE = 'llonebot_select_ffmpeg'
|
export const CHANNEL_SELECT_FILE = 'llonebot_select_ffmpeg'
|
||||||
|
@@ -1,6 +1,10 @@
|
|||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import {Config, OB11Config} from './types';
|
import {Config, OB11Config} from './types';
|
||||||
import {mergeNewProperties} from "./utils";
|
|
||||||
|
import {mergeNewProperties} from "./utils/helper";
|
||||||
|
import path from "node:path";
|
||||||
|
import {selfInfo} from "./data";
|
||||||
|
import {DATA_DIR} from "./utils";
|
||||||
|
|
||||||
export const HOOK_LOG = false;
|
export const HOOK_LOG = false;
|
||||||
|
|
||||||
@@ -44,6 +48,7 @@ export class ConfigUtil {
|
|||||||
reportSelfMessage: false,
|
reportSelfMessage: false,
|
||||||
autoDeleteFile: false,
|
autoDeleteFile: false,
|
||||||
autoDeleteFileSecond: 60,
|
autoDeleteFileSecond: 60,
|
||||||
|
enablePoke: false
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!fs.existsSync(this.configPath)) {
|
if (!fs.existsSync(this.configPath)) {
|
||||||
@@ -84,3 +89,8 @@ export class ConfigUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getConfigUtil() {
|
||||||
|
const configFilePath = path.join(DATA_DIR, `config_${selfInfo.uin}.json`)
|
||||||
|
return new ConfigUtil(configFilePath)
|
||||||
|
}
|
@@ -1,17 +1,14 @@
|
|||||||
import {NTQQApi} from '../ntqqapi/ntcall'
|
|
||||||
import {
|
import {
|
||||||
type Friend,
|
type Friend,
|
||||||
type FriendRequest,
|
type FriendRequest,
|
||||||
type Group,
|
type Group,
|
||||||
type GroupMember,
|
type GroupMember,
|
||||||
type GroupNotify,
|
|
||||||
type RawMessage,
|
|
||||||
type SelfInfo
|
type SelfInfo
|
||||||
} from '../ntqqapi/types'
|
} from '../ntqqapi/types'
|
||||||
import {type FileCache, type LLOneBotError} from './types'
|
import {type FileCache, type LLOneBotError} from './types'
|
||||||
import {dbUtil} from "./db";
|
import {NTQQGroupApi} from "../ntqqapi/api/group";
|
||||||
import {raw} from "express";
|
import {log} from "./utils/log";
|
||||||
import {isNumeric, log} from "./utils";
|
import {isNumeric} from "./utils/helper";
|
||||||
|
|
||||||
export const selfInfo: SelfInfo = {
|
export const selfInfo: SelfInfo = {
|
||||||
uid: '',
|
uid: '',
|
||||||
@@ -47,7 +44,7 @@ export async function getGroup(qq: string): Promise<Group | undefined> {
|
|||||||
let group = groups.find(group => group.groupCode === qq.toString())
|
let group = groups.find(group => group.groupCode === qq.toString())
|
||||||
if (!group) {
|
if (!group) {
|
||||||
try {
|
try {
|
||||||
const _groups = await NTQQApi.getGroups(true);
|
const _groups = await NTQQGroupApi.getGroups(true);
|
||||||
group = _groups.find(group => group.groupCode === qq.toString())
|
group = _groups.find(group => group.groupCode === qq.toString())
|
||||||
if (group) {
|
if (group) {
|
||||||
groups.push(group)
|
groups.push(group)
|
||||||
@@ -70,7 +67,7 @@ export async function getGroupMember(groupQQ: string | number, memberUinOrUid: s
|
|||||||
let member = group.members?.find(filterFunc)
|
let member = group.members?.find(filterFunc)
|
||||||
if (!member) {
|
if (!member) {
|
||||||
try {
|
try {
|
||||||
const _members = await NTQQApi.getGroupMembers(groupQQ)
|
const _members = await NTQQGroupApi.getGroupMembers(groupQQ)
|
||||||
if (_members.length > 0) {
|
if (_members.length > 0) {
|
||||||
group.members = _members
|
group.members = _members
|
||||||
}
|
}
|
||||||
@@ -88,7 +85,7 @@ export async function getGroupMember(groupQQ: string | number, memberUinOrUid: s
|
|||||||
export async function refreshGroupMembers(groupQQ: string) {
|
export async function refreshGroupMembers(groupQQ: string) {
|
||||||
const group = groups.find(group => group.groupCode === groupQQ)
|
const group = groups.find(group => group.groupCode === groupQQ)
|
||||||
if (group) {
|
if (group) {
|
||||||
group.members = await NTQQApi.getGroupMembers(groupQQ)
|
group.members = await NTQQGroupApi.getGroupMembers(groupQQ)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,9 +1,11 @@
|
|||||||
import {Level} from "level";
|
import {Level} from "level";
|
||||||
import {type GroupNotify, RawMessage} from "../ntqqapi/types";
|
import {type GroupNotify, RawMessage} from "../ntqqapi/types";
|
||||||
import {DATA_DIR, log} from "./utils";
|
import {DATA_DIR} from "./utils";
|
||||||
import {selfInfo} from "./data";
|
import {selfInfo} from "./data";
|
||||||
import {FileCache} from "./types";
|
import {FileCache} from "./types";
|
||||||
|
import {log} from "./utils/log";
|
||||||
|
|
||||||
|
type ReceiveTempUinMap = Record<string, string>;
|
||||||
|
|
||||||
class DBUtil {
|
class DBUtil {
|
||||||
public readonly DB_KEY_PREFIX_MSG_ID = "msg_id_";
|
public readonly DB_KEY_PREFIX_MSG_ID = "msg_id_";
|
||||||
@@ -11,8 +13,9 @@ class DBUtil {
|
|||||||
public readonly DB_KEY_PREFIX_MSG_SEQ_ID = "msg_seq_id_";
|
public readonly DB_KEY_PREFIX_MSG_SEQ_ID = "msg_seq_id_";
|
||||||
public readonly DB_KEY_PREFIX_FILE = "file_";
|
public readonly DB_KEY_PREFIX_FILE = "file_";
|
||||||
public readonly DB_KEY_PREFIX_GROUP_NOTIFY = "group_notify_";
|
public readonly DB_KEY_PREFIX_GROUP_NOTIFY = "group_notify_";
|
||||||
|
private readonly DB_KEY_RECEIVED_TEMP_UIN_MAP = "received_temp_uin_map";
|
||||||
public db: Level;
|
public db: Level;
|
||||||
public cache: Record<string, RawMessage | string | FileCache | GroupNotify> = {} // <msg_id_ | msg_short_id_ | msg_seq_id_><id>: RawMessage
|
public cache: Record<string, RawMessage | string | FileCache | GroupNotify | ReceiveTempUinMap> = {} // <msg_id_ | msg_short_id_ | msg_seq_id_><id>: RawMessage
|
||||||
private currentShortId: number;
|
private currentShortId: number;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -67,6 +70,17 @@ class DBUtil {
|
|||||||
}, expiredMilliSecond)
|
}, expiredMilliSecond)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async getReceivedTempUinMap(): Promise<ReceiveTempUinMap> {
|
||||||
|
try{
|
||||||
|
this.cache[this.DB_KEY_RECEIVED_TEMP_UIN_MAP] = JSON.parse(await this.db.get(this.DB_KEY_RECEIVED_TEMP_UIN_MAP));
|
||||||
|
}catch (e) {
|
||||||
|
}
|
||||||
|
return (this.cache[this.DB_KEY_RECEIVED_TEMP_UIN_MAP] || {}) as ReceiveTempUinMap;
|
||||||
|
}
|
||||||
|
public setReceivedTempUinMap(data: ReceiveTempUinMap) {
|
||||||
|
this.cache[this.DB_KEY_RECEIVED_TEMP_UIN_MAP] = data;
|
||||||
|
this.db.put(this.DB_KEY_RECEIVED_TEMP_UIN_MAP, JSON.stringify(data)).then();
|
||||||
|
}
|
||||||
private addCache(msg: RawMessage) {
|
private addCache(msg: RawMessage) {
|
||||||
const longIdKey = this.DB_KEY_PREFIX_MSG_ID + msg.msgId
|
const longIdKey = this.DB_KEY_PREFIX_MSG_ID + msg.msgId
|
||||||
const shortIdKey = this.DB_KEY_PREFIX_MSG_SHORT_ID + msg.msgShortId
|
const shortIdKey = this.DB_KEY_PREFIX_MSG_SHORT_ID + msg.msgShortId
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
import express, {Express, json, Request, Response} from "express";
|
import express, {Express, json, Request, Response} from "express";
|
||||||
import {getConfigUtil, log} from "../utils";
|
|
||||||
import http from "http";
|
import http from "http";
|
||||||
|
import {log} from "../utils/log";
|
||||||
|
import {getConfigUtil} from "../config";
|
||||||
|
|
||||||
type RegisterHandler = (res: Response, payload: any) => Promise<any>
|
type RegisterHandler = (res: Response, payload: any) => Promise<any>
|
||||||
|
|
||||||
|
@@ -1,7 +1,8 @@
|
|||||||
import {WebSocket, WebSocketServer} from "ws";
|
import {WebSocket, WebSocketServer} from "ws";
|
||||||
import {getConfigUtil, log} from "../utils";
|
|
||||||
import urlParse from "url";
|
import urlParse from "url";
|
||||||
import {IncomingMessage} from "node:http";
|
import {IncomingMessage} from "node:http";
|
||||||
|
import {log} from "../utils/log";
|
||||||
|
import {getConfigUtil} from "../config";
|
||||||
|
|
||||||
class WebsocketClientBase {
|
class WebsocketClientBase {
|
||||||
private wsClient: WebSocket
|
private wsClient: WebSocket
|
||||||
|
@@ -9,7 +9,10 @@ export interface OB11Config {
|
|||||||
enableWsReverse?: boolean
|
enableWsReverse?: boolean
|
||||||
messagePostFormat?: 'array' | 'string'
|
messagePostFormat?: 'array' | 'string'
|
||||||
}
|
}
|
||||||
|
export interface CheckVersion {
|
||||||
|
result: boolean,
|
||||||
|
version: string
|
||||||
|
}
|
||||||
export interface Config {
|
export interface Config {
|
||||||
ob11: OB11Config
|
ob11: OB11Config
|
||||||
token?: string
|
token?: string
|
||||||
@@ -21,6 +24,7 @@ export interface Config {
|
|||||||
autoDeleteFile?: boolean
|
autoDeleteFile?: boolean
|
||||||
autoDeleteFileSecond?: number
|
autoDeleteFileSecond?: number
|
||||||
ffmpeg?: string // ffmpeg路径
|
ffmpeg?: string // ffmpeg路径
|
||||||
|
enablePoke?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface LLOneBotError {
|
export interface LLOneBotError {
|
||||||
|
@@ -1,70 +1,13 @@
|
|||||||
import * as path from "node:path";
|
import fs from "fs";
|
||||||
import {selfInfo} from "./data";
|
import crypto from "crypto";
|
||||||
import {ConfigUtil} from "./config";
|
import ffmpeg from "fluent-ffmpeg";
|
||||||
import util from "util";
|
import util from "util";
|
||||||
import {encode, getDuration, isWav} from "silk-wasm";
|
import {encode, getDuration, isWav} from "silk-wasm";
|
||||||
import fs from 'fs';
|
import path from "node:path";
|
||||||
import * as crypto from 'crypto';
|
|
||||||
import {v4 as uuidv4} from "uuid";
|
import {v4 as uuidv4} from "uuid";
|
||||||
import ffmpeg from "fluent-ffmpeg"
|
import {DATA_DIR} from "./index";
|
||||||
|
import {log} from "./log";
|
||||||
export const DATA_DIR = global.LiteLoader.plugins["LLOneBot"].path.data;
|
import {getConfigUtil} from "../config";
|
||||||
|
|
||||||
export function getConfigUtil() {
|
|
||||||
const configFilePath = path.join(DATA_DIR, `config_${selfInfo.uin}.json`)
|
|
||||||
return new ConfigUtil(configFilePath)
|
|
||||||
}
|
|
||||||
|
|
||||||
function truncateString(obj: any, maxLength = 500) {
|
|
||||||
if (obj !== null && typeof obj === 'object') {
|
|
||||||
Object.keys(obj).forEach(key => {
|
|
||||||
if (typeof obj[key] === 'string') {
|
|
||||||
// 如果是字符串且超过指定长度,则截断
|
|
||||||
if (obj[key].length > maxLength) {
|
|
||||||
obj[key] = obj[key].substring(0, maxLength) + '...';
|
|
||||||
}
|
|
||||||
} else if (typeof obj[key] === 'object') {
|
|
||||||
// 如果是对象或数组,则递归调用
|
|
||||||
truncateString(obj[key], maxLength);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function isNumeric(str: string) {
|
|
||||||
return /^\d+$/.test(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export function log(...msg: any[]) {
|
|
||||||
if (!getConfigUtil().getConfig().log) {
|
|
||||||
return //console.log(...msg);
|
|
||||||
}
|
|
||||||
let currentDateTime = new Date().toLocaleString();
|
|
||||||
const date = new Date();
|
|
||||||
const year = date.getFullYear();
|
|
||||||
const month = date.getMonth() + 1;
|
|
||||||
const day = date.getDate();
|
|
||||||
const currentDate = `${year}-${month}-${day}`;
|
|
||||||
const userInfo = selfInfo.uin ? `${selfInfo.nick}(${selfInfo.uin})` : ""
|
|
||||||
let logMsg = "";
|
|
||||||
for (let msgItem of msg) {
|
|
||||||
// 判断是否是对象
|
|
||||||
if (typeof msgItem === "object") {
|
|
||||||
let obj = JSON.parse(JSON.stringify(msgItem));
|
|
||||||
logMsg += JSON.stringify(truncateString(obj)) + " ";
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
logMsg += msgItem + " ";
|
|
||||||
}
|
|
||||||
logMsg = `${currentDateTime} ${userInfo}: ${logMsg}\n\n`
|
|
||||||
// sendLog(...msg);
|
|
||||||
// console.log(msg)
|
|
||||||
fs.appendFile(path.join(DATA_DIR, `llonebot-${currentDate}.log`), logMsg, (err: any) => {
|
|
||||||
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
export function isGIF(path: string) {
|
export function isGIF(path: string) {
|
||||||
const buffer = Buffer.alloc(4);
|
const buffer = Buffer.alloc(4);
|
||||||
@@ -74,11 +17,6 @@ export function isGIF(path: string) {
|
|||||||
return buffer.toString() === 'GIF8'
|
return buffer.toString() === 'GIF8'
|
||||||
}
|
}
|
||||||
|
|
||||||
export function sleep(ms: number): Promise<void> {
|
|
||||||
return new Promise(resolve => setTimeout(resolve, ms));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// 定义一个异步函数来检查文件是否存在
|
// 定义一个异步函数来检查文件是否存在
|
||||||
export function checkFileReceived(path: string, timeout: number = 3000): Promise<void> {
|
export function checkFileReceived(path: string, timeout: number = 3000): Promise<void> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@@ -124,25 +62,6 @@ export async function file2base64(path: string) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 在保证老对象已有的属性不变化的情况下将新对象的属性复制到老对象
|
|
||||||
export function mergeNewProperties(newObj: any, oldObj: any) {
|
|
||||||
Object.keys(newObj).forEach(key => {
|
|
||||||
// 如果老对象不存在当前属性,则直接复制
|
|
||||||
if (!oldObj.hasOwnProperty(key)) {
|
|
||||||
oldObj[key] = newObj[key];
|
|
||||||
} else {
|
|
||||||
// 如果老对象和新对象的当前属性都是对象,则递归合并
|
|
||||||
if (typeof oldObj[key] === 'object' && typeof newObj[key] === 'object') {
|
|
||||||
mergeNewProperties(newObj[key], oldObj[key]);
|
|
||||||
} else if (typeof oldObj[key] === 'object' || typeof newObj[key] === 'object') {
|
|
||||||
// 属性冲突,有一方不是对象,直接覆盖
|
|
||||||
oldObj[key] = newObj[key];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function checkFfmpeg(newPath: string = null): Promise<boolean> {
|
export function checkFfmpeg(newPath: string = null): Promise<boolean> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (newPath) {
|
if (newPath) {
|
||||||
@@ -230,7 +149,8 @@ export async function encodeSilk(filePath: string) {
|
|||||||
const pcm = fs.readFileSync(filePath);
|
const pcm = fs.readFileSync(filePath);
|
||||||
const silk = await encode(pcm, 0);
|
const silk = await encode(pcm, 0);
|
||||||
fs.writeFileSync(pttPath, silk.data);
|
fs.writeFileSync(pttPath, silk.data);
|
||||||
fs.unlink(wavPath, (err) => { });
|
fs.unlink(wavPath, (err) => {
|
||||||
|
});
|
||||||
log(`语音文件${filePath}转换成功!`, pttPath)
|
log(`语音文件${filePath}转换成功!`, pttPath)
|
||||||
return {
|
return {
|
||||||
converted: true,
|
converted: true,
|
||||||
@@ -264,8 +184,15 @@ export async function encodeSilk(filePath: string) {
|
|||||||
|
|
||||||
export async function getVideoInfo(filePath: string) {
|
export async function getVideoInfo(filePath: string) {
|
||||||
const size = fs.statSync(filePath).size;
|
const size = fs.statSync(filePath).size;
|
||||||
return new Promise<{ width: number, height: number, time: number, format: string, size: number, filePath: string }>((resolve, reject) => {
|
return new Promise<{
|
||||||
ffmpeg(filePath).ffprobe( (err, metadata) => {
|
width: number,
|
||||||
|
height: number,
|
||||||
|
time: number,
|
||||||
|
format: string,
|
||||||
|
size: number,
|
||||||
|
filePath: string
|
||||||
|
}>((resolve, reject) => {
|
||||||
|
ffmpeg(filePath).ffprobe((err, metadata) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
} else {
|
} else {
|
||||||
@@ -287,7 +214,6 @@ export async function getVideoInfo(filePath: string) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export async function encodeMp4(filePath: string) {
|
export async function encodeMp4(filePath: string) {
|
||||||
let videoInfo = await getVideoInfo(filePath);
|
let videoInfo = await getVideoInfo(filePath);
|
||||||
log("视频信息", videoInfo)
|
log("视频信息", videoInfo)
|
||||||
@@ -312,11 +238,6 @@ export async function encodeMp4(filePath: string) {
|
|||||||
return videoInfo
|
return videoInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isNull(value: any) {
|
|
||||||
return value === undefined || value === null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export function calculateFileMD5(filePath: string): Promise<string> {
|
export function calculateFileMD5(filePath: string): Promise<string> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// 创建一个流式读取器
|
// 创建一个流式读取器
|
||||||
@@ -339,4 +260,4 @@ export function calculateFileMD5(filePath: string): Promise<string> {
|
|||||||
reject(err);
|
reject(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
46
src/common/utils/helper.ts
Normal file
46
src/common/utils/helper.ts
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
export function truncateString(obj: any, maxLength = 500) {
|
||||||
|
if (obj !== null && typeof obj === 'object') {
|
||||||
|
Object.keys(obj).forEach(key => {
|
||||||
|
if (typeof obj[key] === 'string') {
|
||||||
|
// 如果是字符串且超过指定长度,则截断
|
||||||
|
if (obj[key].length > maxLength) {
|
||||||
|
obj[key] = obj[key].substring(0, maxLength) + '...';
|
||||||
|
}
|
||||||
|
} else if (typeof obj[key] === 'object') {
|
||||||
|
// 如果是对象或数组,则递归调用
|
||||||
|
truncateString(obj[key], maxLength);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isNumeric(str: string) {
|
||||||
|
return /^\d+$/.test(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function sleep(ms: number): Promise<void> {
|
||||||
|
return new Promise(resolve => setTimeout(resolve, ms));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 在保证老对象已有的属性不变化的情况下将新对象的属性复制到老对象
|
||||||
|
export function mergeNewProperties(newObj: any, oldObj: any) {
|
||||||
|
Object.keys(newObj).forEach(key => {
|
||||||
|
// 如果老对象不存在当前属性,则直接复制
|
||||||
|
if (!oldObj.hasOwnProperty(key)) {
|
||||||
|
oldObj[key] = newObj[key];
|
||||||
|
} else {
|
||||||
|
// 如果老对象和新对象的当前属性都是对象,则递归合并
|
||||||
|
if (typeof oldObj[key] === 'object' && typeof newObj[key] === 'object') {
|
||||||
|
mergeNewProperties(newObj[key], oldObj[key]);
|
||||||
|
} else if (typeof oldObj[key] === 'object' || typeof newObj[key] === 'object') {
|
||||||
|
// 属性冲突,有一方不是对象,直接覆盖
|
||||||
|
oldObj[key] = newObj[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isNull(value: any) {
|
||||||
|
return value === undefined || value === null;
|
||||||
|
}
|
10
src/common/utils/index.ts
Normal file
10
src/common/utils/index.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
export * from './file'
|
||||||
|
export * from './helper'
|
||||||
|
export * from './log'
|
||||||
|
export * from './qqlevel'
|
||||||
|
export * from './qqpkg'
|
||||||
|
export * from './update'
|
||||||
|
export const DATA_DIR = global.LiteLoader.plugins["LLOneBot"].path.data;
|
||||||
|
|
||||||
|
|
||||||
|
|
34
src/common/utils/log.ts
Normal file
34
src/common/utils/log.ts
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import {selfInfo} from "../data";
|
||||||
|
import fs from "fs";
|
||||||
|
import path from "node:path";
|
||||||
|
import {DATA_DIR, truncateString} from "./index";
|
||||||
|
import {getConfigUtil} from "../config";
|
||||||
|
|
||||||
|
export function log(...msg: any[]) {
|
||||||
|
if (!getConfigUtil().getConfig().log) {
|
||||||
|
return //console.log(...msg);
|
||||||
|
}
|
||||||
|
let currentDateTime = new Date().toLocaleString();
|
||||||
|
const date = new Date();
|
||||||
|
const year = date.getFullYear();
|
||||||
|
const month = date.getMonth() + 1;
|
||||||
|
const day = date.getDate();
|
||||||
|
const currentDate = `${year}-${month}-${day}`;
|
||||||
|
const userInfo = selfInfo.uin ? `${selfInfo.nick}(${selfInfo.uin})` : ""
|
||||||
|
let logMsg = "";
|
||||||
|
for (let msgItem of msg) {
|
||||||
|
// 判断是否是对象
|
||||||
|
if (typeof msgItem === "object") {
|
||||||
|
let obj = JSON.parse(JSON.stringify(msgItem));
|
||||||
|
logMsg += JSON.stringify(truncateString(obj)) + " ";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
logMsg += msgItem + " ";
|
||||||
|
}
|
||||||
|
logMsg = `${currentDateTime} ${userInfo}: ${logMsg}\n\n`
|
||||||
|
// sendLog(...msg);
|
||||||
|
// console.log(msg)
|
||||||
|
fs.appendFile(path.join(DATA_DIR, `llonebot-${currentDate}.log`), logMsg, (err: any) => {
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
7
src/common/utils/qqlevel.ts
Normal file
7
src/common/utils/qqlevel.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
// QQ等级换算
|
||||||
|
import {QQLevel} from "../../ntqqapi/types";
|
||||||
|
|
||||||
|
export function calcQQLevel(level: QQLevel) {
|
||||||
|
const {crownNum, sunNum, moonNum, starNum} = level
|
||||||
|
return crownNum * 64 + sunNum * 16 + moonNum * 4 + starNum
|
||||||
|
}
|
10
src/common/utils/qqpkg.ts
Normal file
10
src/common/utils/qqpkg.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import path from "path";
|
||||||
|
|
||||||
|
type QQPkgInfo = {
|
||||||
|
version: string;
|
||||||
|
buildVersion: string;
|
||||||
|
platform: string;
|
||||||
|
eleArch: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const qqPkgInfo: QQPkgInfo = require(path.join(process.resourcesPath, "app/package.json"))
|
62
src/common/utils/update.ts
Normal file
62
src/common/utils/update.ts
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
import {version} from "../../version";
|
||||||
|
import https from "node:https";
|
||||||
|
|
||||||
|
export async function checkVersion() {
|
||||||
|
const latestVersionText = await getRemoteVersion();
|
||||||
|
const latestVersion = latestVersionText.split(".");
|
||||||
|
const currentVersion = version.split(".");
|
||||||
|
for (let k in [0, 1, 2]) {
|
||||||
|
if (latestVersion[k] > currentVersion[k]) {
|
||||||
|
return { result: false, version: latestVersionText };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return { result: true, version: version };
|
||||||
|
}
|
||||||
|
export async function updateLLOneBot() {
|
||||||
|
let mirrorGithubList = ["https://mirror.ghproxy.com"];
|
||||||
|
const latestVersion = await getRemoteVersion();
|
||||||
|
if (latestVersion && latestVersion != "") {
|
||||||
|
const downloadUrl = "https://github.com/LLOneBot/LLOneBot/releases/download/v" + latestVersion + "/LLOneBot.zip";
|
||||||
|
const realUrl = mirrorGithubList[0] + downloadUrl;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
export async function getRemoteVersion() {
|
||||||
|
let mirrorGithubList = ["https://521github.com"];
|
||||||
|
let Version = "";
|
||||||
|
for (let i = 0; i < mirrorGithubList.length; i++) {
|
||||||
|
let mirrorGithub = mirrorGithubList[i];
|
||||||
|
let tVersion = await getRemoteVersionByMirror(mirrorGithub);
|
||||||
|
if (tVersion && tVersion != "") {
|
||||||
|
Version = tVersion;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Version;
|
||||||
|
}
|
||||||
|
export async function getRemoteVersionByMirror(mirrorGithub: string) {
|
||||||
|
let releasePage = "error";
|
||||||
|
let reqPromise = async function (): Promise<string> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
https.get(mirrorGithub + "/LLOneBot/LLOneBot/releases", res => {
|
||||||
|
let list = [];
|
||||||
|
res.on('data', chunk => {
|
||||||
|
list.push(chunk);
|
||||||
|
});
|
||||||
|
res.on('end', () => {
|
||||||
|
resolve(Buffer.concat(list).toString());
|
||||||
|
});
|
||||||
|
}).on('error', err => {
|
||||||
|
reject();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
releasePage = await reqPromise();
|
||||||
|
if (releasePage === "error") return "";
|
||||||
|
return releasePage.match(new RegExp('(?<=(tag/v)).*?(?=("))'))[0];
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
return "";
|
||||||
|
|
||||||
|
}
|
@@ -7,11 +7,13 @@ import {
|
|||||||
CHANNEL_ERROR,
|
CHANNEL_ERROR,
|
||||||
CHANNEL_GET_CONFIG,
|
CHANNEL_GET_CONFIG,
|
||||||
CHANNEL_LOG,
|
CHANNEL_LOG,
|
||||||
|
CHANNEL_CHECKVERSION,
|
||||||
CHANNEL_SELECT_FILE,
|
CHANNEL_SELECT_FILE,
|
||||||
CHANNEL_SET_CONFIG,
|
CHANNEL_SET_CONFIG,
|
||||||
|
CHANNEL_UPDATE,
|
||||||
} from "../common/channels";
|
} from "../common/channels";
|
||||||
import {ob11WebsocketServer} from "../onebot11/server/ws/WebsocketServer";
|
import {ob11WebsocketServer} from "../onebot11/server/ws/WebsocketServer";
|
||||||
import {checkFfmpeg, DATA_DIR, getConfigUtil, log} from "../common/utils";
|
import {DATA_DIR} from "../common/utils";
|
||||||
import {
|
import {
|
||||||
friendRequests,
|
friendRequests,
|
||||||
getFriend,
|
getFriend,
|
||||||
@@ -19,11 +21,10 @@ import {
|
|||||||
getGroupMember,
|
getGroupMember,
|
||||||
llonebotError,
|
llonebotError,
|
||||||
refreshGroupMembers,
|
refreshGroupMembers,
|
||||||
selfInfo
|
selfInfo, uidMaps
|
||||||
} from "../common/data";
|
} from "../common/data";
|
||||||
import {hookNTQQApiCall, hookNTQQApiReceive, ReceiveCmd, registerReceiveHook} from "../ntqqapi/hook";
|
import {hookNTQQApiCall, hookNTQQApiReceive, ReceiveCmdS, registerReceiveHook} from "../ntqqapi/hook";
|
||||||
import {OB11Constructor} from "../onebot11/constructor";
|
import {OB11Constructor} from "../onebot11/constructor";
|
||||||
import {NTQQApi} from "../ntqqapi/ntcall";
|
|
||||||
import {ChatType, FriendRequestNotify, GroupNotifies, GroupNotifyTypes, RawMessage} from "../ntqqapi/types";
|
import {ChatType, FriendRequestNotify, GroupNotifies, GroupNotifyTypes, RawMessage} from "../ntqqapi/types";
|
||||||
import {ob11HTTPServer} from "../onebot11/server/http";
|
import {ob11HTTPServer} from "../onebot11/server/http";
|
||||||
import {OB11FriendRecallNoticeEvent} from "../onebot11/event/notice/OB11FriendRecallNoticeEvent";
|
import {OB11FriendRecallNoticeEvent} from "../onebot11/event/notice/OB11FriendRecallNoticeEvent";
|
||||||
@@ -36,6 +37,14 @@ import {OB11FriendRequestEvent} from "../onebot11/event/request/OB11FriendReques
|
|||||||
import * as path from "node:path";
|
import * as path from "node:path";
|
||||||
import {dbUtil} from "../common/db";
|
import {dbUtil} from "../common/db";
|
||||||
import {setConfig} from "./setConfig";
|
import {setConfig} from "./setConfig";
|
||||||
|
import {NTQQUserApi} from "../ntqqapi/api/user";
|
||||||
|
import {NTQQGroupApi} from "../ntqqapi/api/group";
|
||||||
|
import {registerPokeHandler} from "../ntqqapi/external/ccpoke";
|
||||||
|
import {OB11FriendPokeEvent, OB11GroupPokeEvent} from "../onebot11/event/notice/OB11PokeEvent";
|
||||||
|
import {checkVersion, updateLLOneBot} from "../common/utils/update";
|
||||||
|
import {checkFfmpeg} from "../common/utils/file";
|
||||||
|
import {log} from "../common/utils/log";
|
||||||
|
import {getConfigUtil} from "../common/config";
|
||||||
|
|
||||||
|
|
||||||
let running = false;
|
let running = false;
|
||||||
@@ -44,7 +53,12 @@ let running = false;
|
|||||||
// 加载插件时触发
|
// 加载插件时触发
|
||||||
function onLoad() {
|
function onLoad() {
|
||||||
log("llonebot main onLoad");
|
log("llonebot main onLoad");
|
||||||
|
ipcMain.handle(CHANNEL_CHECKVERSION, async (event, arg) => {
|
||||||
|
return checkVersion();
|
||||||
|
});
|
||||||
|
ipcMain.handle(CHANNEL_UPDATE, async (event, arg) => {
|
||||||
|
return updateLLOneBot();
|
||||||
|
});
|
||||||
ipcMain.handle(CHANNEL_SELECT_FILE, async (event, arg) => {
|
ipcMain.handle(CHANNEL_SELECT_FILE, async (event, arg) => {
|
||||||
const selectPath = new Promise<string>((resolve, reject) => {
|
const selectPath = new Promise<string>((resolve, reject) => {
|
||||||
dialog
|
dialog
|
||||||
@@ -105,11 +119,18 @@ function onLoad() {
|
|||||||
OB11Constructor.message(message).then((msg) => {
|
OB11Constructor.message(message).then((msg) => {
|
||||||
if (debug) {
|
if (debug) {
|
||||||
msg.raw = message;
|
msg.raw = message;
|
||||||
|
} else {
|
||||||
|
if (msg.message.length === 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const isSelfMsg = msg.user_id.toString() == selfInfo.uin
|
const isSelfMsg = msg.user_id.toString() == selfInfo.uin
|
||||||
if (isSelfMsg && !reportSelfMessage) {
|
if (isSelfMsg && !reportSelfMessage) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (isSelfMsg) {
|
||||||
|
msg.target_id = parseInt(message.peerUin);
|
||||||
|
}
|
||||||
postOB11Event(msg);
|
postOB11Event(msg);
|
||||||
// log("post msg", msg)
|
// log("post msg", msg)
|
||||||
}).catch(e => log("constructMessage error: ", e.stack.toString()));
|
}).catch(e => log("constructMessage error: ", e.stack.toString()));
|
||||||
@@ -123,14 +144,28 @@ function onLoad() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function startReceiveHook() {
|
async function startReceiveHook() {
|
||||||
registerReceiveHook<{ msgList: Array<RawMessage> }>(ReceiveCmd.NEW_MSG, async (payload) => {
|
if (getConfigUtil().getConfig().enablePoke) {
|
||||||
|
registerPokeHandler((id, isGroup) => {
|
||||||
|
log(`收到戳一戳消息了!是否群聊:${isGroup},id:${id}`)
|
||||||
|
let pokeEvent: OB11FriendPokeEvent | OB11GroupPokeEvent;
|
||||||
|
if (isGroup) {
|
||||||
|
pokeEvent = new OB11GroupPokeEvent(parseInt(id));
|
||||||
|
} else {
|
||||||
|
pokeEvent = new OB11FriendPokeEvent(parseInt(id));
|
||||||
|
}
|
||||||
|
postOB11Event(pokeEvent);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
registerReceiveHook<{
|
||||||
|
msgList: Array<RawMessage>
|
||||||
|
}>([ReceiveCmdS.NEW_MSG, ReceiveCmdS.NEW_ACTIVE_MSG], async (payload) => {
|
||||||
try {
|
try {
|
||||||
await postReceiveMsg(payload.msgList);
|
await postReceiveMsg(payload.msgList);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log("report message error: ", e.stack.toString());
|
log("report message error: ", e.stack.toString());
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
registerReceiveHook<{ msgList: Array<RawMessage> }>(ReceiveCmd.UPDATE_MSG, async (payload) => {
|
registerReceiveHook<{ msgList: Array<RawMessage> }>([ReceiveCmdS.UPDATE_MSG], async (payload) => {
|
||||||
for (const message of payload.msgList) {
|
for (const message of payload.msgList) {
|
||||||
// log("message update", message.sendStatus, message.msgId, message.msgSeq)
|
// log("message update", message.sendStatus, message.msgId, message.msgSeq)
|
||||||
if (message.recallTime != "0") { //todo: 这个判断方法不太好,应该使用灰色消息元素来判断
|
if (message.recallTime != "0") { //todo: 这个判断方法不太好,应该使用灰色消息元素来判断
|
||||||
@@ -166,7 +201,7 @@ function onLoad() {
|
|||||||
dbUtil.updateMsg(message).then();
|
dbUtil.updateMsg(message).then();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
registerReceiveHook<{ msgRecord: RawMessage }>(ReceiveCmd.SELF_SEND_MSG, async (payload) => {
|
registerReceiveHook<{ msgRecord: RawMessage }>(ReceiveCmdS.SELF_SEND_MSG, async (payload) => {
|
||||||
const {reportSelfMessage} = getConfigUtil().getConfig();
|
const {reportSelfMessage} = getConfigUtil().getConfig();
|
||||||
if (!reportSelfMessage) {
|
if (!reportSelfMessage) {
|
||||||
return
|
return
|
||||||
@@ -182,12 +217,12 @@ function onLoad() {
|
|||||||
"doubt": boolean,
|
"doubt": boolean,
|
||||||
"oldestUnreadSeq": string,
|
"oldestUnreadSeq": string,
|
||||||
"unreadCount": number
|
"unreadCount": number
|
||||||
}>(ReceiveCmd.UNREAD_GROUP_NOTIFY, async (payload) => {
|
}>(ReceiveCmdS.UNREAD_GROUP_NOTIFY, async (payload) => {
|
||||||
if (payload.unreadCount) {
|
if (payload.unreadCount) {
|
||||||
// log("开始获取群通知详情")
|
// log("开始获取群通知详情")
|
||||||
let notify: GroupNotifies;
|
let notify: GroupNotifies;
|
||||||
try {
|
try {
|
||||||
notify = await NTQQApi.getGroupNotifies();
|
notify = await NTQQGroupApi.getGroupNotifies();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// log("获取群通知详情失败", e);
|
// log("获取群通知详情失败", e);
|
||||||
return
|
return
|
||||||
@@ -240,7 +275,7 @@ function onLoad() {
|
|||||||
groupRequestEvent.group_id = parseInt(notify.group.groupCode);
|
groupRequestEvent.group_id = parseInt(notify.group.groupCode);
|
||||||
let requestQQ = ""
|
let requestQQ = ""
|
||||||
try {
|
try {
|
||||||
requestQQ = (await NTQQApi.getUserDetailInfo(notify.user1.uid)).uin;
|
requestQQ = (await NTQQUserApi.getUserDetailInfo(notify.user1.uid)).uin;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log("获取加群人QQ号失败", e)
|
log("获取加群人QQ号失败", e)
|
||||||
}
|
}
|
||||||
@@ -255,7 +290,7 @@ function onLoad() {
|
|||||||
groupInviteEvent.group_id = parseInt(notify.group.groupCode);
|
groupInviteEvent.group_id = parseInt(notify.group.groupCode);
|
||||||
let user_id = (await getFriend(notify.user2.uid))?.uin
|
let user_id = (await getFriend(notify.user2.uid))?.uin
|
||||||
if (!user_id) {
|
if (!user_id) {
|
||||||
user_id = (await NTQQApi.getUserDetailInfo(notify.user2.uid))?.uin
|
user_id = (await NTQQUserApi.getUserDetailInfo(notify.user2.uid))?.uin
|
||||||
}
|
}
|
||||||
groupInviteEvent.user_id = parseInt(user_id);
|
groupInviteEvent.user_id = parseInt(user_id);
|
||||||
groupInviteEvent.sub_type = "invite";
|
groupInviteEvent.sub_type = "invite";
|
||||||
@@ -272,14 +307,14 @@ function onLoad() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
registerReceiveHook<FriendRequestNotify>(ReceiveCmd.FRIEND_REQUEST, async (payload) => {
|
registerReceiveHook<FriendRequestNotify>(ReceiveCmdS.FRIEND_REQUEST, async (payload) => {
|
||||||
for (const req of payload.data.buddyReqs) {
|
for (const req of payload.data.buddyReqs) {
|
||||||
if (req.isUnread && !friendRequests[req.sourceId] && (parseInt(req.reqTime) > startTime / 1000)) {
|
if (req.isUnread && !friendRequests[req.sourceId] && (parseInt(req.reqTime) > startTime / 1000)) {
|
||||||
friendRequests[req.sourceId] = req;
|
friendRequests[req.sourceId] = req;
|
||||||
log("有新的好友请求", req);
|
log("有新的好友请求", req);
|
||||||
let friendRequestEvent = new OB11FriendRequestEvent();
|
let friendRequestEvent = new OB11FriendRequestEvent();
|
||||||
try {
|
try {
|
||||||
let requester = await NTQQApi.getUserDetailInfo(req.friendUid)
|
let requester = await NTQQUserApi.getUserDetailInfo(req.friendUid)
|
||||||
friendRequestEvent.user_id = parseInt(requester.uin);
|
friendRequestEvent.user_id = parseInt(requester.uin);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log("获取加好友者QQ号失败", e);
|
log("获取加好友者QQ号失败", e);
|
||||||
@@ -296,9 +331,15 @@ function onLoad() {
|
|||||||
|
|
||||||
async function start() {
|
async function start() {
|
||||||
log("llonebot pid", process.pid)
|
log("llonebot pid", process.pid)
|
||||||
|
|
||||||
startTime = Date.now();
|
startTime = Date.now();
|
||||||
|
dbUtil.getReceivedTempUinMap().then(m=>{
|
||||||
|
for (const [key, value] of Object.entries(m)) {
|
||||||
|
uidMaps[value] = key;
|
||||||
|
}
|
||||||
|
})
|
||||||
startReceiveHook().then();
|
startReceiveHook().then();
|
||||||
NTQQApi.getGroups(true).then()
|
NTQQGroupApi.getGroups(true).then()
|
||||||
const config = getConfigUtil().getConfig()
|
const config = getConfigUtil().getConfig()
|
||||||
// 检查ffmpeg
|
// 检查ffmpeg
|
||||||
checkFfmpeg(config.ffmpeg).then(exist => {
|
checkFfmpeg(config.ffmpeg).then(exist => {
|
||||||
@@ -327,7 +368,7 @@ function onLoad() {
|
|||||||
const init = async () => {
|
const init = async () => {
|
||||||
try {
|
try {
|
||||||
log("start get self info")
|
log("start get self info")
|
||||||
const _ = await NTQQApi.getSelfInfo();
|
const _ = await NTQQUserApi.getSelfInfo();
|
||||||
log("get self info api result:", _);
|
log("get self info api result:", _);
|
||||||
Object.assign(selfInfo, _);
|
Object.assign(selfInfo, _);
|
||||||
selfInfo.nick = selfInfo.uin;
|
selfInfo.nick = selfInfo.uin;
|
||||||
@@ -337,7 +378,7 @@ function onLoad() {
|
|||||||
log("self info", selfInfo);
|
log("self info", selfInfo);
|
||||||
if (selfInfo.uin) {
|
if (selfInfo.uin) {
|
||||||
try {
|
try {
|
||||||
const userInfo = (await NTQQApi.getUserDetailInfo(selfInfo.uid));
|
const userInfo = (await NTQQUserApi.getUserDetailInfo(selfInfo.uid));
|
||||||
log("self info", userInfo);
|
log("self info", userInfo);
|
||||||
if (userInfo) {
|
if (userInfo) {
|
||||||
selfInfo.nick = userInfo.nick;
|
selfInfo.nick = userInfo.nick;
|
||||||
|
@@ -1,9 +1,10 @@
|
|||||||
import {Config} from "../common/types";
|
import {Config} from "../common/types";
|
||||||
import {checkFfmpeg, getConfigUtil} from "../common/utils";
|
|
||||||
import {ob11HTTPServer} from "../onebot11/server/http";
|
import {ob11HTTPServer} from "../onebot11/server/http";
|
||||||
import {ob11WebsocketServer} from "../onebot11/server/ws/WebsocketServer";
|
import {ob11WebsocketServer} from "../onebot11/server/ws/WebsocketServer";
|
||||||
import {ob11ReverseWebsockets} from "../onebot11/server/ws/ReverseWebsocket";
|
import {ob11ReverseWebsockets} from "../onebot11/server/ws/ReverseWebsocket";
|
||||||
import {llonebotError} from "../common/data";
|
import {llonebotError} from "../common/data";
|
||||||
|
import {checkFfmpeg} from "../common/utils/file";
|
||||||
|
import {getConfigUtil} from "../common/config";
|
||||||
|
|
||||||
export async function setConfig(config: Config) {
|
export async function setConfig(config: Config) {
|
||||||
let oldConfig = getConfigUtil().getConfig();
|
let oldConfig = getConfigUtil().getConfig();
|
||||||
|
217
src/ntqqapi/api/file.ts
Normal file
217
src/ntqqapi/api/file.ts
Normal file
@@ -0,0 +1,217 @@
|
|||||||
|
import {callNTQQApi, GeneralCallResult, NTQQApiClass, NTQQApiMethod} from "../ntcall";
|
||||||
|
import {
|
||||||
|
CacheFileList,
|
||||||
|
CacheFileListItem,
|
||||||
|
CacheFileType,
|
||||||
|
CacheScanResult,
|
||||||
|
ChatCacheList, ChatCacheListItemBasic,
|
||||||
|
ChatType,
|
||||||
|
ElementType
|
||||||
|
} from "../types";
|
||||||
|
import path from "path";
|
||||||
|
import fs from "fs";
|
||||||
|
import {ReceiveCmdS} from "../hook";
|
||||||
|
import {log} from "../../common/utils/log";
|
||||||
|
|
||||||
|
export class NTQQFileApi{
|
||||||
|
static async getFileType(filePath: string) {
|
||||||
|
return await callNTQQApi<{ ext: string }>({
|
||||||
|
className: NTQQApiClass.FS_API, methodName: NTQQApiMethod.FILE_TYPE, args: [filePath]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
static async getFileMd5(filePath: string) {
|
||||||
|
return await callNTQQApi<string>({
|
||||||
|
className: NTQQApiClass.FS_API,
|
||||||
|
methodName: NTQQApiMethod.FILE_MD5,
|
||||||
|
args: [filePath]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
static async copyFile(filePath: string, destPath: string) {
|
||||||
|
return await callNTQQApi<string>({
|
||||||
|
className: NTQQApiClass.FS_API,
|
||||||
|
methodName: NTQQApiMethod.FILE_COPY,
|
||||||
|
args: [{
|
||||||
|
fromPath: filePath,
|
||||||
|
toPath: destPath
|
||||||
|
}]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
static async getFileSize(filePath: string) {
|
||||||
|
return await callNTQQApi<number>({
|
||||||
|
className: NTQQApiClass.FS_API, methodName: NTQQApiMethod.FILE_SIZE, args: [filePath]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
// 上传文件到QQ的文件夹
|
||||||
|
static async uploadFile(filePath: string, elementType: ElementType = ElementType.PIC) {
|
||||||
|
const md5 = await NTQQFileApi.getFileMd5(filePath);
|
||||||
|
let ext = (await NTQQFileApi.getFileType(filePath))?.ext
|
||||||
|
if (ext) {
|
||||||
|
ext = "." + ext
|
||||||
|
} else {
|
||||||
|
ext = ""
|
||||||
|
}
|
||||||
|
let fileName = `${path.basename(filePath)}`;
|
||||||
|
if (fileName.indexOf(".") === -1) {
|
||||||
|
fileName += ext;
|
||||||
|
}
|
||||||
|
const mediaPath = await callNTQQApi<string>({
|
||||||
|
methodName: NTQQApiMethod.MEDIA_FILE_PATH,
|
||||||
|
args: [{
|
||||||
|
path_info: {
|
||||||
|
md5HexStr: md5,
|
||||||
|
fileName: fileName,
|
||||||
|
elementType: elementType,
|
||||||
|
elementSubType: 0,
|
||||||
|
thumbSize: 0,
|
||||||
|
needCreate: true,
|
||||||
|
downloadType: 1,
|
||||||
|
file_uuid: ""
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
})
|
||||||
|
log("media path", mediaPath)
|
||||||
|
await NTQQFileApi.copyFile(filePath, mediaPath);
|
||||||
|
const fileSize = await NTQQFileApi.getFileSize(filePath);
|
||||||
|
return {
|
||||||
|
md5,
|
||||||
|
fileName,
|
||||||
|
path: mediaPath,
|
||||||
|
fileSize
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static async downloadMedia(msgId: string, chatType: ChatType, peerUid: string, elementId: string, thumbPath: string, sourcePath: string) {
|
||||||
|
// 用于下载收到的消息中的图片等
|
||||||
|
if (fs.existsSync(sourcePath)) {
|
||||||
|
return sourcePath
|
||||||
|
}
|
||||||
|
const apiParams = [
|
||||||
|
{
|
||||||
|
getReq: {
|
||||||
|
msgId: msgId,
|
||||||
|
chatType: chatType,
|
||||||
|
peerUid: peerUid,
|
||||||
|
elementId: elementId,
|
||||||
|
thumbSize: 0,
|
||||||
|
downloadType: 1,
|
||||||
|
filePath: thumbPath,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
undefined,
|
||||||
|
]
|
||||||
|
// log("需要下载media", sourcePath);
|
||||||
|
await callNTQQApi({
|
||||||
|
methodName: NTQQApiMethod.DOWNLOAD_MEDIA,
|
||||||
|
args: apiParams,
|
||||||
|
cbCmd: ReceiveCmdS.MEDIA_DOWNLOAD_COMPLETE,
|
||||||
|
cmdCB: (payload: { notifyInfo: { filePath: string } }) => {
|
||||||
|
// log("media 下载完成判断", payload.notifyInfo.filePath, sourcePath);
|
||||||
|
return payload.notifyInfo.filePath == sourcePath;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return sourcePath
|
||||||
|
}
|
||||||
|
static async getImageSize(filePath: string) {
|
||||||
|
return await callNTQQApi<{ width: number, height: number }>({
|
||||||
|
className: NTQQApiClass.FS_API, methodName: NTQQApiMethod.IMAGE_SIZE, args: [filePath]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export class NTQQFileCacheApi{
|
||||||
|
static async setCacheSilentScan(isSilent: boolean = true) {
|
||||||
|
return await callNTQQApi<GeneralCallResult>({
|
||||||
|
methodName: NTQQApiMethod.CACHE_SET_SILENCE,
|
||||||
|
args: [{
|
||||||
|
isSilent
|
||||||
|
}, null]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
static getCacheSessionPathList() {
|
||||||
|
return callNTQQApi<{
|
||||||
|
key: string,
|
||||||
|
value: string
|
||||||
|
}[]>({
|
||||||
|
className: NTQQApiClass.OS_API,
|
||||||
|
methodName: NTQQApiMethod.CACHE_PATH_SESSION,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
static clearCache(cacheKeys: Array<string> = ['tmp', 'hotUpdate']) {
|
||||||
|
return callNTQQApi<any>({ // TODO: 目前还不知道真正的返回值是什么
|
||||||
|
methodName: NTQQApiMethod.CACHE_CLEAR,
|
||||||
|
args: [{
|
||||||
|
keys: cacheKeys
|
||||||
|
}, null]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
static addCacheScannedPaths(pathMap: object = {}) {
|
||||||
|
return callNTQQApi<GeneralCallResult>({
|
||||||
|
methodName: NTQQApiMethod.CACHE_ADD_SCANNED_PATH,
|
||||||
|
args: [{
|
||||||
|
pathMap: {...pathMap},
|
||||||
|
}, null]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
static scanCache() {
|
||||||
|
callNTQQApi<GeneralCallResult>({
|
||||||
|
methodName: ReceiveCmdS.CACHE_SCAN_FINISH,
|
||||||
|
classNameIsRegister: true,
|
||||||
|
}).then();
|
||||||
|
return callNTQQApi<CacheScanResult>({
|
||||||
|
methodName: NTQQApiMethod.CACHE_SCAN,
|
||||||
|
args: [null, null],
|
||||||
|
timeoutSecond: 300,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
static getHotUpdateCachePath() {
|
||||||
|
return callNTQQApi<string>({
|
||||||
|
className: NTQQApiClass.HOTUPDATE_API,
|
||||||
|
methodName: NTQQApiMethod.CACHE_PATH_HOT_UPDATE
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
static getDesktopTmpPath() {
|
||||||
|
return callNTQQApi<string>({
|
||||||
|
className: NTQQApiClass.BUSINESS_API,
|
||||||
|
methodName: NTQQApiMethod.CACHE_PATH_DESKTOP_TEMP
|
||||||
|
});
|
||||||
|
}
|
||||||
|
static getChatCacheList(type: ChatType, pageSize: number = 1000, pageIndex: number = 0) {
|
||||||
|
return new Promise<ChatCacheList>((res, rej) => {
|
||||||
|
callNTQQApi<ChatCacheList>({
|
||||||
|
methodName: NTQQApiMethod.CACHE_CHAT_GET,
|
||||||
|
args: [{
|
||||||
|
chatType: type,
|
||||||
|
pageSize,
|
||||||
|
order: 1,
|
||||||
|
pageIndex
|
||||||
|
}, null]
|
||||||
|
}).then(list => res(list))
|
||||||
|
.catch(e => rej(e));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
static getFileCacheInfo(fileType: CacheFileType, pageSize: number = 1000, lastRecord?: CacheFileListItem) {
|
||||||
|
const _lastRecord = lastRecord ? lastRecord : {fileType: fileType};
|
||||||
|
|
||||||
|
return callNTQQApi<CacheFileList>({
|
||||||
|
methodName: NTQQApiMethod.CACHE_FILE_GET,
|
||||||
|
args: [{
|
||||||
|
fileType: fileType,
|
||||||
|
restart: true,
|
||||||
|
pageSize: pageSize,
|
||||||
|
order: 1,
|
||||||
|
lastRecord: _lastRecord,
|
||||||
|
}, null]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
static async clearChatCache(chats: ChatCacheListItemBasic[] = [], fileKeys: string[] = []) {
|
||||||
|
return await callNTQQApi<GeneralCallResult>({
|
||||||
|
methodName: NTQQApiMethod.CACHE_CHAT_CLEAR,
|
||||||
|
args: [{
|
||||||
|
chats,
|
||||||
|
fileKeys
|
||||||
|
}, null]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
61
src/ntqqapi/api/friend.ts
Normal file
61
src/ntqqapi/api/friend.ts
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
import {Friend, FriendRequest} from "../types";
|
||||||
|
import {ReceiveCmdS} from "../hook";
|
||||||
|
import {callNTQQApi, GeneralCallResult, NTQQApiMethod} from "../ntcall";
|
||||||
|
import {friendRequests} from "../../common/data";
|
||||||
|
|
||||||
|
export class NTQQFriendApi{
|
||||||
|
static async getFriends(forced = false) {
|
||||||
|
const data = await callNTQQApi<{
|
||||||
|
data: {
|
||||||
|
categoryId: number,
|
||||||
|
categroyName: string,
|
||||||
|
categroyMbCount: number,
|
||||||
|
buddyList: Friend[]
|
||||||
|
}[]
|
||||||
|
}>(
|
||||||
|
{
|
||||||
|
methodName: NTQQApiMethod.FRIENDS,
|
||||||
|
args: [{force_update: forced}, undefined],
|
||||||
|
cbCmd: ReceiveCmdS.FRIENDS
|
||||||
|
})
|
||||||
|
let _friends: Friend[] = [];
|
||||||
|
for (const fData of data.data) {
|
||||||
|
_friends.push(...fData.buddyList)
|
||||||
|
}
|
||||||
|
return _friends
|
||||||
|
}
|
||||||
|
static async likeFriend(uid: string, count = 1) {
|
||||||
|
return await callNTQQApi<GeneralCallResult>({
|
||||||
|
methodName: NTQQApiMethod.LIKE_FRIEND,
|
||||||
|
args: [{
|
||||||
|
doLikeUserInfo: {
|
||||||
|
friendUid: uid,
|
||||||
|
sourceId: 71,
|
||||||
|
doLikeCount: count,
|
||||||
|
doLikeTollCount: 0
|
||||||
|
}
|
||||||
|
}, null]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
static async handleFriendRequest(sourceId: number, accept: boolean,) {
|
||||||
|
const request: FriendRequest = friendRequests[sourceId]
|
||||||
|
if (!request) {
|
||||||
|
throw `sourceId ${sourceId}, 对应的好友请求不存在`
|
||||||
|
}
|
||||||
|
const result = await callNTQQApi<GeneralCallResult>({
|
||||||
|
methodName: NTQQApiMethod.HANDLE_FRIEND_REQUEST,
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
"approvalInfo": {
|
||||||
|
"friendUid": request.friendUid,
|
||||||
|
"reqTime": request.reqTime,
|
||||||
|
accept
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
delete friendRequests[sourceId];
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
223
src/ntqqapi/api/group.ts
Normal file
223
src/ntqqapi/api/group.ts
Normal file
@@ -0,0 +1,223 @@
|
|||||||
|
import {ReceiveCmdS} from "../hook";
|
||||||
|
import {Group, GroupMember, GroupMemberRole, GroupNotifies, GroupNotify, GroupRequestOperateTypes} from "../types";
|
||||||
|
import {callNTQQApi, GeneralCallResult, NTQQApiClass, NTQQApiMethod} from "../ntcall";
|
||||||
|
import {uidMaps} from "../../common/data";
|
||||||
|
import {BrowserWindow} from "electron";
|
||||||
|
import {dbUtil} from "../../common/db";
|
||||||
|
import {log} from "../../common/utils/log";
|
||||||
|
|
||||||
|
export class NTQQGroupApi{
|
||||||
|
static async getGroups(forced = false) {
|
||||||
|
let cbCmd = ReceiveCmdS.GROUPS
|
||||||
|
if (process.platform != "win32") {
|
||||||
|
cbCmd = ReceiveCmdS.GROUPS_UNIX
|
||||||
|
}
|
||||||
|
const result = await callNTQQApi<{
|
||||||
|
updateType: number,
|
||||||
|
groupList: Group[]
|
||||||
|
}>({methodName: NTQQApiMethod.GROUPS, args: [{force_update: forced}, undefined], cbCmd})
|
||||||
|
return result.groupList
|
||||||
|
}
|
||||||
|
static async getGroupMembers(groupQQ: string, num = 3000): Promise<GroupMember[]> {
|
||||||
|
const sceneId = await callNTQQApi({
|
||||||
|
methodName: NTQQApiMethod.GROUP_MEMBER_SCENE,
|
||||||
|
args: [{
|
||||||
|
groupCode: groupQQ,
|
||||||
|
scene: "groupMemberList_MainWindow"
|
||||||
|
}]
|
||||||
|
})
|
||||||
|
// log("get group member sceneId", sceneId);
|
||||||
|
try {
|
||||||
|
const result = await callNTQQApi<{
|
||||||
|
result: { infos: any }
|
||||||
|
}>({
|
||||||
|
methodName: NTQQApiMethod.GROUP_MEMBERS,
|
||||||
|
args: [{
|
||||||
|
sceneId: sceneId,
|
||||||
|
num: num
|
||||||
|
},
|
||||||
|
null
|
||||||
|
]
|
||||||
|
})
|
||||||
|
// log("members info", typeof result.result.infos, Object.keys(result.result.infos))
|
||||||
|
const values = result.result.infos.values()
|
||||||
|
|
||||||
|
const members: GroupMember[] = Array.from(values)
|
||||||
|
for (const member of members) {
|
||||||
|
uidMaps[member.uid] = member.uin;
|
||||||
|
}
|
||||||
|
// log(uidMaps);
|
||||||
|
// log("members info", values);
|
||||||
|
log(`get group ${groupQQ} members success`)
|
||||||
|
return members
|
||||||
|
} catch (e) {
|
||||||
|
log(`get group ${groupQQ} members failed`, e)
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static async getGroupNotifies() {
|
||||||
|
// 获取管理员变更
|
||||||
|
// 加群通知,退出通知,需要管理员权限
|
||||||
|
callNTQQApi<GeneralCallResult>({
|
||||||
|
methodName: ReceiveCmdS.GROUP_NOTIFY,
|
||||||
|
classNameIsRegister: true,
|
||||||
|
}).then()
|
||||||
|
return await callNTQQApi<GroupNotifies>({
|
||||||
|
methodName: NTQQApiMethod.GET_GROUP_NOTICE,
|
||||||
|
cbCmd: ReceiveCmdS.GROUP_NOTIFY,
|
||||||
|
afterFirstCmd: false,
|
||||||
|
args: [
|
||||||
|
{"doubt": false, "startSeq": "", "number": 14},
|
||||||
|
null
|
||||||
|
]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
static async getGroupIgnoreNotifies() {
|
||||||
|
await NTQQGroupApi.getGroupNotifies();
|
||||||
|
const result = callNTQQApi<GroupNotifies>({
|
||||||
|
className: NTQQApiClass.WINDOW_API,
|
||||||
|
methodName: NTQQApiMethod.OPEN_EXTRA_WINDOW,
|
||||||
|
cbCmd: ReceiveCmdS.GROUP_NOTIFY,
|
||||||
|
afterFirstCmd: false,
|
||||||
|
args: [
|
||||||
|
"GroupNotifyFilterWindow"
|
||||||
|
]
|
||||||
|
})
|
||||||
|
// 关闭窗口
|
||||||
|
setTimeout(() => {
|
||||||
|
for (const w of BrowserWindow.getAllWindows()) {
|
||||||
|
// log("close window", w.webContents.getURL())
|
||||||
|
if (w.webContents.getURL().indexOf("#/notify-filter/") != -1) {
|
||||||
|
w.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 2000);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
static async handleGroupRequest(seq: string, operateType: GroupRequestOperateTypes, reason?: string) {
|
||||||
|
const notify: GroupNotify = await dbUtil.getGroupNotify(seq)
|
||||||
|
if (!notify) {
|
||||||
|
throw `${seq}对应的加群通知不存在`
|
||||||
|
}
|
||||||
|
// delete groupNotifies[seq];
|
||||||
|
return await callNTQQApi<GeneralCallResult>({
|
||||||
|
methodName: NTQQApiMethod.HANDLE_GROUP_REQUEST,
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
"doubt": false,
|
||||||
|
"operateMsg": {
|
||||||
|
"operateType": operateType, // 2 拒绝
|
||||||
|
"targetMsg": {
|
||||||
|
"seq": seq, // 通知序列号
|
||||||
|
"type": notify.type,
|
||||||
|
"groupCode": notify.group.groupCode,
|
||||||
|
"postscript": reason
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
null
|
||||||
|
]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
static async quitGroup(groupQQ: string) {
|
||||||
|
await callNTQQApi<GeneralCallResult>({
|
||||||
|
methodName: NTQQApiMethod.QUIT_GROUP,
|
||||||
|
args: [
|
||||||
|
{"groupCode": groupQQ},
|
||||||
|
null
|
||||||
|
]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
static async kickMember(groupQQ: string, kickUids: string[], refuseForever: boolean = false, kickReason: string = '') {
|
||||||
|
return await callNTQQApi<GeneralCallResult>(
|
||||||
|
{
|
||||||
|
methodName: NTQQApiMethod.KICK_MEMBER,
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
groupCode: groupQQ,
|
||||||
|
kickUids,
|
||||||
|
refuseForever,
|
||||||
|
kickReason,
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
static async banMember(groupQQ: string, memList: Array<{ uid: string, timeStamp: number }>) {
|
||||||
|
// timeStamp为秒数, 0为解除禁言
|
||||||
|
return await callNTQQApi<GeneralCallResult>(
|
||||||
|
{
|
||||||
|
methodName: NTQQApiMethod.MUTE_MEMBER,
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
groupCode: groupQQ,
|
||||||
|
memList,
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
static async banGroup(groupQQ: string, shutUp: boolean) {
|
||||||
|
return await callNTQQApi<GeneralCallResult>({
|
||||||
|
methodName: NTQQApiMethod.MUTE_GROUP,
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
groupCode: groupQQ,
|
||||||
|
shutUp
|
||||||
|
}, null
|
||||||
|
]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
static async setMemberCard(groupQQ: string, memberUid: string, cardName: string) {
|
||||||
|
return await callNTQQApi<GeneralCallResult>({
|
||||||
|
methodName: NTQQApiMethod.SET_MEMBER_CARD,
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
groupCode: groupQQ,
|
||||||
|
uid: memberUid,
|
||||||
|
cardName
|
||||||
|
}, null
|
||||||
|
]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
static async setMemberRole(groupQQ: string, memberUid: string, role: GroupMemberRole) {
|
||||||
|
return await callNTQQApi<GeneralCallResult>({
|
||||||
|
methodName: NTQQApiMethod.SET_MEMBER_ROLE,
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
groupCode: groupQQ,
|
||||||
|
uid: memberUid,
|
||||||
|
role
|
||||||
|
}, null
|
||||||
|
]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
static async setGroupName(groupQQ: string, groupName: string) {
|
||||||
|
return await callNTQQApi<GeneralCallResult>({
|
||||||
|
methodName: NTQQApiMethod.SET_GROUP_NAME,
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
groupCode: groupQQ,
|
||||||
|
groupName
|
||||||
|
}, null
|
||||||
|
]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 头衔不可用
|
||||||
|
static async setGroupTitle(groupQQ: string, uid: string, title: string) {
|
||||||
|
return await callNTQQApi<GeneralCallResult>({
|
||||||
|
methodName: NTQQApiMethod.SET_GROUP_TITLE,
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
groupCode: groupQQ,
|
||||||
|
uid,
|
||||||
|
title
|
||||||
|
}, null
|
||||||
|
]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
static publishGroupBulletin(groupQQ: string, title: string, content: string) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
188
src/ntqqapi/api/msg.ts
Normal file
188
src/ntqqapi/api/msg.ts
Normal file
@@ -0,0 +1,188 @@
|
|||||||
|
import {callNTQQApi, GeneralCallResult, NTQQApiMethod} from "../ntcall";
|
||||||
|
import {ChatType, RawMessage, SendMessageElement} from "../types";
|
||||||
|
import {dbUtil} from "../../common/db";
|
||||||
|
import {selfInfo} from "../../common/data";
|
||||||
|
import {ReceiveCmdS, registerReceiveHook} from "../hook";
|
||||||
|
import {log} from "../../common/utils/log";
|
||||||
|
import {sleep} from "../../common/utils/helper";
|
||||||
|
|
||||||
|
export let sendMessagePool: Record<string, ((sendSuccessMsg: RawMessage) => void) | null> = {}// peerUid: callbackFunnc
|
||||||
|
|
||||||
|
export interface Peer {
|
||||||
|
chatType: ChatType
|
||||||
|
peerUid: string // 如果是群聊uid为群号,私聊uid就是加密的字符串
|
||||||
|
guildId?: ""
|
||||||
|
}
|
||||||
|
|
||||||
|
export class NTQQMsgApi {
|
||||||
|
static async activateGroupChat(groupCode: string) {
|
||||||
|
// await this.fetchRecentContact();
|
||||||
|
// await sleep(500);
|
||||||
|
return await callNTQQApi<GeneralCallResult>({
|
||||||
|
methodName: NTQQApiMethod.ADD_ACTIVE_CHAT,
|
||||||
|
args: [{peer:{peerUid: groupCode, chatType: ChatType.group}, cnt: 20}, null]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
static async fetchRecentContact(){
|
||||||
|
await callNTQQApi({
|
||||||
|
methodName: NTQQApiMethod.RECENT_CONTACT,
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
fetchParam: {
|
||||||
|
anchorPointContact: {
|
||||||
|
contactId: '',
|
||||||
|
sortField: '',
|
||||||
|
pos: 0,
|
||||||
|
},
|
||||||
|
relativeMoveCount: 0,
|
||||||
|
listType: 2, // 1普通消息,2群助手内的消息
|
||||||
|
count: 200,
|
||||||
|
fetchOld: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
static async recallMsg(peer: Peer, msgIds: string[]) {
|
||||||
|
return await callNTQQApi({
|
||||||
|
methodName: NTQQApiMethod.RECALL_MSG,
|
||||||
|
args: [{
|
||||||
|
peer,
|
||||||
|
msgIds
|
||||||
|
}, null]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
static async sendMsg(peer: Peer, msgElements: SendMessageElement[],
|
||||||
|
waitComplete = true, timeout = 10000) {
|
||||||
|
const peerUid = peer.peerUid
|
||||||
|
|
||||||
|
// 等待上一个相同的peer发送完
|
||||||
|
let checkLastSendUsingTime = 0;
|
||||||
|
const waitLastSend = async () => {
|
||||||
|
if (checkLastSendUsingTime > timeout) {
|
||||||
|
throw ("发送超时")
|
||||||
|
}
|
||||||
|
let lastSending = sendMessagePool[peer.peerUid]
|
||||||
|
if (lastSending) {
|
||||||
|
// log("有正在发送的消息,等待中...")
|
||||||
|
await sleep(500);
|
||||||
|
checkLastSendUsingTime += 500;
|
||||||
|
return await waitLastSend();
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await waitLastSend();
|
||||||
|
|
||||||
|
let sentMessage: RawMessage = null;
|
||||||
|
sendMessagePool[peerUid] = async (rawMessage: RawMessage) => {
|
||||||
|
delete sendMessagePool[peerUid];
|
||||||
|
sentMessage = rawMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
let checkSendCompleteUsingTime = 0;
|
||||||
|
const checkSendComplete = async (): Promise<RawMessage> => {
|
||||||
|
if (sentMessage) {
|
||||||
|
if (waitComplete) {
|
||||||
|
if ((await dbUtil.getMsgByLongId(sentMessage.msgId)).sendStatus == 2) {
|
||||||
|
return sentMessage
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return sentMessage
|
||||||
|
}
|
||||||
|
// log(`给${peerUid}发送消息成功`)
|
||||||
|
}
|
||||||
|
checkSendCompleteUsingTime += 500
|
||||||
|
if (checkSendCompleteUsingTime > timeout) {
|
||||||
|
throw ('发送超时')
|
||||||
|
}
|
||||||
|
await sleep(500)
|
||||||
|
return await checkSendComplete()
|
||||||
|
}
|
||||||
|
|
||||||
|
callNTQQApi({
|
||||||
|
methodName: NTQQApiMethod.SEND_MSG,
|
||||||
|
args: [{
|
||||||
|
msgId: "0",
|
||||||
|
peer, msgElements,
|
||||||
|
msgAttributeInfos: new Map(),
|
||||||
|
}, null]
|
||||||
|
}).then()
|
||||||
|
return await checkSendComplete()
|
||||||
|
}
|
||||||
|
|
||||||
|
static async forwardMsg(srcPeer: Peer, destPeer: Peer, msgIds: string[]) {
|
||||||
|
return await callNTQQApi<GeneralCallResult>({
|
||||||
|
methodName: NTQQApiMethod.FORWARD_MSG,
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
msgIds: msgIds,
|
||||||
|
srcContact: srcPeer,
|
||||||
|
dstContacts: [
|
||||||
|
destPeer
|
||||||
|
],
|
||||||
|
commentElements: [],
|
||||||
|
msgAttributeInfos: new Map()
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
static async multiForwardMsg(srcPeer: Peer, destPeer: Peer, msgIds: string[]) {
|
||||||
|
const msgInfos = msgIds.map(id => {
|
||||||
|
return {msgId: id, senderShowName: selfInfo.nick}
|
||||||
|
})
|
||||||
|
const apiArgs = [
|
||||||
|
{
|
||||||
|
msgInfos,
|
||||||
|
srcContact: srcPeer,
|
||||||
|
dstContact: destPeer,
|
||||||
|
commentElements: [],
|
||||||
|
msgAttributeInfos: new Map()
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
]
|
||||||
|
return await new Promise<RawMessage>((resolve, reject) => {
|
||||||
|
let complete = false
|
||||||
|
setTimeout(() => {
|
||||||
|
if (!complete) {
|
||||||
|
reject("转发消息超时");
|
||||||
|
}
|
||||||
|
}, 5000)
|
||||||
|
registerReceiveHook(ReceiveCmdS.SELF_SEND_MSG, async (payload: { msgRecord: RawMessage }) => {
|
||||||
|
const msg = payload.msgRecord
|
||||||
|
// 需要判断它是转发的消息,并且识别到是当前转发的这一条
|
||||||
|
const arkElement = msg.elements.find(ele => ele.arkElement)
|
||||||
|
if (!arkElement) {
|
||||||
|
// log("收到的不是转发消息")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const forwardData: any = JSON.parse(arkElement.arkElement.bytesData)
|
||||||
|
if (forwardData.app != 'com.tencent.multimsg') {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (msg.peerUid == destPeer.peerUid && msg.senderUid == selfInfo.uid) {
|
||||||
|
complete = true
|
||||||
|
await dbUtil.addMsg(msg)
|
||||||
|
resolve(msg)
|
||||||
|
log('转发消息成功:', payload)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
callNTQQApi<GeneralCallResult>({
|
||||||
|
methodName: NTQQApiMethod.MULTI_FORWARD_MSG,
|
||||||
|
args: apiArgs
|
||||||
|
}).then(result => {
|
||||||
|
log("转发消息结果:", result, apiArgs)
|
||||||
|
if (result.result !== 0) {
|
||||||
|
complete = true;
|
||||||
|
reject("转发消息失败," + JSON.stringify(result));
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
57
src/ntqqapi/api/user.ts
Normal file
57
src/ntqqapi/api/user.ts
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
import {callNTQQApi, GeneralCallResult, NTQQApiClass, NTQQApiMethod} from "../ntcall";
|
||||||
|
import {SelfInfo, User} from "../types";
|
||||||
|
import {ReceiveCmdS} from "../hook";
|
||||||
|
import {uidMaps} from "../../common/data";
|
||||||
|
|
||||||
|
|
||||||
|
export class NTQQUserApi{
|
||||||
|
static async setQQAvatar(filePath: string) {
|
||||||
|
return await callNTQQApi<GeneralCallResult>({
|
||||||
|
methodName: NTQQApiMethod.SET_QQ_AVATAR,
|
||||||
|
args: [{
|
||||||
|
path:filePath
|
||||||
|
}, null],
|
||||||
|
timeoutSecond: 10 // 10秒不一定够
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
static async getSelfInfo() {
|
||||||
|
return await callNTQQApi<SelfInfo>({
|
||||||
|
className: NTQQApiClass.GLOBAL_DATA,
|
||||||
|
methodName: NTQQApiMethod.SELF_INFO, timeoutSecond: 2
|
||||||
|
})
|
||||||
|
}
|
||||||
|
static async getUserInfo(uid: string) {
|
||||||
|
const result = await callNTQQApi<{ profiles: Map<string, User> }>({
|
||||||
|
methodName: NTQQApiMethod.USER_INFO,
|
||||||
|
args: [{force: true, uids: [uid]}, undefined],
|
||||||
|
cbCmd: ReceiveCmdS.USER_INFO
|
||||||
|
})
|
||||||
|
return result.profiles.get(uid)
|
||||||
|
}
|
||||||
|
static async getUserDetailInfo(uid: string) {
|
||||||
|
const result = await callNTQQApi<{ info: User }>({
|
||||||
|
methodName: NTQQApiMethod.USER_DETAIL_INFO,
|
||||||
|
cbCmd: ReceiveCmdS.USER_DETAIL_INFO,
|
||||||
|
afterFirstCmd: false,
|
||||||
|
cmdCB: (payload) => {
|
||||||
|
const success = payload.info.uid == uid
|
||||||
|
// log("get user detail info", success, uid, payload)
|
||||||
|
return success
|
||||||
|
},
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
uid
|
||||||
|
},
|
||||||
|
null
|
||||||
|
]
|
||||||
|
})
|
||||||
|
const info = result.info
|
||||||
|
if (info?.uin) {
|
||||||
|
uidMaps[info.uid] = info.uin
|
||||||
|
}
|
||||||
|
return info
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@@ -11,10 +11,12 @@ import {
|
|||||||
SendTextElement,
|
SendTextElement,
|
||||||
SendVideoElement
|
SendVideoElement
|
||||||
} from "./types";
|
} from "./types";
|
||||||
import {NTQQApi} from "./ntcall";
|
|
||||||
import {calculateFileMD5, encodeSilk, getVideoInfo, isGIF, log, sleep} from "../common/utils";
|
|
||||||
import {promises as fs} from "node:fs";
|
import {promises as fs} from "node:fs";
|
||||||
import ffmpeg from "fluent-ffmpeg"
|
import ffmpeg from "fluent-ffmpeg"
|
||||||
|
import {NTQQFileApi} from "./api/file";
|
||||||
|
import {calculateFileMD5, encodeSilk, getVideoInfo, isGIF} from "../common/utils/file";
|
||||||
|
import {log} from "../common/utils/log";
|
||||||
|
import {sleep} from "../common/utils/helper";
|
||||||
|
|
||||||
|
|
||||||
export class SendMsgElementConstructor {
|
export class SendMsgElementConstructor {
|
||||||
@@ -59,12 +61,12 @@ export class SendMsgElementConstructor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static async pic(picPath: string): Promise<SendPicElement> {
|
static async pic(picPath: string, summary: string = ""): Promise<SendPicElement> {
|
||||||
const {md5, fileName, path, fileSize} = await NTQQApi.uploadFile(picPath, ElementType.PIC);
|
const {md5, fileName, path, fileSize} = await NTQQFileApi.uploadFile(picPath, ElementType.PIC);
|
||||||
if (fileSize === 0) {
|
if (fileSize === 0) {
|
||||||
throw "文件异常,大小为0";
|
throw "文件异常,大小为0";
|
||||||
}
|
}
|
||||||
const imageSize = await NTQQApi.getImageSize(picPath);
|
const imageSize = await NTQQFileApi.getImageSize(picPath);
|
||||||
const picElement = {
|
const picElement = {
|
||||||
md5HexStr: md5,
|
md5HexStr: md5,
|
||||||
fileSize: fileSize,
|
fileSize: fileSize,
|
||||||
@@ -78,7 +80,7 @@ export class SendMsgElementConstructor {
|
|||||||
fileUuid: "",
|
fileUuid: "",
|
||||||
fileSubId: "",
|
fileSubId: "",
|
||||||
thumbFileSize: 0,
|
thumbFileSize: 0,
|
||||||
summary: "",
|
summary,
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -89,7 +91,7 @@ export class SendMsgElementConstructor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static async file(filePath: string, fileName: string = ""): Promise<SendFileElement> {
|
static async file(filePath: string, fileName: string = ""): Promise<SendFileElement> {
|
||||||
const {md5, fileName: _fileName, path, fileSize} = await NTQQApi.uploadFile(filePath, ElementType.FILE);
|
const {md5, fileName: _fileName, path, fileSize} = await NTQQFileApi.uploadFile(filePath, ElementType.FILE);
|
||||||
if (fileSize === 0) {
|
if (fileSize === 0) {
|
||||||
throw "文件异常,大小为0";
|
throw "文件异常,大小为0";
|
||||||
}
|
}
|
||||||
@@ -107,7 +109,7 @@ export class SendMsgElementConstructor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static async video(filePath: string, fileName: string = ""): Promise<SendVideoElement> {
|
static async video(filePath: string, fileName: string = ""): Promise<SendVideoElement> {
|
||||||
let {fileName: _fileName, path, fileSize, md5} = await NTQQApi.uploadFile(filePath, ElementType.VIDEO);
|
let {fileName: _fileName, path, fileSize, md5} = await NTQQFileApi.uploadFile(filePath, ElementType.VIDEO);
|
||||||
if (fileSize === 0) {
|
if (fileSize === 0) {
|
||||||
throw "文件异常,大小为0";
|
throw "文件异常,大小为0";
|
||||||
}
|
}
|
||||||
@@ -136,7 +138,7 @@ export class SendMsgElementConstructor {
|
|||||||
folder: thumb,
|
folder: thumb,
|
||||||
size: videoInfo.width + "x" + videoInfo.height
|
size: videoInfo.width + "x" + videoInfo.height
|
||||||
}).on("end", () => {
|
}).on("end", () => {
|
||||||
resolve(pathLib.join(thumb, thumbFileName));
|
resolve(pathLib.join(thumb, thumbFileName));
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
let thumbPath = new Map()
|
let thumbPath = new Map()
|
||||||
@@ -177,7 +179,7 @@ export class SendMsgElementConstructor {
|
|||||||
static async ptt(pttPath: string): Promise<SendPttElement> {
|
static async ptt(pttPath: string): Promise<SendPttElement> {
|
||||||
const {converted, path: silkPath, duration} = await encodeSilk(pttPath);
|
const {converted, path: silkPath, duration} = await encodeSilk(pttPath);
|
||||||
// log("生成语音", silkPath, duration);
|
// log("生成语音", silkPath, duration);
|
||||||
const {md5, fileName, path, fileSize} = await NTQQApi.uploadFile(silkPath, ElementType.PTT);
|
const {md5, fileName, path, fileSize} = await NTQQFileApi.uploadFile(silkPath, ElementType.PTT);
|
||||||
if (fileSize === 0) {
|
if (fileSize === 0) {
|
||||||
throw "文件异常,大小为0";
|
throw "文件异常,大小为0";
|
||||||
}
|
}
|
||||||
|
28
src/ntqqapi/external/ccpoke/index.ts
vendored
Normal file
28
src/ntqqapi/external/ccpoke/index.ts
vendored
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import {log} from "../../../common/utils/log";
|
||||||
|
|
||||||
|
let pokeEngine: any = null
|
||||||
|
|
||||||
|
type PokeHandler = (id: string, isGroup: boolean)=>void
|
||||||
|
|
||||||
|
let pokeRecords: Record<string, number> = {}
|
||||||
|
export function registerPokeHandler(handler: PokeHandler){
|
||||||
|
if(!pokeEngine){
|
||||||
|
try {
|
||||||
|
pokeEngine = require("./ccpoke/poke-win32-x64.node")
|
||||||
|
pokeEngine.performHooks();
|
||||||
|
}catch (e) {
|
||||||
|
log("戳一戳引擎加载失败", e)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pokeEngine.setHandlerForPokeHook((id: string, isGroup: boolean)=>{
|
||||||
|
let existTime = pokeRecords[id]
|
||||||
|
if (existTime){
|
||||||
|
if (Date.now() - existTime < 1500){
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pokeRecords[id] = Date.now()
|
||||||
|
handler(id, isGroup);
|
||||||
|
})
|
||||||
|
}
|
BIN
src/ntqqapi/external/ccpoke/poke-win32-x64.node
vendored
Normal file
BIN
src/ntqqapi/external/ccpoke/poke-win32-x64.node
vendored
Normal file
Binary file not shown.
@@ -1,36 +1,42 @@
|
|||||||
import {BrowserWindow} from 'electron';
|
import {BrowserWindow} from 'electron';
|
||||||
import {getConfigUtil, log, sleep} from "../common/utils";
|
import {NTQQApiClass} from "./ntcall";
|
||||||
import {NTQQApi, NTQQApiClass, sendMessagePool} from "./ntcall";
|
import {NTQQMsgApi, sendMessagePool} from "./api/msg"
|
||||||
import {Group, RawMessage, User} from "./types";
|
import {ChatType, Group, RawMessage, User} from "./types";
|
||||||
import {friends, groups, selfInfo, tempGroupCodeMap} from "../common/data";
|
import {friends, groups, selfInfo, tempGroupCodeMap, uidMaps} from "../common/data";
|
||||||
import {OB11GroupDecreaseEvent} from "../onebot11/event/notice/OB11GroupDecreaseEvent";
|
import {OB11GroupDecreaseEvent} from "../onebot11/event/notice/OB11GroupDecreaseEvent";
|
||||||
import {OB11GroupIncreaseEvent} from "../onebot11/event/notice/OB11GroupIncreaseEvent";
|
|
||||||
import {v4 as uuidv4} from "uuid"
|
import {v4 as uuidv4} from "uuid"
|
||||||
import {postOB11Event} from "../onebot11/server/postOB11Event";
|
import {postOB11Event} from "../onebot11/server/postOB11Event";
|
||||||
import {HOOK_LOG} from "../common/config";
|
import {getConfigUtil, HOOK_LOG} from "../common/config";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import {dbUtil} from "../common/db";
|
import {dbUtil} from "../common/db";
|
||||||
|
import {NTQQGroupApi} from "./api/group";
|
||||||
|
import {log} from "../common/utils/log";
|
||||||
|
import {sleep} from "../common/utils/helper";
|
||||||
|
|
||||||
export let hookApiCallbacks: Record<string, (apiReturn: any) => void> = {}
|
export let hookApiCallbacks: Record<string, (apiReturn: any) => void> = {}
|
||||||
|
|
||||||
export enum ReceiveCmd {
|
export let ReceiveCmdS = {
|
||||||
UPDATE_MSG = "nodeIKernelMsgListener/onMsgInfoListUpdate",
|
UPDATE_MSG: "nodeIKernelMsgListener/onMsgInfoListUpdate",
|
||||||
NEW_MSG = "nodeIKernelMsgListener/onRecvMsg",
|
UPDATE_ACTIVE_MSG: "nodeIKernelMsgListener/onActiveMsgInfoUpdate",
|
||||||
SELF_SEND_MSG = "nodeIKernelMsgListener/onAddSendMsg",
|
NEW_MSG: `nodeIKernelMsgListener/onRecvMsg`,
|
||||||
USER_INFO = "nodeIKernelProfileListener/onProfileSimpleChanged",
|
NEW_ACTIVE_MSG: `nodeIKernelMsgListener/onRecvActiveMsg`,
|
||||||
USER_DETAIL_INFO = "nodeIKernelProfileListener/onProfileDetailInfoChanged",
|
SELF_SEND_MSG: "nodeIKernelMsgListener/onAddSendMsg",
|
||||||
GROUPS = "nodeIKernelGroupListener/onGroupListUpdate",
|
USER_INFO: "nodeIKernelProfileListener/onProfileSimpleChanged",
|
||||||
GROUPS_UNIX = "onGroupListUpdate",
|
USER_DETAIL_INFO: "nodeIKernelProfileListener/onProfileDetailInfoChanged",
|
||||||
FRIENDS = "onBuddyListChange",
|
GROUPS: "nodeIKernelGroupListener/onGroupListUpdate",
|
||||||
MEDIA_DOWNLOAD_COMPLETE = "nodeIKernelMsgListener/onRichMediaDownloadComplete",
|
GROUPS_UNIX: "onGroupListUpdate",
|
||||||
UNREAD_GROUP_NOTIFY = "nodeIKernelGroupListener/onGroupNotifiesUnreadCountUpdated",
|
FRIENDS: "onBuddyListChange",
|
||||||
GROUP_NOTIFY = "nodeIKernelGroupListener/onGroupSingleScreenNotifies",
|
MEDIA_DOWNLOAD_COMPLETE: "nodeIKernelMsgListener/onRichMediaDownloadComplete",
|
||||||
FRIEND_REQUEST = "nodeIKernelBuddyListener/onBuddyReqChange",
|
UNREAD_GROUP_NOTIFY: "nodeIKernelGroupListener/onGroupNotifiesUnreadCountUpdated",
|
||||||
SELF_STATUS = 'nodeIKernelProfileListener/onSelfStatusChanged',
|
GROUP_NOTIFY: "nodeIKernelGroupListener/onGroupSingleScreenNotifies",
|
||||||
CACHE_SCAN_FINISH = "nodeIKernelStorageCleanListener/onFinishScan",
|
FRIEND_REQUEST: "nodeIKernelBuddyListener/onBuddyReqChange",
|
||||||
MEDIA_UPLOAD_COMPLETE = "nodeIKernelMsgListener/onRichMediaUploadComplete",
|
SELF_STATUS: 'nodeIKernelProfileListener/onSelfStatusChanged',
|
||||||
|
CACHE_SCAN_FINISH: "nodeIKernelStorageCleanListener/onFinishScan",
|
||||||
|
MEDIA_UPLOAD_COMPLETE: "nodeIKernelMsgListener/onRichMediaUploadComplete",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type ReceiveCmd = typeof ReceiveCmdS[keyof typeof ReceiveCmdS]
|
||||||
|
|
||||||
interface NTQQApiReturnData<PayloadType = unknown> extends Array<any> {
|
interface NTQQApiReturnData<PayloadType = unknown> extends Array<any> {
|
||||||
0: {
|
0: {
|
||||||
"type": "request",
|
"type": "request",
|
||||||
@@ -46,7 +52,7 @@ interface NTQQApiReturnData<PayloadType = unknown> extends Array<any> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let receiveHooks: Array<{
|
let receiveHooks: Array<{
|
||||||
method: ReceiveCmd,
|
method: ReceiveCmd[],
|
||||||
hookFunc: ((payload: any) => void | Promise<void>)
|
hookFunc: ((payload: any) => void | Promise<void>)
|
||||||
id: string
|
id: string
|
||||||
}> = []
|
}> = []
|
||||||
@@ -54,13 +60,19 @@ let receiveHooks: Array<{
|
|||||||
export function hookNTQQApiReceive(window: BrowserWindow) {
|
export function hookNTQQApiReceive(window: BrowserWindow) {
|
||||||
const originalSend = window.webContents.send;
|
const originalSend = window.webContents.send;
|
||||||
const patchSend = (channel: string, ...args: NTQQApiReturnData) => {
|
const patchSend = (channel: string, ...args: NTQQApiReturnData) => {
|
||||||
HOOK_LOG && log(`received ntqq api message: ${channel}`, JSON.stringify(args))
|
try {
|
||||||
|
if (!args[0]?.eventName?.startsWith("ns-LoggerApi")) {
|
||||||
|
HOOK_LOG && log(`received ntqq api message: ${channel}`, JSON.stringify(args))
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
|
||||||
|
}
|
||||||
if (args?.[1] instanceof Array) {
|
if (args?.[1] instanceof Array) {
|
||||||
for (let receiveData of args?.[1]) {
|
for (let receiveData of args?.[1]) {
|
||||||
const ntQQApiMethodName = receiveData.cmdName;
|
const ntQQApiMethodName = receiveData.cmdName;
|
||||||
// log(`received ntqq api message: ${channel} ${ntQQApiMethodName}`, JSON.stringify(receiveData))
|
// log(`received ntqq api message: ${channel} ${ntQQApiMethodName}`, JSON.stringify(receiveData))
|
||||||
for (let hook of receiveHooks) {
|
for (let hook of receiveHooks) {
|
||||||
if (hook.method === ntQQApiMethodName) {
|
if (hook.method.includes(ntQQApiMethodName)) {
|
||||||
new Promise((resolve, reject) => {
|
new Promise((resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
let _ = hook.hookFunc(receiveData.payload)
|
let _ = hook.hookFunc(receiveData.payload)
|
||||||
@@ -98,7 +110,13 @@ export function hookNTQQApiCall(window: BrowserWindow) {
|
|||||||
|
|
||||||
const proxyIpcMsg = new Proxy(ipc_message_proxy, {
|
const proxyIpcMsg = new Proxy(ipc_message_proxy, {
|
||||||
apply(target, thisArg, args) {
|
apply(target, thisArg, args) {
|
||||||
HOOK_LOG && log("call NTQQ api", thisArg, args);
|
try {
|
||||||
|
if (args[3][1][0] !== "info") {
|
||||||
|
HOOK_LOG && log("call NTQQ api", thisArg, args);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
|
||||||
|
}
|
||||||
return target.apply(thisArg, args);
|
return target.apply(thisArg, args);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -109,8 +127,11 @@ export function hookNTQQApiCall(window: BrowserWindow) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function registerReceiveHook<PayloadType>(method: ReceiveCmd, hookFunc: (payload: PayloadType) => void): string {
|
export function registerReceiveHook<PayloadType>(method: ReceiveCmd | ReceiveCmd[], hookFunc: (payload: PayloadType) => void): string {
|
||||||
const id = uuidv4()
|
const id = uuidv4()
|
||||||
|
if (!Array.isArray(method)) {
|
||||||
|
method = [method]
|
||||||
|
}
|
||||||
receiveHooks.push({
|
receiveHooks.push({
|
||||||
method,
|
method,
|
||||||
hookFunc,
|
hookFunc,
|
||||||
@@ -124,8 +145,20 @@ export function removeReceiveHook(id: string) {
|
|||||||
receiveHooks.splice(index, 1);
|
receiveHooks.splice(index, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let activatedGroups: string[] = [];
|
||||||
async function updateGroups(_groups: Group[], needUpdate: boolean = true) {
|
async function updateGroups(_groups: Group[], needUpdate: boolean = true) {
|
||||||
for (let group of _groups) {
|
for (let group of _groups) {
|
||||||
|
// log("update group", group)
|
||||||
|
if (!activatedGroups.includes(group.groupCode)) {
|
||||||
|
NTQQMsgApi.activateGroupChat(group.groupCode).then((r) => {
|
||||||
|
activatedGroups.push(group.groupCode);
|
||||||
|
// log(`激活群聊天窗口${group.groupName}(${group.groupCode})`, r)
|
||||||
|
// if (r.result !== 0) {
|
||||||
|
// setTimeout(() => NTQQMsgApi.activateGroupChat(group.groupCode).then(r => log(`再次激活群聊天窗口${group.groupName}(${group.groupCode})`, r)), 500);
|
||||||
|
// }else {
|
||||||
|
// }
|
||||||
|
}).catch(log)
|
||||||
|
}
|
||||||
let existGroup = groups.find(g => g.groupCode == group.groupCode);
|
let existGroup = groups.find(g => g.groupCode == group.groupCode);
|
||||||
if (existGroup) {
|
if (existGroup) {
|
||||||
Object.assign(existGroup, group);
|
Object.assign(existGroup, group);
|
||||||
@@ -135,7 +168,7 @@ async function updateGroups(_groups: Group[], needUpdate: boolean = true) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (needUpdate) {
|
if (needUpdate) {
|
||||||
const members = await NTQQApi.getGroupMembers(group.groupCode);
|
const members = await NTQQGroupApi.getGroupMembers(group.groupCode);
|
||||||
|
|
||||||
if (members) {
|
if (members) {
|
||||||
existGroup.members = members;
|
existGroup.members = members;
|
||||||
@@ -154,7 +187,7 @@ async function processGroupEvent(payload) {
|
|||||||
const oldMembers = existGroup.members;
|
const oldMembers = existGroup.members;
|
||||||
|
|
||||||
await sleep(200); // 如果请求QQ API的速度过快,通常无法正确拉取到最新的群信息,因此这里人为引入一个延时
|
await sleep(200); // 如果请求QQ API的速度过快,通常无法正确拉取到最新的群信息,因此这里人为引入一个延时
|
||||||
const newMembers = await NTQQApi.getGroupMembers(group.groupCode);
|
const newMembers = await NTQQGroupApi.getGroupMembers(group.groupCode);
|
||||||
|
|
||||||
group.members = newMembers;
|
group.members = newMembers;
|
||||||
const newMembersSet = new Set<string>(); // 建立索引降低时间复杂度
|
const newMembersSet = new Set<string>(); // 建立索引降低时间复杂度
|
||||||
@@ -181,7 +214,7 @@ async function processGroupEvent(payload) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 群列表变动
|
// 群列表变动
|
||||||
registerReceiveHook<{ groupList: Group[], updateType: number }>(ReceiveCmd.GROUPS, (payload) => {
|
registerReceiveHook<{ groupList: Group[], updateType: number }>(ReceiveCmdS.GROUPS, (payload) => {
|
||||||
if (payload.updateType != 2) {
|
if (payload.updateType != 2) {
|
||||||
updateGroups(payload.groupList).then();
|
updateGroups(payload.groupList).then();
|
||||||
} else {
|
} else {
|
||||||
@@ -190,7 +223,7 @@ registerReceiveHook<{ groupList: Group[], updateType: number }>(ReceiveCmd.GROUP
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
registerReceiveHook<{ groupList: Group[], updateType: number }>(ReceiveCmd.GROUPS_UNIX, (payload) => {
|
registerReceiveHook<{ groupList: Group[], updateType: number }>(ReceiveCmdS.GROUPS_UNIX, (payload) => {
|
||||||
if (payload.updateType != 2) {
|
if (payload.updateType != 2) {
|
||||||
updateGroups(payload.groupList).then();
|
updateGroups(payload.groupList).then();
|
||||||
} else {
|
} else {
|
||||||
@@ -203,7 +236,7 @@ registerReceiveHook<{ groupList: Group[], updateType: number }>(ReceiveCmd.GROUP
|
|||||||
// 好友列表变动
|
// 好友列表变动
|
||||||
registerReceiveHook<{
|
registerReceiveHook<{
|
||||||
data: { categoryId: number, categroyName: string, categroyMbCount: number, buddyList: User[] }[]
|
data: { categoryId: number, categroyName: string, categroyMbCount: number, buddyList: User[] }[]
|
||||||
}>(ReceiveCmd.FRIENDS, payload => {
|
}>(ReceiveCmdS.FRIENDS, payload => {
|
||||||
for (const fData of payload.data) {
|
for (const fData of payload.data) {
|
||||||
const _friends = fData.buddyList;
|
const _friends = fData.buddyList;
|
||||||
for (let friend of _friends) {
|
for (let friend of _friends) {
|
||||||
@@ -217,8 +250,26 @@ registerReceiveHook<{
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// 新消息
|
registerReceiveHook<{ msgList: Array<RawMessage> }>([ReceiveCmdS.NEW_MSG, ReceiveCmdS.NEW_ACTIVE_MSG], (payload) => {
|
||||||
registerReceiveHook<{ msgList: Array<RawMessage> }>(ReceiveCmd.NEW_MSG, (payload) => {
|
// 保存一下uid
|
||||||
|
for (const message of payload.msgList) {
|
||||||
|
const uid = message.senderUid;
|
||||||
|
const uin = message.senderUin;
|
||||||
|
if (uid && uin) {
|
||||||
|
if (message.chatType === ChatType.temp){
|
||||||
|
dbUtil.getReceivedTempUinMap().then(receivedTempUinMap=>{
|
||||||
|
if (!receivedTempUinMap[uin]){
|
||||||
|
receivedTempUinMap[uin] = uid;
|
||||||
|
dbUtil.setReceivedTempUinMap(receivedTempUinMap)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
uidMaps[uid] = uin;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 自动清理新消息文件
|
||||||
const {autoDeleteFile} = getConfigUtil().getConfig();
|
const {autoDeleteFile} = getConfigUtil().getConfig();
|
||||||
if (!autoDeleteFile) {
|
if (!autoDeleteFile) {
|
||||||
return
|
return
|
||||||
@@ -241,7 +292,7 @@ registerReceiveHook<{ msgList: Array<RawMessage> }>(ReceiveCmd.NEW_MSG, (payload
|
|||||||
pathList.push(...Object.values(msgElement.picElement.thumbPath))
|
pathList.push(...Object.values(msgElement.picElement.thumbPath))
|
||||||
}
|
}
|
||||||
const aioOpGrayTipElement = msgElement.grayTipElement?.aioOpGrayTipElement
|
const aioOpGrayTipElement = msgElement.grayTipElement?.aioOpGrayTipElement
|
||||||
if (aioOpGrayTipElement){
|
if (aioOpGrayTipElement) {
|
||||||
tempGroupCodeMap[aioOpGrayTipElement.peerUid] = aioOpGrayTipElement.fromGrpCodeOfTmpChat;
|
tempGroupCodeMap[aioOpGrayTipElement.peerUid] = aioOpGrayTipElement.fromGrpCodeOfTmpChat;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -258,7 +309,7 @@ registerReceiveHook<{ msgList: Array<RawMessage> }>(ReceiveCmd.NEW_MSG, (payload
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
registerReceiveHook<{ msgRecord: RawMessage }>(ReceiveCmd.SELF_SEND_MSG, ({msgRecord}) => {
|
registerReceiveHook<{ msgRecord: RawMessage }>(ReceiveCmdS.SELF_SEND_MSG, ({msgRecord}) => {
|
||||||
const message = msgRecord;
|
const message = msgRecord;
|
||||||
const peerUid = message.peerUid;
|
const peerUid = message.peerUid;
|
||||||
// log("收到自己发送成功的消息", Object.keys(sendMessagePool), message);
|
// log("收到自己发送成功的消息", Object.keys(sendMessagePool), message);
|
||||||
@@ -274,6 +325,6 @@ registerReceiveHook<{ msgRecord: RawMessage }>(ReceiveCmd.SELF_SEND_MSG, ({msgRe
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
registerReceiveHook<{ info: { status: number } }>(ReceiveCmd.SELF_STATUS, (info) => {
|
registerReceiveHook<{ info: { status: number } }>(ReceiveCmdS.SELF_STATUS, (info) => {
|
||||||
selfInfo.online = info.info.status !== 20
|
selfInfo.online = info.info.status !== 20
|
||||||
})
|
})
|
||||||
|
@@ -1,42 +1,8 @@
|
|||||||
import {BrowserWindow, ipcMain} from "electron";
|
import {ipcMain} from "electron";
|
||||||
import {hookApiCallbacks, ReceiveCmd, registerReceiveHook, removeReceiveHook} from "./hook";
|
import {hookApiCallbacks, ReceiveCmd, registerReceiveHook, removeReceiveHook} from "./hook";
|
||||||
import {log, sleep} from "../common/utils";
|
|
||||||
import {
|
|
||||||
ChatType,
|
|
||||||
ElementType,
|
|
||||||
Friend,
|
|
||||||
FriendRequest,
|
|
||||||
Group,
|
|
||||||
GroupMember,
|
|
||||||
GroupMemberRole,
|
|
||||||
GroupNotifies,
|
|
||||||
GroupNotify,
|
|
||||||
GroupRequestOperateTypes,
|
|
||||||
RawMessage,
|
|
||||||
SelfInfo,
|
|
||||||
SendMessageElement,
|
|
||||||
User,
|
|
||||||
CacheScanResult,
|
|
||||||
ChatCacheList, ChatCacheListItemBasic,
|
|
||||||
CacheFileList, CacheFileListItem, CacheFileType,
|
|
||||||
} from "./types";
|
|
||||||
import * as fs from "fs";
|
|
||||||
import {friendRequests, selfInfo, uidMaps} from "../common/data";
|
|
||||||
import {v4 as uuidv4} from "uuid"
|
import {v4 as uuidv4} from "uuid"
|
||||||
import path from "path";
|
import {log} from "../common/utils/log";
|
||||||
import {dbUtil} from "../common/db";
|
|
||||||
|
|
||||||
interface IPCReceiveEvent {
|
|
||||||
eventName: string
|
|
||||||
callbackId: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export type IPCReceiveDetail = [
|
|
||||||
{
|
|
||||||
cmdName: NTQQApiMethod
|
|
||||||
payload: unknown
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
export enum NTQQApiClass {
|
export enum NTQQApiClass {
|
||||||
NT_API = "ns-ntApi",
|
NT_API = "ns-ntApi",
|
||||||
@@ -49,7 +15,9 @@ export enum NTQQApiClass {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export enum NTQQApiMethod {
|
export enum NTQQApiMethod {
|
||||||
SET_HEADER = "nodeIKernelProfileService/setHeader",
|
RECENT_CONTACT = "nodeIKernelRecentContactService/fetchAndSubscribeABatchOfRecentContact",
|
||||||
|
ADD_ACTIVE_CHAT = "nodeIKernelMsgService/getAioFirstViewLatestMsgsAndAddActiveChat", // 激活群助手内的聊天窗口,这样才能收到消息
|
||||||
|
ADD_ACTIVE_CHAT_2 = "nodeIKernelMsgService/getMsgsIncludeSelfAndAddActiveChat",
|
||||||
LIKE_FRIEND = "nodeIKernelProfileLikeService/setBuddyProfileLike",
|
LIKE_FRIEND = "nodeIKernelProfileLikeService/setBuddyProfileLike",
|
||||||
SELF_INFO = "fetchAuthData",
|
SELF_INFO = "fetchAuthData",
|
||||||
FRIENDS = "nodeIKernelBuddyService/getBuddyList",
|
FRIENDS = "nodeIKernelBuddyService/getBuddyList",
|
||||||
@@ -96,6 +64,8 @@ export enum NTQQApiMethod {
|
|||||||
CACHE_CHAT_CLEAR = 'nodeIKernelStorageCleanService/clearChatCacheInfo',
|
CACHE_CHAT_CLEAR = 'nodeIKernelStorageCleanService/clearChatCacheInfo',
|
||||||
|
|
||||||
OPEN_EXTRA_WINDOW = 'openExternalWindow',
|
OPEN_EXTRA_WINDOW = 'openExternalWindow',
|
||||||
|
|
||||||
|
SET_QQ_AVATAR = 'nodeIKernelProfileService/setHeader'
|
||||||
}
|
}
|
||||||
|
|
||||||
enum NTQQApiChannel {
|
enum NTQQApiChannel {
|
||||||
@@ -104,12 +74,6 @@ enum NTQQApiChannel {
|
|||||||
IPC_UP_1 = "IPC_UP_1",
|
IPC_UP_1 = "IPC_UP_1",
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Peer {
|
|
||||||
chatType: ChatType
|
|
||||||
peerUid: string // 如果是群聊uid为群号,私聊uid就是加密的字符串
|
|
||||||
guildId?: ""
|
|
||||||
}
|
|
||||||
|
|
||||||
interface NTQQApiParams {
|
interface NTQQApiParams {
|
||||||
methodName: NTQQApiMethod | string,
|
methodName: NTQQApiMethod | string,
|
||||||
className?: NTQQApiClass,
|
className?: NTQQApiClass,
|
||||||
@@ -122,7 +86,7 @@ interface NTQQApiParams {
|
|||||||
timeoutSecond?: number,
|
timeoutSecond?: number,
|
||||||
}
|
}
|
||||||
|
|
||||||
function callNTQQApi<ReturnType>(params: NTQQApiParams) {
|
export function callNTQQApi<ReturnType>(params: NTQQApiParams) {
|
||||||
let {
|
let {
|
||||||
className, methodName, channel, args,
|
className, methodName, channel, args,
|
||||||
cbCmd, timeoutSecond: timeout,
|
cbCmd, timeoutSecond: timeout,
|
||||||
@@ -197,574 +161,13 @@ function callNTQQApi<ReturnType>(params: NTQQApiParams) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export let sendMessagePool: Record<string, ((sendSuccessMsg: RawMessage) => void) | null> = {}// peerUid: callbackFunnc
|
export interface GeneralCallResult {
|
||||||
|
|
||||||
interface GeneralCallResult {
|
|
||||||
result: number, // 0: success
|
result: number, // 0: success
|
||||||
errMsg: string
|
errMsg: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export class NTQQApi {
|
export class NTQQApi {
|
||||||
static async setHeader(path: string) {
|
|
||||||
return await callNTQQApi<GeneralCallResult>({
|
|
||||||
methodName: NTQQApiMethod.SET_HEADER,
|
|
||||||
args: [path]
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
static async likeFriend(uid: string, count = 1) {
|
|
||||||
return await callNTQQApi<GeneralCallResult>({
|
|
||||||
methodName: NTQQApiMethod.LIKE_FRIEND,
|
|
||||||
args: [{
|
|
||||||
doLikeUserInfo: {
|
|
||||||
friendUid: uid,
|
|
||||||
sourceId: 71,
|
|
||||||
doLikeCount: count,
|
|
||||||
doLikeTollCount: 0
|
|
||||||
}
|
|
||||||
}, null]
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
static async getSelfInfo() {
|
|
||||||
return await callNTQQApi<SelfInfo>({
|
|
||||||
className: NTQQApiClass.GLOBAL_DATA,
|
|
||||||
methodName: NTQQApiMethod.SELF_INFO, timeoutSecond: 2
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
static async getUserInfo(uid: string) {
|
|
||||||
const result = await callNTQQApi<{ profiles: Map<string, User> }>({
|
|
||||||
methodName: NTQQApiMethod.USER_INFO,
|
|
||||||
args: [{force: true, uids: [uid]}, undefined],
|
|
||||||
cbCmd: ReceiveCmd.USER_INFO
|
|
||||||
})
|
|
||||||
return result.profiles.get(uid)
|
|
||||||
}
|
|
||||||
|
|
||||||
static async getUserDetailInfo(uid: string) {
|
|
||||||
const result = await callNTQQApi<{ info: User }>({
|
|
||||||
methodName: NTQQApiMethod.USER_DETAIL_INFO,
|
|
||||||
cbCmd: ReceiveCmd.USER_DETAIL_INFO,
|
|
||||||
afterFirstCmd: false,
|
|
||||||
cmdCB: (payload) => {
|
|
||||||
const success = payload.info.uid == uid
|
|
||||||
// log("get user detail info", success, uid, payload)
|
|
||||||
return success
|
|
||||||
},
|
|
||||||
args: [
|
|
||||||
{
|
|
||||||
uid
|
|
||||||
},
|
|
||||||
null
|
|
||||||
]
|
|
||||||
})
|
|
||||||
const info = result.info
|
|
||||||
if (info?.uin) {
|
|
||||||
uidMaps[info.uid] = info.uin
|
|
||||||
}
|
|
||||||
return info
|
|
||||||
}
|
|
||||||
|
|
||||||
static async getFriends(forced = false) {
|
|
||||||
const data = await callNTQQApi<{
|
|
||||||
data: {
|
|
||||||
categoryId: number,
|
|
||||||
categroyName: string,
|
|
||||||
categroyMbCount: number,
|
|
||||||
buddyList: Friend[]
|
|
||||||
}[]
|
|
||||||
}>(
|
|
||||||
{
|
|
||||||
methodName: NTQQApiMethod.FRIENDS,
|
|
||||||
args: [{force_update: forced}, undefined],
|
|
||||||
cbCmd: ReceiveCmd.FRIENDS
|
|
||||||
})
|
|
||||||
let _friends: Friend[] = [];
|
|
||||||
for (const fData of data.data) {
|
|
||||||
_friends.push(...fData.buddyList)
|
|
||||||
}
|
|
||||||
return _friends
|
|
||||||
}
|
|
||||||
|
|
||||||
static async getGroups(forced = false) {
|
|
||||||
let cbCmd = ReceiveCmd.GROUPS
|
|
||||||
if (process.platform != "win32") {
|
|
||||||
cbCmd = ReceiveCmd.GROUPS_UNIX
|
|
||||||
}
|
|
||||||
const result = await callNTQQApi<{
|
|
||||||
updateType: number,
|
|
||||||
groupList: Group[]
|
|
||||||
}>({methodName: NTQQApiMethod.GROUPS, args: [{force_update: forced}, undefined], cbCmd})
|
|
||||||
return result.groupList
|
|
||||||
}
|
|
||||||
|
|
||||||
static async getGroupMembers(groupQQ: string, num = 3000): Promise<GroupMember[]> {
|
|
||||||
const sceneId = await callNTQQApi({
|
|
||||||
methodName: NTQQApiMethod.GROUP_MEMBER_SCENE,
|
|
||||||
args: [{
|
|
||||||
groupCode: groupQQ,
|
|
||||||
scene: "groupMemberList_MainWindow"
|
|
||||||
}]
|
|
||||||
})
|
|
||||||
// log("get group member sceneId", sceneId);
|
|
||||||
try {
|
|
||||||
const result = await callNTQQApi<{
|
|
||||||
result: { infos: any }
|
|
||||||
}>({
|
|
||||||
methodName: NTQQApiMethod.GROUP_MEMBERS,
|
|
||||||
args: [{
|
|
||||||
sceneId: sceneId,
|
|
||||||
num: num
|
|
||||||
},
|
|
||||||
null
|
|
||||||
]
|
|
||||||
})
|
|
||||||
// log("members info", typeof result.result.infos, Object.keys(result.result.infos))
|
|
||||||
const values = result.result.infos.values()
|
|
||||||
|
|
||||||
const members: GroupMember[] = Array.from(values)
|
|
||||||
for (const member of members) {
|
|
||||||
uidMaps[member.uid] = member.uin;
|
|
||||||
}
|
|
||||||
// log(uidMaps);
|
|
||||||
// log("members info", values);
|
|
||||||
log(`get group ${groupQQ} members success`)
|
|
||||||
return members
|
|
||||||
} catch (e) {
|
|
||||||
log(`get group ${groupQQ} members failed`, e)
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static async getFileType(filePath: string) {
|
|
||||||
return await callNTQQApi<{ ext: string }>({
|
|
||||||
className: NTQQApiClass.FS_API, methodName: NTQQApiMethod.FILE_TYPE, args: [filePath]
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
static async getFileMd5(filePath: string) {
|
|
||||||
return await callNTQQApi<string>({
|
|
||||||
className: NTQQApiClass.FS_API,
|
|
||||||
methodName: NTQQApiMethod.FILE_MD5,
|
|
||||||
args: [filePath]
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
static async copyFile(filePath: string, destPath: string) {
|
|
||||||
return await callNTQQApi<string>({
|
|
||||||
className: NTQQApiClass.FS_API,
|
|
||||||
methodName: NTQQApiMethod.FILE_COPY,
|
|
||||||
args: [{
|
|
||||||
fromPath: filePath,
|
|
||||||
toPath: destPath
|
|
||||||
}]
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
static async getImageSize(filePath: string) {
|
|
||||||
return await callNTQQApi<{ width: number, height: number }>({
|
|
||||||
className: NTQQApiClass.FS_API, methodName: NTQQApiMethod.IMAGE_SIZE, args: [filePath]
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
static async getFileSize(filePath: string) {
|
|
||||||
return await callNTQQApi<number>({
|
|
||||||
className: NTQQApiClass.FS_API, methodName: NTQQApiMethod.FILE_SIZE, args: [filePath]
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// 上传文件到QQ的文件夹
|
|
||||||
static async uploadFile(filePath: string, elementType: ElementType = ElementType.PIC) {
|
|
||||||
const md5 = await NTQQApi.getFileMd5(filePath);
|
|
||||||
let ext = (await NTQQApi.getFileType(filePath))?.ext
|
|
||||||
if (ext) {
|
|
||||||
ext = "." + ext
|
|
||||||
} else {
|
|
||||||
ext = ""
|
|
||||||
}
|
|
||||||
let fileName = `${path.basename(filePath)}`;
|
|
||||||
if (fileName.indexOf(".") === -1) {
|
|
||||||
fileName += ext;
|
|
||||||
}
|
|
||||||
const mediaPath = await callNTQQApi<string>({
|
|
||||||
methodName: NTQQApiMethod.MEDIA_FILE_PATH,
|
|
||||||
args: [{
|
|
||||||
path_info: {
|
|
||||||
md5HexStr: md5,
|
|
||||||
fileName: fileName,
|
|
||||||
elementType: elementType,
|
|
||||||
elementSubType: 0,
|
|
||||||
thumbSize: 0,
|
|
||||||
needCreate: true,
|
|
||||||
downloadType: 1,
|
|
||||||
file_uuid: ""
|
|
||||||
}
|
|
||||||
}]
|
|
||||||
})
|
|
||||||
log("media path", mediaPath)
|
|
||||||
await NTQQApi.copyFile(filePath, mediaPath);
|
|
||||||
const fileSize = await NTQQApi.getFileSize(filePath);
|
|
||||||
return {
|
|
||||||
md5,
|
|
||||||
fileName,
|
|
||||||
path: mediaPath,
|
|
||||||
fileSize
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static async downloadMedia(msgId: string, chatType: ChatType, peerUid: string, elementId: string, thumbPath: string, sourcePath: string) {
|
|
||||||
// 用于下载收到的消息中的图片等
|
|
||||||
if (fs.existsSync(sourcePath)) {
|
|
||||||
return sourcePath
|
|
||||||
}
|
|
||||||
const apiParams = [
|
|
||||||
{
|
|
||||||
getReq: {
|
|
||||||
msgId: msgId,
|
|
||||||
chatType: chatType,
|
|
||||||
peerUid: peerUid,
|
|
||||||
elementId: elementId,
|
|
||||||
thumbSize: 0,
|
|
||||||
downloadType: 1,
|
|
||||||
filePath: thumbPath,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
undefined,
|
|
||||||
]
|
|
||||||
// log("需要下载media", sourcePath);
|
|
||||||
await callNTQQApi({
|
|
||||||
methodName: NTQQApiMethod.DOWNLOAD_MEDIA,
|
|
||||||
args: apiParams,
|
|
||||||
cbCmd: ReceiveCmd.MEDIA_DOWNLOAD_COMPLETE,
|
|
||||||
cmdCB: (payload: { notifyInfo: { filePath: string } }) => {
|
|
||||||
// log("media 下载完成判断", payload.notifyInfo.filePath, sourcePath);
|
|
||||||
return payload.notifyInfo.filePath == sourcePath;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return sourcePath
|
|
||||||
}
|
|
||||||
|
|
||||||
static async recallMsg(peer: Peer, msgIds: string[]) {
|
|
||||||
return await callNTQQApi({
|
|
||||||
methodName: NTQQApiMethod.RECALL_MSG,
|
|
||||||
args: [{
|
|
||||||
peer,
|
|
||||||
msgIds
|
|
||||||
}, null]
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
static async sendMsg(peer: Peer, msgElements: SendMessageElement[], waitComplete = true, timeout = 10000) {
|
|
||||||
const peerUid = peer.peerUid
|
|
||||||
|
|
||||||
// 等待上一个相同的peer发送完
|
|
||||||
let checkLastSendUsingTime = 0;
|
|
||||||
const waitLastSend = async () => {
|
|
||||||
if (checkLastSendUsingTime > timeout) {
|
|
||||||
throw ("发送超时")
|
|
||||||
}
|
|
||||||
let lastSending = sendMessagePool[peer.peerUid]
|
|
||||||
if (lastSending) {
|
|
||||||
// log("有正在发送的消息,等待中...")
|
|
||||||
await sleep(500);
|
|
||||||
checkLastSendUsingTime += 500;
|
|
||||||
return await waitLastSend();
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await waitLastSend();
|
|
||||||
|
|
||||||
let sentMessage: RawMessage = null;
|
|
||||||
sendMessagePool[peerUid] = async (rawMessage: RawMessage) => {
|
|
||||||
delete sendMessagePool[peerUid];
|
|
||||||
sentMessage = rawMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
let checkSendCompleteUsingTime = 0;
|
|
||||||
const checkSendComplete = async (): Promise<RawMessage> => {
|
|
||||||
if (sentMessage) {
|
|
||||||
if (waitComplete) {
|
|
||||||
if ((await dbUtil.getMsgByLongId(sentMessage.msgId)).sendStatus == 2) {
|
|
||||||
return sentMessage
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return sentMessage
|
|
||||||
}
|
|
||||||
// log(`给${peerUid}发送消息成功`)
|
|
||||||
}
|
|
||||||
checkSendCompleteUsingTime += 500
|
|
||||||
if (checkSendCompleteUsingTime > timeout) {
|
|
||||||
throw ('发送超时')
|
|
||||||
}
|
|
||||||
await sleep(500)
|
|
||||||
return await checkSendComplete()
|
|
||||||
}
|
|
||||||
|
|
||||||
callNTQQApi({
|
|
||||||
methodName: NTQQApiMethod.SEND_MSG,
|
|
||||||
args: [{
|
|
||||||
msgId: "0",
|
|
||||||
peer, msgElements,
|
|
||||||
msgAttributeInfos: new Map(),
|
|
||||||
}, null]
|
|
||||||
}).then()
|
|
||||||
return await checkSendComplete()
|
|
||||||
}
|
|
||||||
|
|
||||||
static async forwardMsg(srcPeer: Peer, destPeer: Peer, msgIds: string[]) {
|
|
||||||
return await callNTQQApi<GeneralCallResult>({
|
|
||||||
methodName: NTQQApiMethod.FORWARD_MSG,
|
|
||||||
args: [
|
|
||||||
{
|
|
||||||
msgIds: msgIds,
|
|
||||||
srcContact: srcPeer,
|
|
||||||
dstContacts: [
|
|
||||||
destPeer
|
|
||||||
],
|
|
||||||
commentElements: [],
|
|
||||||
msgAttributeInfos: new Map()
|
|
||||||
},
|
|
||||||
null,
|
|
||||||
]
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static async multiForwardMsg(srcPeer: Peer, destPeer: Peer, msgIds: string[]) {
|
|
||||||
const msgInfos = msgIds.map(id => {
|
|
||||||
return {msgId: id, senderShowName: selfInfo.nick}
|
|
||||||
})
|
|
||||||
const apiArgs = [
|
|
||||||
{
|
|
||||||
msgInfos,
|
|
||||||
srcContact: srcPeer,
|
|
||||||
dstContact: destPeer,
|
|
||||||
commentElements: [],
|
|
||||||
msgAttributeInfos: new Map()
|
|
||||||
},
|
|
||||||
null,
|
|
||||||
]
|
|
||||||
return await new Promise<RawMessage>((resolve, reject) => {
|
|
||||||
let complete = false
|
|
||||||
setTimeout(() => {
|
|
||||||
if (!complete) {
|
|
||||||
reject("转发消息超时");
|
|
||||||
}
|
|
||||||
}, 5000)
|
|
||||||
registerReceiveHook(ReceiveCmd.SELF_SEND_MSG, async (payload: { msgRecord: RawMessage }) => {
|
|
||||||
const msg = payload.msgRecord
|
|
||||||
// 需要判断它是转发的消息,并且识别到是当前转发的这一条
|
|
||||||
const arkElement = msg.elements.find(ele => ele.arkElement)
|
|
||||||
if (!arkElement) {
|
|
||||||
// log("收到的不是转发消息")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
const forwardData: any = JSON.parse(arkElement.arkElement.bytesData)
|
|
||||||
if (forwardData.app != 'com.tencent.multimsg') {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (msg.peerUid == destPeer.peerUid && msg.senderUid == selfInfo.uid) {
|
|
||||||
complete = true
|
|
||||||
await dbUtil.addMsg(msg)
|
|
||||||
resolve(msg)
|
|
||||||
log('转发消息成功:', payload)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
callNTQQApi<GeneralCallResult>({
|
|
||||||
methodName: NTQQApiMethod.MULTI_FORWARD_MSG,
|
|
||||||
args: apiArgs
|
|
||||||
}).then(result => {
|
|
||||||
log("转发消息结果:", result, apiArgs)
|
|
||||||
if (result.result !== 0) {
|
|
||||||
complete = true;
|
|
||||||
reject("转发消息失败," + JSON.stringify(result));
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
static async getGroupNotifies() {
|
|
||||||
// 获取管理员变更
|
|
||||||
// 加群通知,退出通知,需要管理员权限
|
|
||||||
callNTQQApi<GeneralCallResult>({
|
|
||||||
methodName: ReceiveCmd.GROUP_NOTIFY,
|
|
||||||
classNameIsRegister: true,
|
|
||||||
}).then()
|
|
||||||
return await callNTQQApi<GroupNotifies>({
|
|
||||||
methodName: NTQQApiMethod.GET_GROUP_NOTICE,
|
|
||||||
cbCmd: ReceiveCmd.GROUP_NOTIFY,
|
|
||||||
afterFirstCmd: false,
|
|
||||||
args: [
|
|
||||||
{"doubt": false, "startSeq": "", "number": 14},
|
|
||||||
null
|
|
||||||
]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
static async getGroupIgnoreNotifies() {
|
|
||||||
await NTQQApi.getGroupNotifies();
|
|
||||||
const result = callNTQQApi<GroupNotifies>({
|
|
||||||
className: NTQQApiClass.WINDOW_API,
|
|
||||||
methodName: NTQQApiMethod.OPEN_EXTRA_WINDOW,
|
|
||||||
cbCmd: ReceiveCmd.GROUP_NOTIFY,
|
|
||||||
afterFirstCmd: false,
|
|
||||||
args: [
|
|
||||||
"GroupNotifyFilterWindow"
|
|
||||||
]
|
|
||||||
})
|
|
||||||
// 关闭窗口
|
|
||||||
setTimeout(() => {
|
|
||||||
for (const w of BrowserWindow.getAllWindows()) {
|
|
||||||
// log("close window", w.webContents.getURL())
|
|
||||||
if (w.webContents.getURL().indexOf("#/notify-filter/") != -1) {
|
|
||||||
w.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, 2000);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
static async handleGroupRequest(seq: string, operateType: GroupRequestOperateTypes, reason?: string) {
|
|
||||||
const notify: GroupNotify = await dbUtil.getGroupNotify(seq)
|
|
||||||
if (!notify) {
|
|
||||||
throw `${seq}对应的加群通知不存在`
|
|
||||||
}
|
|
||||||
// delete groupNotifies[seq];
|
|
||||||
return await callNTQQApi<GeneralCallResult>({
|
|
||||||
methodName: NTQQApiMethod.HANDLE_GROUP_REQUEST,
|
|
||||||
args: [
|
|
||||||
{
|
|
||||||
"doubt": false,
|
|
||||||
"operateMsg": {
|
|
||||||
"operateType": operateType, // 2 拒绝
|
|
||||||
"targetMsg": {
|
|
||||||
"seq": seq, // 通知序列号
|
|
||||||
"type": notify.type,
|
|
||||||
"groupCode": notify.group.groupCode,
|
|
||||||
"postscript": reason
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
null
|
|
||||||
]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
static async quitGroup(groupQQ: string) {
|
|
||||||
await callNTQQApi<GeneralCallResult>({
|
|
||||||
methodName: NTQQApiMethod.QUIT_GROUP,
|
|
||||||
args: [
|
|
||||||
{"groupCode": groupQQ},
|
|
||||||
null
|
|
||||||
]
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
static async handleFriendRequest(sourceId: number, accept: boolean,) {
|
|
||||||
const request: FriendRequest = friendRequests[sourceId]
|
|
||||||
if (!request) {
|
|
||||||
throw `sourceId ${sourceId}, 对应的好友请求不存在`
|
|
||||||
}
|
|
||||||
const result = await callNTQQApi<GeneralCallResult>({
|
|
||||||
methodName: NTQQApiMethod.HANDLE_FRIEND_REQUEST,
|
|
||||||
args: [
|
|
||||||
{
|
|
||||||
"approvalInfo": {
|
|
||||||
"friendUid": request.friendUid,
|
|
||||||
"reqTime": request.reqTime,
|
|
||||||
accept
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
})
|
|
||||||
delete friendRequests[sourceId];
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
static async kickMember(groupQQ: string, kickUids: string[], refuseForever: boolean = false, kickReason: string = '') {
|
|
||||||
return await callNTQQApi<GeneralCallResult>(
|
|
||||||
{
|
|
||||||
methodName: NTQQApiMethod.KICK_MEMBER,
|
|
||||||
args: [
|
|
||||||
{
|
|
||||||
groupCode: groupQQ,
|
|
||||||
kickUids,
|
|
||||||
refuseForever,
|
|
||||||
kickReason,
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
static async banMember(groupQQ: string, memList: Array<{ uid: string, timeStamp: number }>) {
|
|
||||||
// timeStamp为秒数, 0为解除禁言
|
|
||||||
return await callNTQQApi<GeneralCallResult>(
|
|
||||||
{
|
|
||||||
methodName: NTQQApiMethod.MUTE_MEMBER,
|
|
||||||
args: [
|
|
||||||
{
|
|
||||||
groupCode: groupQQ,
|
|
||||||
memList,
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
static async banGroup(groupQQ: string, shutUp: boolean) {
|
|
||||||
return await callNTQQApi<GeneralCallResult>({
|
|
||||||
methodName: NTQQApiMethod.MUTE_GROUP,
|
|
||||||
args: [
|
|
||||||
{
|
|
||||||
groupCode: groupQQ,
|
|
||||||
shutUp
|
|
||||||
}, null
|
|
||||||
]
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
static async setMemberCard(groupQQ: string, memberUid: string, cardName: string) {
|
|
||||||
return await callNTQQApi<GeneralCallResult>({
|
|
||||||
methodName: NTQQApiMethod.SET_MEMBER_CARD,
|
|
||||||
args: [
|
|
||||||
{
|
|
||||||
groupCode: groupQQ,
|
|
||||||
uid: memberUid,
|
|
||||||
cardName
|
|
||||||
}, null
|
|
||||||
]
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
static async setMemberRole(groupQQ: string, memberUid: string, role: GroupMemberRole) {
|
|
||||||
return await callNTQQApi<GeneralCallResult>({
|
|
||||||
methodName: NTQQApiMethod.SET_MEMBER_ROLE,
|
|
||||||
args: [
|
|
||||||
{
|
|
||||||
groupCode: groupQQ,
|
|
||||||
uid: memberUid,
|
|
||||||
role
|
|
||||||
}, null
|
|
||||||
]
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
static async setGroupName(groupQQ: string, groupName: string) {
|
|
||||||
return await callNTQQApi<GeneralCallResult>({
|
|
||||||
methodName: NTQQApiMethod.SET_GROUP_NAME,
|
|
||||||
args: [
|
|
||||||
{
|
|
||||||
groupCode: groupQQ,
|
|
||||||
groupName
|
|
||||||
}, null
|
|
||||||
]
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
static async call(className: NTQQApiClass, cmdName: string, args: any[],) {
|
static async call(className: NTQQApiClass, cmdName: string, args: any[],) {
|
||||||
return await callNTQQApi<GeneralCallResult>({
|
return await callNTQQApi<GeneralCallResult>({
|
||||||
className,
|
className,
|
||||||
@@ -775,123 +178,4 @@ export class NTQQApi {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
static async setGroupTitle(groupQQ: string, uid: string, title: string) {
|
|
||||||
return await callNTQQApi<GeneralCallResult>({
|
|
||||||
methodName: NTQQApiMethod.SET_GROUP_TITLE,
|
|
||||||
args: [
|
|
||||||
{
|
|
||||||
groupCode: groupQQ,
|
|
||||||
uid,
|
|
||||||
title
|
|
||||||
}, null
|
|
||||||
]
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
static publishGroupBulletin(groupQQ: string, title: string, content: string) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static async setCacheSilentScan(isSilent: boolean = true) {
|
|
||||||
return await callNTQQApi<GeneralCallResult>({
|
|
||||||
methodName: NTQQApiMethod.CACHE_SET_SILENCE,
|
|
||||||
args: [{
|
|
||||||
isSilent
|
|
||||||
}, null]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
static addCacheScannedPaths(pathMap: object = {}) {
|
|
||||||
return callNTQQApi<GeneralCallResult>({
|
|
||||||
methodName: NTQQApiMethod.CACHE_ADD_SCANNED_PATH,
|
|
||||||
args: [{
|
|
||||||
pathMap: {...pathMap},
|
|
||||||
}, null]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
static scanCache() {
|
|
||||||
callNTQQApi<GeneralCallResult>({
|
|
||||||
methodName: ReceiveCmd.CACHE_SCAN_FINISH,
|
|
||||||
classNameIsRegister: true,
|
|
||||||
}).then();
|
|
||||||
return callNTQQApi<CacheScanResult>({
|
|
||||||
methodName: NTQQApiMethod.CACHE_SCAN,
|
|
||||||
args: [null, null],
|
|
||||||
timeoutSecond: 300,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
static getHotUpdateCachePath() {
|
|
||||||
return callNTQQApi<string>({
|
|
||||||
className: NTQQApiClass.HOTUPDATE_API,
|
|
||||||
methodName: NTQQApiMethod.CACHE_PATH_HOT_UPDATE
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
static getDesktopTmpPath() {
|
|
||||||
return callNTQQApi<string>({
|
|
||||||
className: NTQQApiClass.BUSINESS_API,
|
|
||||||
methodName: NTQQApiMethod.CACHE_PATH_DESKTOP_TEMP
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
static getCacheSessionPathList() {
|
|
||||||
return callNTQQApi<{
|
|
||||||
key: string,
|
|
||||||
value: string
|
|
||||||
}[]>({
|
|
||||||
className: NTQQApiClass.OS_API,
|
|
||||||
methodName: NTQQApiMethod.CACHE_PATH_SESSION,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
static clearCache(cacheKeys: Array<string> = ['tmp', 'hotUpdate']) {
|
|
||||||
return callNTQQApi<any>({ // TODO: 目前还不知道真正的返回值是什么
|
|
||||||
methodName: NTQQApiMethod.CACHE_CLEAR,
|
|
||||||
args: [{
|
|
||||||
keys: cacheKeys
|
|
||||||
}, null]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
static getChatCacheList(type: ChatType, pageSize: number = 1000, pageIndex: number = 0) {
|
|
||||||
return new Promise<ChatCacheList>((res, rej) => {
|
|
||||||
callNTQQApi<ChatCacheList>({
|
|
||||||
methodName: NTQQApiMethod.CACHE_CHAT_GET,
|
|
||||||
args: [{
|
|
||||||
chatType: type,
|
|
||||||
pageSize,
|
|
||||||
order: 1,
|
|
||||||
pageIndex
|
|
||||||
}, null]
|
|
||||||
}).then(list => res(list))
|
|
||||||
.catch(e => rej(e));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
static getFileCacheInfo(fileType: CacheFileType, pageSize: number = 1000, lastRecord?: CacheFileListItem) {
|
|
||||||
const _lastRecord = lastRecord ? lastRecord : {fileType: fileType};
|
|
||||||
|
|
||||||
return callNTQQApi<CacheFileList>({
|
|
||||||
methodName: NTQQApiMethod.CACHE_FILE_GET,
|
|
||||||
args: [{
|
|
||||||
fileType: fileType,
|
|
||||||
restart: true,
|
|
||||||
pageSize: pageSize,
|
|
||||||
order: 1,
|
|
||||||
lastRecord: _lastRecord,
|
|
||||||
}, null]
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
static async clearChatCache(chats: ChatCacheListItemBasic[] = [], fileKeys: string[] = []) {
|
|
||||||
return await callNTQQApi<GeneralCallResult>({
|
|
||||||
methodName: NTQQApiMethod.CACHE_CHAT_CLEAR,
|
|
||||||
args: [{
|
|
||||||
chats,
|
|
||||||
fileKeys
|
|
||||||
}, null]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
65
src/ntqqapi/types/cache.ts
Normal file
65
src/ntqqapi/types/cache.ts
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
import {ChatType} from "./msg";
|
||||||
|
|
||||||
|
export interface CacheScanResult {
|
||||||
|
result: number,
|
||||||
|
size: [ // 单位为字节
|
||||||
|
string, // 系统总存储空间
|
||||||
|
string, // 系统可用存储空间
|
||||||
|
string, // 系统已用存储空间
|
||||||
|
string, // QQ总大小
|
||||||
|
string, // 「聊天与文件」大小
|
||||||
|
string, // 未知
|
||||||
|
string, // 「缓存数据」大小
|
||||||
|
string, // 「其他数据」大小
|
||||||
|
string, // 未知
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ChatCacheList {
|
||||||
|
pageCount: number,
|
||||||
|
infos: ChatCacheListItem[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ChatCacheListItem {
|
||||||
|
chatType: ChatType,
|
||||||
|
basicChatCacheInfo: ChatCacheListItemBasic,
|
||||||
|
guildChatCacheInfo: unknown[] // TODO: 没用过频道所以不知道这里边的详细内容
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ChatCacheListItemBasic {
|
||||||
|
chatSize: string,
|
||||||
|
chatTime: string,
|
||||||
|
uid: string,
|
||||||
|
uin: string,
|
||||||
|
remarkName: string,
|
||||||
|
nickName: string,
|
||||||
|
chatType?: ChatType,
|
||||||
|
isChecked?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum CacheFileType {
|
||||||
|
IMAGE = 0,
|
||||||
|
VIDEO = 1,
|
||||||
|
AUDIO = 2,
|
||||||
|
DOCUMENT = 3,
|
||||||
|
OTHER = 4,
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CacheFileList {
|
||||||
|
infos: CacheFileListItem[],
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CacheFileListItem {
|
||||||
|
fileSize: string,
|
||||||
|
fileTime: string,
|
||||||
|
fileKey: string,
|
||||||
|
elementId: string,
|
||||||
|
elementIdStr: string,
|
||||||
|
fileType: CacheFileType,
|
||||||
|
path: string,
|
||||||
|
fileName: string,
|
||||||
|
senderId: string,
|
||||||
|
previewPath: string,
|
||||||
|
senderName: string,
|
||||||
|
isChecked?: boolean,
|
||||||
|
}
|
55
src/ntqqapi/types/group.ts
Normal file
55
src/ntqqapi/types/group.ts
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
import {QQLevel, Sex} from "./user";
|
||||||
|
|
||||||
|
export interface Group {
|
||||||
|
groupCode: string,
|
||||||
|
maxMember: number,
|
||||||
|
memberCount: number,
|
||||||
|
groupName: string,
|
||||||
|
groupStatus: 0,
|
||||||
|
memberRole: 2,
|
||||||
|
isTop: boolean,
|
||||||
|
toppedTimestamp: "0",
|
||||||
|
privilegeFlag: number, //65760
|
||||||
|
isConf: boolean,
|
||||||
|
hasModifyConfGroupFace: boolean,
|
||||||
|
hasModifyConfGroupName: boolean,
|
||||||
|
remarkName: string,
|
||||||
|
hasMemo: boolean,
|
||||||
|
groupShutupExpireTime: string, //"0",
|
||||||
|
personShutupExpireTime: string, //"0",
|
||||||
|
discussToGroupUin: string, //"0",
|
||||||
|
discussToGroupMaxMsgSeq: number,
|
||||||
|
discussToGroupTime: number,
|
||||||
|
groupFlagExt: number, //1073938496,
|
||||||
|
authGroupType: number, //0,
|
||||||
|
groupCreditLevel: number, //0,
|
||||||
|
groupFlagExt3: number, //0,
|
||||||
|
groupOwnerId: {
|
||||||
|
"memberUin": string, //"0",
|
||||||
|
"memberUid": string, //"u_fbf8N7aeuZEnUiJAbQ9R8Q"
|
||||||
|
},
|
||||||
|
members: GroupMember[] // 原始数据是没有这个的,为了方便自己加了这个字段
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum GroupMemberRole {
|
||||||
|
normal = 2,
|
||||||
|
admin = 3,
|
||||||
|
owner = 4
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface GroupMember {
|
||||||
|
avatarPath: string;
|
||||||
|
cardName: string;
|
||||||
|
cardType: number;
|
||||||
|
isDelete: boolean;
|
||||||
|
nick: string;
|
||||||
|
qid: string;
|
||||||
|
remark: string;
|
||||||
|
role: GroupMemberRole; // 群主:4, 管理员:3,群员:2
|
||||||
|
shutUpTime: number; // 禁言时间,单位是什么暂时不清楚
|
||||||
|
uid: string; // 加密的字符串
|
||||||
|
uin: string; // QQ号
|
||||||
|
isRobot: boolean;
|
||||||
|
sex?: Sex
|
||||||
|
qqLevel?: QQLevel
|
||||||
|
}
|
7
src/ntqqapi/types/index.ts
Normal file
7
src/ntqqapi/types/index.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
|
||||||
|
export * from './user';
|
||||||
|
export * from './group';
|
||||||
|
export * from './msg';
|
||||||
|
export * from './notify';
|
||||||
|
export * from './cache';
|
||||||
|
|
@@ -1,70 +1,4 @@
|
|||||||
export interface User {
|
import {GroupMemberRole} from "./group";
|
||||||
uid: string; // 加密的字符串
|
|
||||||
uin: string; // QQ号
|
|
||||||
nick: string;
|
|
||||||
avatarUrl?: string;
|
|
||||||
longNick?: string; // 签名
|
|
||||||
remark?: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface SelfInfo extends User {
|
|
||||||
online?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Friend extends User {
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Group {
|
|
||||||
groupCode: string,
|
|
||||||
maxMember: number,
|
|
||||||
memberCount: number,
|
|
||||||
groupName: string,
|
|
||||||
groupStatus: 0,
|
|
||||||
memberRole: 2,
|
|
||||||
isTop: boolean,
|
|
||||||
toppedTimestamp: "0",
|
|
||||||
privilegeFlag: number, //65760
|
|
||||||
isConf: boolean,
|
|
||||||
hasModifyConfGroupFace: boolean,
|
|
||||||
hasModifyConfGroupName: boolean,
|
|
||||||
remarkName: string,
|
|
||||||
hasMemo: boolean,
|
|
||||||
groupShutupExpireTime: string, //"0",
|
|
||||||
personShutupExpireTime: string, //"0",
|
|
||||||
discussToGroupUin: string, //"0",
|
|
||||||
discussToGroupMaxMsgSeq: number,
|
|
||||||
discussToGroupTime: number,
|
|
||||||
groupFlagExt: number, //1073938496,
|
|
||||||
authGroupType: number, //0,
|
|
||||||
groupCreditLevel: number, //0,
|
|
||||||
groupFlagExt3: number, //0,
|
|
||||||
groupOwnerId: {
|
|
||||||
"memberUin": string, //"0",
|
|
||||||
"memberUid": string, //"u_fbf8N7aeuZEnUiJAbQ9R8Q"
|
|
||||||
},
|
|
||||||
members: GroupMember[] // 原始数据是没有这个的,为了方便自己加了这个字段
|
|
||||||
}
|
|
||||||
|
|
||||||
export enum GroupMemberRole {
|
|
||||||
normal = 2,
|
|
||||||
admin = 3,
|
|
||||||
owner = 4
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface GroupMember {
|
|
||||||
avatarPath: string;
|
|
||||||
cardName: string;
|
|
||||||
cardType: number;
|
|
||||||
isDelete: boolean;
|
|
||||||
nick: string;
|
|
||||||
qid: string;
|
|
||||||
remark: string;
|
|
||||||
role: GroupMemberRole; // 群主:4, 管理员:3,群员:2
|
|
||||||
shutUpTime: number; // 禁言时间,单位是什么暂时不清楚
|
|
||||||
uid: string; // 加密的字符串
|
|
||||||
uin: string; // QQ号
|
|
||||||
isRobot: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export enum ElementType {
|
export enum ElementType {
|
||||||
TEXT = 1,
|
TEXT = 1,
|
||||||
@@ -178,6 +112,7 @@ export interface SendVideoElement {
|
|||||||
elementId: "",
|
elementId: "",
|
||||||
videoElement: VideoElement
|
videoElement: VideoElement
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SendArkElement {
|
export interface SendArkElement {
|
||||||
elementType: ElementType.ARK,
|
elementType: ElementType.ARK,
|
||||||
elementId: "",
|
elementId: "",
|
||||||
@@ -243,7 +178,12 @@ export interface PicElement {
|
|||||||
md5HexStr?: string;
|
md5HexStr?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum GrayTipElementSubType {
|
||||||
|
INVITE_NEW_MEMBER = 12,
|
||||||
|
}
|
||||||
|
|
||||||
export interface GrayTipElement {
|
export interface GrayTipElement {
|
||||||
|
subElementType: GrayTipElementSubType;
|
||||||
revokeElement: {
|
revokeElement: {
|
||||||
operatorRole: string;
|
operatorRole: string;
|
||||||
operatorUid: string;
|
operatorUid: string;
|
||||||
@@ -253,7 +193,10 @@ export interface GrayTipElement {
|
|||||||
wording: string; // 自定义的撤回提示语
|
wording: string; // 自定义的撤回提示语
|
||||||
}
|
}
|
||||||
aioOpGrayTipElement: TipAioOpGrayTipElement,
|
aioOpGrayTipElement: TipAioOpGrayTipElement,
|
||||||
groupElement: TipGroupElement
|
groupElement: TipGroupElement,
|
||||||
|
xmlElement: {
|
||||||
|
content: string;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface FaceElement {
|
export interface FaceElement {
|
||||||
@@ -374,131 +317,4 @@ export interface RawMessage {
|
|||||||
videoElement: VideoElement;
|
videoElement: VideoElement;
|
||||||
fileElement: FileElement;
|
fileElement: FileElement;
|
||||||
}[];
|
}[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum GroupNotifyTypes {
|
|
||||||
INVITE_ME = 1,
|
|
||||||
INVITED_JOIN = 4, // 有人接受了邀请入群
|
|
||||||
JOIN_REQUEST = 7,
|
|
||||||
ADMIN_SET = 8,
|
|
||||||
ADMIN_UNSET = 12,
|
|
||||||
MEMBER_EXIT = 11, // 主动退出?
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface GroupNotifies {
|
|
||||||
doubt: boolean,
|
|
||||||
nextStartSeq: string,
|
|
||||||
notifies: GroupNotify[],
|
|
||||||
}
|
|
||||||
|
|
||||||
export enum GroupNotifyStatus {
|
|
||||||
IGNORE = 0,
|
|
||||||
WAIT_HANDLE = 1,
|
|
||||||
APPROVE = 2,
|
|
||||||
REJECT = 3
|
|
||||||
}
|
|
||||||
export interface GroupNotify {
|
|
||||||
time: number; // 自己添加的字段,时间戳,毫秒, 用于判断收到短时间内收到重复的notify
|
|
||||||
seq: string, // 唯一标识符,转成数字再除以1000应该就是时间戳?
|
|
||||||
type: GroupNotifyTypes,
|
|
||||||
status: GroupNotifyStatus, // 0是已忽略?,1是未处理,2是已同意
|
|
||||||
group: { groupCode: string, groupName: string },
|
|
||||||
user1: { uid: string, nickName: string }, // 被设置管理员的人
|
|
||||||
user2: { uid: string, nickName: string }, // 操作者
|
|
||||||
actionUser: { uid: string, nickName: string }, //未知
|
|
||||||
actionTime: string,
|
|
||||||
invitationExt: {
|
|
||||||
srcType: number, // 0?未知
|
|
||||||
groupCode: string, waitStatus: number
|
|
||||||
},
|
|
||||||
postscript: string, // 加群用户填写的验证信息
|
|
||||||
repeatSeqs: [],
|
|
||||||
warningTips: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export enum GroupRequestOperateTypes {
|
|
||||||
approve = 1,
|
|
||||||
reject = 2
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface FriendRequest {
|
|
||||||
friendUid: string,
|
|
||||||
reqTime: string, // 时间戳,秒
|
|
||||||
extWords: string, // 申请人填写的验证消息
|
|
||||||
isUnread: boolean,
|
|
||||||
friendNick: string,
|
|
||||||
sourceId: number,
|
|
||||||
groupCode: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface FriendRequestNotify {
|
|
||||||
data: {
|
|
||||||
unreadNums: number,
|
|
||||||
buddyReqs: FriendRequest[]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface CacheScanResult {
|
|
||||||
result: number,
|
|
||||||
size: [ // 单位为字节
|
|
||||||
string, // 系统总存储空间
|
|
||||||
string, // 系统可用存储空间
|
|
||||||
string, // 系统已用存储空间
|
|
||||||
string, // QQ总大小
|
|
||||||
string, // 「聊天与文件」大小
|
|
||||||
string, // 未知
|
|
||||||
string, // 「缓存数据」大小
|
|
||||||
string, // 「其他数据」大小
|
|
||||||
string, // 未知
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ChatCacheList {
|
|
||||||
pageCount: number,
|
|
||||||
infos: ChatCacheListItem[]
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ChatCacheListItem {
|
|
||||||
chatType: ChatType,
|
|
||||||
basicChatCacheInfo: ChatCacheListItemBasic,
|
|
||||||
guildChatCacheInfo: unknown[] // TODO: 没用过频道所以不知道这里边的详细内容
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ChatCacheListItemBasic {
|
|
||||||
chatSize: string,
|
|
||||||
chatTime: string,
|
|
||||||
uid: string,
|
|
||||||
uin: string,
|
|
||||||
remarkName: string,
|
|
||||||
nickName: string,
|
|
||||||
chatType?: ChatType,
|
|
||||||
isChecked?: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
export enum CacheFileType {
|
|
||||||
IMAGE = 0,
|
|
||||||
VIDEO = 1,
|
|
||||||
AUDIO = 2,
|
|
||||||
DOCUMENT = 3,
|
|
||||||
OTHER = 4,
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface CacheFileList {
|
|
||||||
infos: CacheFileListItem[],
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface CacheFileListItem {
|
|
||||||
fileSize: string,
|
|
||||||
fileTime: string,
|
|
||||||
fileKey: string,
|
|
||||||
elementId: string,
|
|
||||||
elementIdStr: string,
|
|
||||||
fileType: CacheFileType,
|
|
||||||
path: string,
|
|
||||||
fileName: string,
|
|
||||||
senderId: string,
|
|
||||||
previewPath: string,
|
|
||||||
senderName: string,
|
|
||||||
isChecked?: boolean,
|
|
||||||
}
|
|
64
src/ntqqapi/types/notify.ts
Normal file
64
src/ntqqapi/types/notify.ts
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
|
||||||
|
export enum GroupNotifyTypes {
|
||||||
|
INVITE_ME = 1,
|
||||||
|
INVITED_JOIN = 4, // 有人接受了邀请入群
|
||||||
|
JOIN_REQUEST = 7,
|
||||||
|
ADMIN_SET = 8,
|
||||||
|
ADMIN_UNSET = 12,
|
||||||
|
MEMBER_EXIT = 11, // 主动退出?
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface GroupNotifies {
|
||||||
|
doubt: boolean,
|
||||||
|
nextStartSeq: string,
|
||||||
|
notifies: GroupNotify[],
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum GroupNotifyStatus {
|
||||||
|
IGNORE = 0,
|
||||||
|
WAIT_HANDLE = 1,
|
||||||
|
APPROVE = 2,
|
||||||
|
REJECT = 3
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface GroupNotify {
|
||||||
|
time: number; // 自己添加的字段,时间戳,毫秒, 用于判断收到短时间内收到重复的notify
|
||||||
|
seq: string, // 唯一标识符,转成数字再除以1000应该就是时间戳?
|
||||||
|
type: GroupNotifyTypes,
|
||||||
|
status: GroupNotifyStatus, // 0是已忽略?,1是未处理,2是已同意
|
||||||
|
group: { groupCode: string, groupName: string },
|
||||||
|
user1: { uid: string, nickName: string }, // 被设置管理员的人
|
||||||
|
user2: { uid: string, nickName: string }, // 操作者
|
||||||
|
actionUser: { uid: string, nickName: string }, //未知
|
||||||
|
actionTime: string,
|
||||||
|
invitationExt: {
|
||||||
|
srcType: number, // 0?未知
|
||||||
|
groupCode: string, waitStatus: number
|
||||||
|
},
|
||||||
|
postscript: string, // 加群用户填写的验证信息
|
||||||
|
repeatSeqs: [],
|
||||||
|
warningTips: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum GroupRequestOperateTypes {
|
||||||
|
approve = 1,
|
||||||
|
reject = 2
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface FriendRequest {
|
||||||
|
friendUid: string,
|
||||||
|
reqTime: string, // 时间戳,秒
|
||||||
|
extWords: string, // 申请人填写的验证消息
|
||||||
|
isUnread: boolean,
|
||||||
|
friendNick: string,
|
||||||
|
sourceId: number,
|
||||||
|
groupCode: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface FriendRequestNotify {
|
||||||
|
data: {
|
||||||
|
unreadNums: number,
|
||||||
|
buddyReqs: FriendRequest[]
|
||||||
|
}
|
||||||
|
}
|
28
src/ntqqapi/types/user.ts
Normal file
28
src/ntqqapi/types/user.ts
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
export enum Sex {
|
||||||
|
male = 0,
|
||||||
|
female = 2,
|
||||||
|
unknown = 255,
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface QQLevel {
|
||||||
|
"crownNum": number,
|
||||||
|
"sunNum": number,
|
||||||
|
"moonNum": number,
|
||||||
|
"starNum": number
|
||||||
|
}
|
||||||
|
export interface User {
|
||||||
|
uid: string; // 加密的字符串
|
||||||
|
uin: string; // QQ号
|
||||||
|
nick: string;
|
||||||
|
avatarUrl?: string;
|
||||||
|
longNick?: string; // 签名
|
||||||
|
remark?: string;
|
||||||
|
sex?: Sex;
|
||||||
|
"qqLevel"?: QQLevel
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SelfInfo extends User {
|
||||||
|
online?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Friend extends User {}
|
@@ -1,7 +1,8 @@
|
|||||||
import {ActionName, BaseCheckResult} from "./types"
|
import {ActionName, BaseCheckResult} from "./types"
|
||||||
import {OB11Response} from "./utils"
|
import {OB11Response} from "./utils"
|
||||||
import {OB11Return} from "../types";
|
import {OB11Return} from "../types";
|
||||||
import {log} from "../../common/utils";
|
|
||||||
|
import {log} from "../../common/utils/log";
|
||||||
|
|
||||||
class BaseAction<PayloadType, ReturnDataType> {
|
class BaseAction<PayloadType, ReturnDataType> {
|
||||||
actionName: ActionName
|
actionName: ActionName
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "./BaseAction";
|
||||||
import {ActionName} from "./types";
|
import {ActionName} from "./types";
|
||||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import Path from "path";
|
import Path from "path";
|
||||||
import {
|
import {
|
||||||
@@ -9,6 +8,7 @@ import {
|
|||||||
CacheFileType
|
CacheFileType
|
||||||
} from '../../ntqqapi/types';
|
} from '../../ntqqapi/types';
|
||||||
import {dbUtil} from "../../common/db";
|
import {dbUtil} from "../../common/db";
|
||||||
|
import {NTQQFileApi, NTQQFileCacheApi} from "../../ntqqapi/api/file";
|
||||||
|
|
||||||
export default class CleanCache extends BaseAction<void, void> {
|
export default class CleanCache extends BaseAction<void, void> {
|
||||||
actionName = ActionName.CleanCache
|
actionName = ActionName.CleanCache
|
||||||
@@ -19,21 +19,21 @@ export default class CleanCache extends BaseAction<void, void> {
|
|||||||
// dbUtil.clearCache();
|
// dbUtil.clearCache();
|
||||||
const cacheFilePaths: string[] = [];
|
const cacheFilePaths: string[] = [];
|
||||||
|
|
||||||
await NTQQApi.setCacheSilentScan(false);
|
await NTQQFileCacheApi.setCacheSilentScan(false);
|
||||||
|
|
||||||
cacheFilePaths.push((await NTQQApi.getHotUpdateCachePath()));
|
cacheFilePaths.push((await NTQQFileCacheApi.getHotUpdateCachePath()));
|
||||||
cacheFilePaths.push((await NTQQApi.getDesktopTmpPath()));
|
cacheFilePaths.push((await NTQQFileCacheApi.getDesktopTmpPath()));
|
||||||
(await NTQQApi.getCacheSessionPathList()).forEach(e => cacheFilePaths.push(e.value));
|
(await NTQQFileCacheApi.getCacheSessionPathList()).forEach(e => cacheFilePaths.push(e.value));
|
||||||
|
|
||||||
// await NTQQApi.addCacheScannedPaths(); // XXX: 调用就崩溃,原因目前还未知
|
// await NTQQApi.addCacheScannedPaths(); // XXX: 调用就崩溃,原因目前还未知
|
||||||
const cacheScanResult = await NTQQApi.scanCache();
|
const cacheScanResult = await NTQQFileCacheApi.scanCache();
|
||||||
const cacheSize = parseInt(cacheScanResult.size[6]);
|
const cacheSize = parseInt(cacheScanResult.size[6]);
|
||||||
|
|
||||||
if (cacheScanResult.result !== 0) {
|
if (cacheScanResult.result !== 0) {
|
||||||
throw('Something went wrong while scanning cache. Code: ' + cacheScanResult.result);
|
throw('Something went wrong while scanning cache. Code: ' + cacheScanResult.result);
|
||||||
}
|
}
|
||||||
|
|
||||||
await NTQQApi.setCacheSilentScan(true);
|
await NTQQFileCacheApi.setCacheSilentScan(true);
|
||||||
if (cacheSize > 0 && cacheFilePaths.length > 2) { // 存在缓存文件且大小不为 0 时执行清理动作
|
if (cacheSize > 0 && cacheFilePaths.length > 2) { // 存在缓存文件且大小不为 0 时执行清理动作
|
||||||
// await NTQQApi.clearCache([ 'tmp', 'hotUpdate', ...cacheScanResult ]) // XXX: 也是调用就崩溃,调用 fs 删除得了
|
// await NTQQApi.clearCache([ 'tmp', 'hotUpdate', ...cacheScanResult ]) // XXX: 也是调用就崩溃,调用 fs 删除得了
|
||||||
deleteCachePath(cacheFilePaths);
|
deleteCachePath(cacheFilePaths);
|
||||||
@@ -55,11 +55,11 @@ export default class CleanCache extends BaseAction<void, void> {
|
|||||||
const fileTypeAny: any = CacheFileType[name];
|
const fileTypeAny: any = CacheFileType[name];
|
||||||
const fileType: CacheFileType = fileTypeAny;
|
const fileType: CacheFileType = fileTypeAny;
|
||||||
|
|
||||||
cacheFileList.push(...(await NTQQApi.getFileCacheInfo(fileType)).infos.map(file => file.fileKey));
|
cacheFileList.push(...(await NTQQFileCacheApi.getFileCacheInfo(fileType)).infos.map(file => file.fileKey));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 一并清除
|
// 一并清除
|
||||||
await NTQQApi.clearChatCache(chatCacheList, cacheFileList);
|
await NTQQFileCacheApi.clearChatCache(chatCacheList, cacheFileList);
|
||||||
res();
|
res();
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
console.error('清理缓存时发生了错误');
|
console.error('清理缓存时发生了错误');
|
||||||
@@ -89,7 +89,7 @@ function deleteCachePath(pathList: string[]) {
|
|||||||
|
|
||||||
function getCacheList(type: ChatType) { // NOTE: 做这个方法主要是因为目前还不支持针对频道消息的清理
|
function getCacheList(type: ChatType) { // NOTE: 做这个方法主要是因为目前还不支持针对频道消息的清理
|
||||||
return new Promise<Array<ChatCacheListItemBasic>>((res, rej) => {
|
return new Promise<Array<ChatCacheListItemBasic>>((res, rej) => {
|
||||||
NTQQApi.getChatCacheList(type, 1000, 0)
|
NTQQFileCacheApi.getChatCacheList(type, 1000, 0)
|
||||||
.then(data => {
|
.then(data => {
|
||||||
const list = data.infos.filter(e => e.chatType === type && parseInt(e.basicChatCacheInfo.chatSize) > 0);
|
const list = data.infos.filter(e => e.chatType === type && parseInt(e.basicChatCacheInfo.chatSize) > 0);
|
||||||
const result = list.map(e => {
|
const result = list.map(e => {
|
||||||
|
@@ -1,7 +1,8 @@
|
|||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "./BaseAction";
|
||||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
import {NTQQApi} from "../../ntqqapi/ntcall";
|
||||||
import {ActionName} from "./types";
|
import {ActionName} from "./types";
|
||||||
import {log} from "../../common/utils";
|
|
||||||
|
import {log} from "../../common/utils/log";
|
||||||
|
|
||||||
interface Payload {
|
interface Payload {
|
||||||
method: string,
|
method: string,
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import {ActionName} from "./types";
|
import {ActionName} from "./types";
|
||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "./BaseAction";
|
||||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
|
||||||
import {dbUtil} from "../../common/db";
|
import {dbUtil} from "../../common/db";
|
||||||
|
import {NTQQMsgApi} from "../../ntqqapi/api/msg";
|
||||||
|
|
||||||
interface Payload {
|
interface Payload {
|
||||||
message_id: number
|
message_id: number
|
||||||
@@ -12,7 +12,7 @@ class DeleteMsg extends BaseAction<Payload, void> {
|
|||||||
|
|
||||||
protected async _handle(payload: Payload) {
|
protected async _handle(payload: Payload) {
|
||||||
let msg = await dbUtil.getMsgByShortId(payload.message_id)
|
let msg = await dbUtil.getMsgByShortId(payload.message_id)
|
||||||
await NTQQApi.recallMsg({
|
await NTQQMsgApi.recallMsg({
|
||||||
chatType: msg.chatType,
|
chatType: msg.chatType,
|
||||||
peerUid: msg.peerUid
|
peerUid: msg.peerUid
|
||||||
}, [msg.msgId])
|
}, [msg.msgId])
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "./BaseAction";
|
||||||
import {getConfigUtil} from "../../common/utils";
|
|
||||||
import fs from "fs/promises";
|
import fs from "fs/promises";
|
||||||
import {dbUtil} from "../../common/db";
|
import {dbUtil} from "../../common/db";
|
||||||
|
import {getConfigUtil} from "../../common/config";
|
||||||
|
|
||||||
export interface GetFilePayload {
|
export interface GetFilePayload {
|
||||||
file: string // 文件名
|
file: string // 文件名
|
||||||
|
@@ -3,6 +3,9 @@ import {getGroupMember} from "../../common/data";
|
|||||||
import {OB11Constructor} from "../constructor";
|
import {OB11Constructor} from "../constructor";
|
||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "./BaseAction";
|
||||||
import {ActionName} from "./types";
|
import {ActionName} from "./types";
|
||||||
|
import {NTQQUserApi} from "../../ntqqapi/api/user";
|
||||||
|
import {log} from "../../common/utils/log";
|
||||||
|
import {isNull} from "../../common/utils/helper";
|
||||||
|
|
||||||
|
|
||||||
export interface PayloadType {
|
export interface PayloadType {
|
||||||
@@ -16,6 +19,12 @@ class GetGroupMemberInfo extends BaseAction<PayloadType, OB11GroupMember> {
|
|||||||
protected async _handle(payload: PayloadType) {
|
protected async _handle(payload: PayloadType) {
|
||||||
const member = await getGroupMember(payload.group_id.toString(), payload.user_id.toString())
|
const member = await getGroupMember(payload.group_id.toString(), payload.user_id.toString())
|
||||||
if (member) {
|
if (member) {
|
||||||
|
if (isNull(member.sex)){
|
||||||
|
log("获取群成员详细信息")
|
||||||
|
let info = (await NTQQUserApi.getUserDetailInfo(member.uid))
|
||||||
|
log("群成员详细信息结果", info)
|
||||||
|
Object.assign(member, info);
|
||||||
|
}
|
||||||
return OB11Constructor.groupMember(payload.group_id.toString(), member)
|
return OB11Constructor.groupMember(payload.group_id.toString(), member)
|
||||||
} else {
|
} else {
|
||||||
throw (`群成员${payload.user_id}不存在`)
|
throw (`群成员${payload.user_id}不存在`)
|
||||||
|
@@ -1,9 +1,9 @@
|
|||||||
import {OB11GroupMember} from '../types';
|
import {OB11GroupMember} from '../types';
|
||||||
import {getGroup} from "../../common/data";
|
import {getGroup} from "../../common/data";
|
||||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
|
||||||
import {OB11Constructor} from "../constructor";
|
import {OB11Constructor} from "../constructor";
|
||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "./BaseAction";
|
||||||
import {ActionName} from "./types";
|
import {ActionName} from "./types";
|
||||||
|
import {NTQQGroupApi} from "../../ntqqapi/api/group";
|
||||||
|
|
||||||
export interface PayloadType {
|
export interface PayloadType {
|
||||||
group_id: number
|
group_id: number
|
||||||
@@ -17,7 +17,7 @@ class GetGroupMemberList extends BaseAction<PayloadType, OB11GroupMember[]> {
|
|||||||
const group = await getGroup(payload.group_id.toString());
|
const group = await getGroup(payload.group_id.toString());
|
||||||
if (group) {
|
if (group) {
|
||||||
if (!group.members?.length) {
|
if (!group.members?.length) {
|
||||||
group.members = await NTQQApi.getGroupMembers(payload.group_id.toString())
|
group.members = await NTQQGroupApi.getGroupMembers(payload.group_id.toString())
|
||||||
}
|
}
|
||||||
return OB11Constructor.groupMembers(group);
|
return OB11Constructor.groupMembers(group);
|
||||||
} else {
|
} else {
|
||||||
|
@@ -1,7 +1,8 @@
|
|||||||
import SendMsg from "./SendMsg";
|
import SendMsg from "./SendMsg";
|
||||||
import {ActionName, BaseCheckResult} from "./types";
|
import {ActionName, BaseCheckResult} from "./types";
|
||||||
import {OB11PostSendMsg} from "../types";
|
import {OB11PostSendMsg} from "../types";
|
||||||
import {log} from "../../common/utils";
|
|
||||||
|
import {log} from "../../common/utils/log";
|
||||||
|
|
||||||
|
|
||||||
class SendGroupMsg extends SendMsg {
|
class SendGroupMsg extends SendMsg {
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "./BaseAction";
|
||||||
import {getFriend, getUidByUin, uidMaps} from "../../common/data";
|
import {getFriend, getUidByUin, uidMaps} from "../../common/data";
|
||||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
|
||||||
import {ActionName} from "./types";
|
import {ActionName} from "./types";
|
||||||
import {log} from "../../common/utils";
|
import {NTQQFriendApi} from "../../ntqqapi/api/friend";
|
||||||
|
import {log} from "../../common/utils/log";
|
||||||
|
|
||||||
interface Payload {
|
interface Payload {
|
||||||
user_id: number,
|
user_id: number,
|
||||||
@@ -23,7 +23,7 @@ export default class SendLike extends BaseAction<Payload, null> {
|
|||||||
} else {
|
} else {
|
||||||
uid = friend.uid
|
uid = friend.uid
|
||||||
}
|
}
|
||||||
let result = await NTQQApi.likeFriend(uid, parseInt(payload.times?.toString()) || 1);
|
let result = await NTQQFriendApi.likeFriend(uid, parseInt(payload.times?.toString()) || 1);
|
||||||
if (result.result !== 0) {
|
if (result.result !== 0) {
|
||||||
throw result.errMsg
|
throw result.errMsg
|
||||||
}
|
}
|
||||||
|
@@ -7,7 +7,14 @@ import {
|
|||||||
SendArkElement,
|
SendArkElement,
|
||||||
SendMessageElement
|
SendMessageElement
|
||||||
} from "../../ntqqapi/types";
|
} from "../../ntqqapi/types";
|
||||||
import {friends, getFriend, getGroup, getGroupMember, getUidByUin, selfInfo,} from "../../common/data";
|
import {
|
||||||
|
friends,
|
||||||
|
getFriend,
|
||||||
|
getGroup,
|
||||||
|
getGroupMember,
|
||||||
|
getUidByUin,
|
||||||
|
selfInfo,
|
||||||
|
} from "../../common/data";
|
||||||
import {
|
import {
|
||||||
OB11MessageCustomMusic,
|
OB11MessageCustomMusic,
|
||||||
OB11MessageData,
|
OB11MessageData,
|
||||||
@@ -16,16 +23,18 @@ import {
|
|||||||
OB11MessageNode,
|
OB11MessageNode,
|
||||||
OB11PostSendMsg
|
OB11PostSendMsg
|
||||||
} from '../types';
|
} from '../types';
|
||||||
import {NTQQApi, Peer} from "../../ntqqapi/ntcall";
|
import {Peer} from "../../ntqqapi/api/msg";
|
||||||
import {SendMsgElementConstructor} from "../../ntqqapi/constructor";
|
import {SendMsgElementConstructor} from "../../ntqqapi/constructor";
|
||||||
import {uri2local} from "../utils";
|
import {uri2local} from "../utils";
|
||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "./BaseAction";
|
||||||
import {ActionName, BaseCheckResult} from "./types";
|
import {ActionName, BaseCheckResult} from "./types";
|
||||||
import * as fs from "node:fs";
|
import * as fs from "node:fs";
|
||||||
import {log, sleep} from "../../common/utils";
|
|
||||||
import {decodeCQCode} from "../cqcode";
|
import {decodeCQCode} from "../cqcode";
|
||||||
import {dbUtil} from "../../common/db";
|
import {dbUtil} from "../../common/db";
|
||||||
import {ALLOW_SEND_TEMP_MSG} from "../../common/config";
|
import {ALLOW_SEND_TEMP_MSG} from "../../common/config";
|
||||||
|
import {NTQQMsgApi} from "../../ntqqapi/api/msg";
|
||||||
|
import {log} from "../../common/utils/log";
|
||||||
|
import {sleep} from "../../common/utils/helper";
|
||||||
|
|
||||||
function checkSendMessage(sendMsgList: OB11MessageData[]) {
|
function checkSendMessage(sendMsgList: OB11MessageData[]) {
|
||||||
function checkUri(uri: string): boolean {
|
function checkUri(uri: string): boolean {
|
||||||
@@ -86,7 +95,7 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
|||||||
}
|
}
|
||||||
if (payload.user_id && payload.message_type !== "group") {
|
if (payload.user_id && payload.message_type !== "group") {
|
||||||
if (!(await getFriend(payload.user_id))) {
|
if (!(await getFriend(payload.user_id))) {
|
||||||
if (!ALLOW_SEND_TEMP_MSG) {
|
if (!ALLOW_SEND_TEMP_MSG && !(await dbUtil.getReceivedTempUinMap())[payload.user_id.toString()]) {
|
||||||
return {
|
return {
|
||||||
valid: false,
|
valid: false,
|
||||||
message: `不能发送临时消息`
|
message: `不能发送临时消息`
|
||||||
@@ -208,7 +217,7 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
|||||||
}
|
}
|
||||||
log("克隆消息", sendElements)
|
log("克隆消息", sendElements)
|
||||||
try {
|
try {
|
||||||
const nodeMsg = await NTQQApi.sendMsg({
|
const nodeMsg = await NTQQMsgApi.sendMsg({
|
||||||
chatType: ChatType.friend,
|
chatType: ChatType.friend,
|
||||||
peerUid: selfInfo.uid
|
peerUid: selfInfo.uid
|
||||||
}, sendElements, true);
|
}, sendElements, true);
|
||||||
@@ -330,7 +339,7 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
|||||||
// 开发转发
|
// 开发转发
|
||||||
try {
|
try {
|
||||||
log("开发转发", nodeMsgIds)
|
log("开发转发", nodeMsgIds)
|
||||||
return await NTQQApi.multiForwardMsg(srcPeer, destPeer, nodeMsgIds)
|
return await NTQQMsgApi.multiForwardMsg(srcPeer, destPeer, nodeMsgIds)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log("forward failed", e)
|
log("forward failed", e)
|
||||||
return null;
|
return null;
|
||||||
@@ -416,20 +425,16 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
|||||||
if (!isLocal) { // 只删除http和base64转过来的文件
|
if (!isLocal) { // 只删除http和base64转过来的文件
|
||||||
deleteAfterSentFiles.push(path)
|
deleteAfterSentFiles.push(path)
|
||||||
}
|
}
|
||||||
const constructorMap = {
|
|
||||||
[OB11MessageDataType.image]: SendMsgElementConstructor.pic,
|
|
||||||
[OB11MessageDataType.voice]: SendMsgElementConstructor.ptt,
|
|
||||||
[OB11MessageDataType.video]: SendMsgElementConstructor.video,
|
|
||||||
[OB11MessageDataType.file]: SendMsgElementConstructor.file,
|
|
||||||
}
|
|
||||||
if (sendMsg.type === OB11MessageDataType.file) {
|
if (sendMsg.type === OB11MessageDataType.file) {
|
||||||
log("发送文件", path, payloadFileName || fileName)
|
log("发送文件", path, payloadFileName || fileName)
|
||||||
sendElements.push(await SendMsgElementConstructor.file(path, payloadFileName || fileName));
|
sendElements.push(await SendMsgElementConstructor.file(path, payloadFileName || fileName));
|
||||||
} else if (sendMsg.type === OB11MessageDataType.video) {
|
} else if (sendMsg.type === OB11MessageDataType.video) {
|
||||||
log("发送视频", path, payloadFileName || fileName)
|
log("发送视频", path, payloadFileName || fileName)
|
||||||
sendElements.push(await SendMsgElementConstructor.video(path, payloadFileName || fileName));
|
sendElements.push(await SendMsgElementConstructor.video(path, payloadFileName || fileName));
|
||||||
} else {
|
} else if (sendMsg.type === OB11MessageDataType.voice) {
|
||||||
sendElements.push(await constructorMap[sendMsg.type](path));
|
sendElements.push(await SendMsgElementConstructor.ptt(path));
|
||||||
|
}else if (sendMsg.type === OB11MessageDataType.image) {
|
||||||
|
sendElements.push(await SendMsgElementConstructor.pic(path, sendMsg.data.summary || ""));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -449,7 +454,7 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
|||||||
if (!sendElements.length) {
|
if (!sendElements.length) {
|
||||||
throw ("消息体无法解析")
|
throw ("消息体无法解析")
|
||||||
}
|
}
|
||||||
const returnMsg = await NTQQApi.sendMsg(peer, sendElements, waitComplete, 20000);
|
const returnMsg = await NTQQMsgApi.sendMsg(peer, sendElements, waitComplete, 20000);
|
||||||
log("消息发送结果", returnMsg)
|
log("消息发送结果", returnMsg)
|
||||||
returnMsg.msgShortId = await dbUtil.addMsg(returnMsg)
|
returnMsg.msgShortId = await dbUtil.addMsg(returnMsg)
|
||||||
deleteAfterSentFiles.map(f => fs.unlink(f, () => {
|
deleteAfterSentFiles.map(f => fs.unlink(f, () => {
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "./BaseAction";
|
||||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
|
||||||
import {ActionName} from "./types";
|
import {ActionName} from "./types";
|
||||||
|
import {NTQQFriendApi} from "../../ntqqapi/api/friend";
|
||||||
|
|
||||||
interface Payload {
|
interface Payload {
|
||||||
flag: string,
|
flag: string,
|
||||||
@@ -12,7 +12,7 @@ export default class SetFriendAddRequest extends BaseAction<Payload, null> {
|
|||||||
actionName = ActionName.SetFriendAddRequest;
|
actionName = ActionName.SetFriendAddRequest;
|
||||||
|
|
||||||
protected async _handle(payload: Payload): Promise<null> {
|
protected async _handle(payload: Payload): Promise<null> {
|
||||||
await NTQQApi.handleFriendRequest(parseInt(payload.flag), payload.approve)
|
await NTQQFriendApi.handleFriendRequest(parseInt(payload.flag), payload.approve)
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,7 +1,7 @@
|
|||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "./BaseAction";
|
||||||
import {GroupRequestOperateTypes} from "../../ntqqapi/types";
|
import {GroupRequestOperateTypes} from "../../ntqqapi/types";
|
||||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
|
||||||
import {ActionName} from "./types";
|
import {ActionName} from "./types";
|
||||||
|
import {NTQQGroupApi} from "../../ntqqapi/api/group";
|
||||||
|
|
||||||
interface Payload {
|
interface Payload {
|
||||||
flag: string,
|
flag: string,
|
||||||
@@ -16,7 +16,7 @@ export default class SetGroupAddRequest extends BaseAction<Payload, null> {
|
|||||||
|
|
||||||
protected async _handle(payload: Payload): Promise<null> {
|
protected async _handle(payload: Payload): Promise<null> {
|
||||||
const seq = payload.flag.toString();
|
const seq = payload.flag.toString();
|
||||||
await NTQQApi.handleGroupRequest(seq,
|
await NTQQGroupApi.handleGroupRequest(seq,
|
||||||
payload.approve ? GroupRequestOperateTypes.approve : GroupRequestOperateTypes.reject,
|
payload.approve ? GroupRequestOperateTypes.approve : GroupRequestOperateTypes.reject,
|
||||||
payload.reason
|
payload.reason
|
||||||
)
|
)
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "./BaseAction";
|
||||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
|
||||||
import {getGroupMember} from "../../common/data";
|
import {getGroupMember} from "../../common/data";
|
||||||
import {GroupMemberRole} from "../../ntqqapi/types";
|
import {GroupMemberRole} from "../../ntqqapi/types";
|
||||||
import {ActionName} from "./types";
|
import {ActionName} from "./types";
|
||||||
|
import {NTQQGroupApi} from "../../ntqqapi/api/group";
|
||||||
|
|
||||||
interface Payload {
|
interface Payload {
|
||||||
group_id: number,
|
group_id: number,
|
||||||
@@ -18,7 +18,7 @@ export default class SetGroupAdmin extends BaseAction<Payload, null> {
|
|||||||
if (!member) {
|
if (!member) {
|
||||||
throw `群成员${payload.user_id}不存在`
|
throw `群成员${payload.user_id}不存在`
|
||||||
}
|
}
|
||||||
await NTQQApi.setMemberRole(payload.group_id.toString(), member.uid, payload.enable ? GroupMemberRole.admin : GroupMemberRole.normal)
|
await NTQQGroupApi.setMemberRole(payload.group_id.toString(), member.uid, payload.enable ? GroupMemberRole.admin : GroupMemberRole.normal)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,7 +1,7 @@
|
|||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "./BaseAction";
|
||||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
|
||||||
import {getGroupMember} from "../../common/data";
|
import {getGroupMember} from "../../common/data";
|
||||||
import {ActionName} from "./types";
|
import {ActionName} from "./types";
|
||||||
|
import {NTQQGroupApi} from "../../ntqqapi/api/group";
|
||||||
|
|
||||||
interface Payload {
|
interface Payload {
|
||||||
group_id: number,
|
group_id: number,
|
||||||
@@ -17,7 +17,7 @@ export default class SetGroupBan extends BaseAction<Payload, null> {
|
|||||||
if (!member) {
|
if (!member) {
|
||||||
throw `群成员${payload.user_id}不存在`
|
throw `群成员${payload.user_id}不存在`
|
||||||
}
|
}
|
||||||
await NTQQApi.banMember(payload.group_id.toString(),
|
await NTQQGroupApi.banMember(payload.group_id.toString(),
|
||||||
[{uid: member.uid, timeStamp: parseInt(payload.duration.toString())}])
|
[{uid: member.uid, timeStamp: parseInt(payload.duration.toString())}])
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "./BaseAction";
|
||||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
|
||||||
import {getGroupMember} from "../../common/data";
|
import {getGroupMember} from "../../common/data";
|
||||||
import {ActionName} from "./types";
|
import {ActionName} from "./types";
|
||||||
|
import {NTQQGroupApi} from "../../ntqqapi/api/group";
|
||||||
|
|
||||||
interface Payload {
|
interface Payload {
|
||||||
group_id: number,
|
group_id: number,
|
||||||
@@ -17,7 +17,7 @@ export default class SetGroupCard extends BaseAction<Payload, null> {
|
|||||||
if (!member) {
|
if (!member) {
|
||||||
throw `群成员${payload.user_id}不存在`
|
throw `群成员${payload.user_id}不存在`
|
||||||
}
|
}
|
||||||
await NTQQApi.setMemberCard(payload.group_id.toString(), member.uid, payload.card || "")
|
await NTQQGroupApi.setMemberCard(payload.group_id.toString(), member.uid, payload.card || "")
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,7 +1,7 @@
|
|||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "./BaseAction";
|
||||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
|
||||||
import {getGroupMember} from "../../common/data";
|
import {getGroupMember} from "../../common/data";
|
||||||
import {ActionName} from "./types";
|
import {ActionName} from "./types";
|
||||||
|
import {NTQQGroupApi} from "../../ntqqapi/api/group";
|
||||||
|
|
||||||
interface Payload {
|
interface Payload {
|
||||||
group_id: number,
|
group_id: number,
|
||||||
@@ -17,7 +17,7 @@ export default class SetGroupKick extends BaseAction<Payload, null> {
|
|||||||
if (!member) {
|
if (!member) {
|
||||||
throw `群成员${payload.user_id}不存在`
|
throw `群成员${payload.user_id}不存在`
|
||||||
}
|
}
|
||||||
await NTQQApi.kickMember(payload.group_id.toString(), [member.uid], !!payload.reject_add_request);
|
await NTQQGroupApi.kickMember(payload.group_id.toString(), [member.uid], !!payload.reject_add_request);
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,7 +1,7 @@
|
|||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "./BaseAction";
|
||||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
|
||||||
import {log} from "../../common/utils";
|
|
||||||
import {ActionName} from "./types";
|
import {ActionName} from "./types";
|
||||||
|
import {NTQQGroupApi} from "../../ntqqapi/api/group";
|
||||||
|
import {log} from "../../common/utils/log";
|
||||||
|
|
||||||
interface Payload {
|
interface Payload {
|
||||||
group_id: number,
|
group_id: number,
|
||||||
@@ -13,7 +13,7 @@ export default class SetGroupLeave extends BaseAction<Payload, any> {
|
|||||||
|
|
||||||
protected async _handle(payload: Payload): Promise<any> {
|
protected async _handle(payload: Payload): Promise<any> {
|
||||||
try {
|
try {
|
||||||
await NTQQApi.quitGroup(payload.group_id.toString())
|
await NTQQGroupApi.quitGroup(payload.group_id.toString())
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log("退群失败", e)
|
log("退群失败", e)
|
||||||
throw e
|
throw e
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "./BaseAction";
|
||||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
|
||||||
import {ActionName} from "./types";
|
import {ActionName} from "./types";
|
||||||
|
import {NTQQGroupApi} from "../../ntqqapi/api/group";
|
||||||
|
|
||||||
interface Payload {
|
interface Payload {
|
||||||
group_id: number,
|
group_id: number,
|
||||||
@@ -12,7 +12,7 @@ export default class SetGroupName extends BaseAction<Payload, null> {
|
|||||||
|
|
||||||
protected async _handle(payload: Payload): Promise<null> {
|
protected async _handle(payload: Payload): Promise<null> {
|
||||||
|
|
||||||
await NTQQApi.setGroupName(payload.group_id.toString(), payload.group_name)
|
await NTQQGroupApi.setGroupName(payload.group_id.toString(), payload.group_name)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,6 +1,6 @@
|
|||||||
import BaseAction from "./BaseAction";
|
import BaseAction from "./BaseAction";
|
||||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
|
||||||
import {ActionName} from "./types";
|
import {ActionName} from "./types";
|
||||||
|
import {NTQQGroupApi} from "../../ntqqapi/api/group";
|
||||||
|
|
||||||
interface Payload {
|
interface Payload {
|
||||||
group_id: number,
|
group_id: number,
|
||||||
@@ -12,7 +12,7 @@ export default class SetGroupWholeBan extends BaseAction<Payload, null> {
|
|||||||
|
|
||||||
protected async _handle(payload: Payload): Promise<null> {
|
protected async _handle(payload: Payload): Promise<null> {
|
||||||
|
|
||||||
await NTQQApi.banGroup(payload.group_id.toString(), !!payload.enable)
|
await NTQQGroupApi.banGroup(payload.group_id.toString(), !!payload.enable)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -3,9 +3,9 @@ import {getGroup} from "../../../common/data";
|
|||||||
import {ActionName} from "../types";
|
import {ActionName} from "../types";
|
||||||
import {SendMsgElementConstructor} from "../../../ntqqapi/constructor";
|
import {SendMsgElementConstructor} from "../../../ntqqapi/constructor";
|
||||||
import {ChatType, SendFileElement} from "../../../ntqqapi/types";
|
import {ChatType, SendFileElement} from "../../../ntqqapi/types";
|
||||||
import {NTQQApi} from "../../../ntqqapi/ntcall";
|
|
||||||
import {uri2local} from "../../utils";
|
import {uri2local} from "../../utils";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
|
import {NTQQMsgApi} from "../../../ntqqapi/api/msg";
|
||||||
|
|
||||||
interface Payload{
|
interface Payload{
|
||||||
group_id: number
|
group_id: number
|
||||||
@@ -31,7 +31,7 @@ export default class GoCQHTTPUploadGroupFile extends BaseAction<Payload, null> {
|
|||||||
throw new Error(downloadResult.errMsg)
|
throw new Error(downloadResult.errMsg)
|
||||||
}
|
}
|
||||||
let sendFileEle: SendFileElement = await SendMsgElementConstructor.file(downloadResult.path, payload.name);
|
let sendFileEle: SendFileElement = await SendMsgElementConstructor.file(downloadResult.path, payload.name);
|
||||||
await NTQQApi.sendMsg({chatType: ChatType.group, peerUid: group.groupCode}, [sendFileEle]);
|
await NTQQMsgApi.sendMsg({chatType: ChatType.group, peerUid: group.groupCode}, [sendFileEle]);
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -35,12 +35,14 @@ import CleanCache from "./CleanCache";
|
|||||||
import GoCQHTTPUploadGroupFile from "./go-cqhttp/UploadGroupFile";
|
import GoCQHTTPUploadGroupFile from "./go-cqhttp/UploadGroupFile";
|
||||||
import {GetConfigAction, SetConfigAction} from "./llonebot/Config";
|
import {GetConfigAction, SetConfigAction} from "./llonebot/Config";
|
||||||
import GetGroupAddRequest from "./llonebot/GetGroupAddRequest";
|
import GetGroupAddRequest from "./llonebot/GetGroupAddRequest";
|
||||||
|
import SetQQAvatar from './llonebot/SetQQAvatar'
|
||||||
|
|
||||||
export const actionHandlers = [
|
export const actionHandlers = [
|
||||||
new Debug(),
|
new Debug(),
|
||||||
new GetConfigAction(),
|
new GetConfigAction(),
|
||||||
new SetConfigAction(),
|
new SetConfigAction(),
|
||||||
new GetGroupAddRequest(),
|
new GetGroupAddRequest(),
|
||||||
|
new SetQQAvatar(),
|
||||||
// onebot11
|
// onebot11
|
||||||
new SendLike(),
|
new SendLike(),
|
||||||
new GetMsg(),
|
new GetMsg(),
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
import BaseAction from "../BaseAction";
|
import BaseAction from "../BaseAction";
|
||||||
import {Config} from "../../../common/types";
|
import {Config} from "../../../common/types";
|
||||||
import {getConfigUtil} from "../../../common/utils";
|
|
||||||
import {ActionName} from "../types";
|
import {ActionName} from "../types";
|
||||||
import {setConfig} from "../../../main/setConfig";
|
import {setConfig} from "../../../main/setConfig";
|
||||||
|
import {getConfigUtil} from "../../../common/config";
|
||||||
|
|
||||||
|
|
||||||
export class GetConfigAction extends BaseAction<null, Config> {
|
export class GetConfigAction extends BaseAction<null, Config> {
|
||||||
|
@@ -1,9 +1,10 @@
|
|||||||
import {GroupNotify, GroupNotifyStatus} from "../../../ntqqapi/types";
|
import {GroupNotify, GroupNotifyStatus} from "../../../ntqqapi/types";
|
||||||
import BaseAction from "../BaseAction";
|
import BaseAction from "../BaseAction";
|
||||||
import {ActionName} from "../types";
|
import {ActionName} from "../types";
|
||||||
import {NTQQApi} from "../../../ntqqapi/ntcall";
|
|
||||||
import {uidMaps} from "../../../common/data";
|
import {uidMaps} from "../../../common/data";
|
||||||
import {log} from "../../../common/utils";
|
import {NTQQUserApi} from "../../../ntqqapi/api/user";
|
||||||
|
import {NTQQGroupApi} from "../../../ntqqapi/api/group";
|
||||||
|
import {log} from "../../../common/utils/log";
|
||||||
|
|
||||||
interface OB11GroupRequestNotify {
|
interface OB11GroupRequestNotify {
|
||||||
group_id: number,
|
group_id: number,
|
||||||
@@ -15,12 +16,12 @@ export default class GetGroupAddRequest extends BaseAction<null, OB11GroupReques
|
|||||||
actionName = ActionName.GetGroupIgnoreAddRequest
|
actionName = ActionName.GetGroupIgnoreAddRequest
|
||||||
|
|
||||||
protected async _handle(payload: null): Promise<OB11GroupRequestNotify[]> {
|
protected async _handle(payload: null): Promise<OB11GroupRequestNotify[]> {
|
||||||
const data = await NTQQApi.getGroupIgnoreNotifies()
|
const data = await NTQQGroupApi.getGroupIgnoreNotifies()
|
||||||
log(data);
|
log(data);
|
||||||
let notifies: GroupNotify[] = data.notifies.filter(notify => notify.status === GroupNotifyStatus.WAIT_HANDLE);
|
let notifies: GroupNotify[] = data.notifies.filter(notify => notify.status === GroupNotifyStatus.WAIT_HANDLE);
|
||||||
let returnData: OB11GroupRequestNotify[] = []
|
let returnData: OB11GroupRequestNotify[] = []
|
||||||
for (const notify of notifies) {
|
for (const notify of notifies) {
|
||||||
const uin = uidMaps[notify.user1.uid] || (await NTQQApi.getUserDetailInfo(notify.user1.uid))?.uin
|
const uin = uidMaps[notify.user1.uid] || (await NTQQUserApi.getUserDetailInfo(notify.user1.uid))?.uin
|
||||||
returnData.push({
|
returnData.push({
|
||||||
group_id: parseInt(notify.group.groupCode),
|
group_id: parseInt(notify.group.groupCode),
|
||||||
user_id: parseInt(uin),
|
user_id: parseInt(uin),
|
||||||
|
44
src/onebot11/action/llonebot/SetQQAvatar.ts
Normal file
44
src/onebot11/action/llonebot/SetQQAvatar.ts
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
import BaseAction from "../BaseAction";
|
||||||
|
import {ActionName} from "../types";
|
||||||
|
import { uri2local } from "../../utils";
|
||||||
|
import * as fs from "node:fs";
|
||||||
|
import {NTQQUserApi} from "../../../ntqqapi/api/user";
|
||||||
|
import {checkFileReceived} from "../../../common/utils/file";
|
||||||
|
// import { log } from "../../../common/utils";
|
||||||
|
|
||||||
|
interface Payload {
|
||||||
|
file: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class SetAvatar extends BaseAction<Payload, null> {
|
||||||
|
actionName = ActionName.SetQQAvatar
|
||||||
|
|
||||||
|
protected async _handle(payload: Payload): Promise<null> {
|
||||||
|
const {path, isLocal, errMsg} = (await uri2local(payload.file))
|
||||||
|
if (errMsg){
|
||||||
|
throw `头像${payload.file}设置失败,file字段可能格式不正确`
|
||||||
|
}
|
||||||
|
if (path) {
|
||||||
|
await checkFileReceived(path, 5000); // 文件不存在QQ会崩溃,需要提前判断
|
||||||
|
const ret = await NTQQUserApi.setQQAvatar(path)
|
||||||
|
if (!isLocal){
|
||||||
|
fs.unlink(path, () => {})
|
||||||
|
}
|
||||||
|
if (!ret) {
|
||||||
|
throw `头像${payload.file}设置失败,api无返回`
|
||||||
|
}
|
||||||
|
// log(`头像设置返回:${JSON.stringify(ret)}`)
|
||||||
|
if (ret['result'] == 1004022) {
|
||||||
|
throw `头像${payload.file}设置失败,文件可能不是图片格式`
|
||||||
|
} else if(ret['result'] != 0) {
|
||||||
|
throw `头像${payload.file}设置失败,未知的错误,${ret['result']}:${ret['errMsg']}`
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!isLocal){
|
||||||
|
fs.unlink(path, () => {})
|
||||||
|
}
|
||||||
|
throw `头像${payload.file}设置失败,无法获取头像,文件可能不存在`
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
@@ -15,6 +15,7 @@ export interface InvalidCheckResult {
|
|||||||
|
|
||||||
export enum ActionName {
|
export enum ActionName {
|
||||||
GetGroupIgnoreAddRequest = "get_group_ignore_add_request",
|
GetGroupIgnoreAddRequest = "get_group_ignore_add_request",
|
||||||
|
SetQQAvatar = "set_qq_avatar",
|
||||||
GetConfig = "get_config",
|
GetConfig = "get_config",
|
||||||
SetConfig = "set_config",
|
SetConfig = "set_config",
|
||||||
Debug = "llonebot_debug",
|
Debug = "llonebot_debug",
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
import {OB11Return} from '../types';
|
import {OB11Return} from '../types';
|
||||||
import {isNull} from '../../common/utils';
|
|
||||||
|
import {isNull} from "../../common/utils/helper";
|
||||||
|
|
||||||
export class OB11Response {
|
export class OB11Response {
|
||||||
static res<T>(data: T, status: string, retcode: number, message: string = ""): OB11Return<T> {
|
static res<T>(data: T, status: string, retcode: number, message: string = ""): OB11Return<T> {
|
||||||
|
@@ -11,17 +11,16 @@ import {
|
|||||||
import {
|
import {
|
||||||
AtType,
|
AtType,
|
||||||
ChatType,
|
ChatType,
|
||||||
|
GrayTipElementSubType,
|
||||||
Group,
|
Group,
|
||||||
GroupMember,
|
GroupMember,
|
||||||
IMAGE_HTTP_HOST,
|
IMAGE_HTTP_HOST,
|
||||||
RawMessage,
|
RawMessage,
|
||||||
SelfInfo,
|
SelfInfo, Sex,
|
||||||
TipGroupElementType,
|
TipGroupElementType,
|
||||||
User
|
User
|
||||||
} from '../ntqqapi/types';
|
} from '../ntqqapi/types';
|
||||||
import {getFriend, getGroup, getGroupMember, selfInfo, tempGroupCodeMap} from '../common/data';
|
import {getFriend, getGroupMember, selfInfo, tempGroupCodeMap} from '../common/data';
|
||||||
import {getConfigUtil, log, sleep} from "../common/utils";
|
|
||||||
import {NTQQApi} from "../ntqqapi/ntcall";
|
|
||||||
import {EventType} from "./event/OB11BaseEvent";
|
import {EventType} from "./event/OB11BaseEvent";
|
||||||
import {encodeCQCode} from "./cqcode";
|
import {encodeCQCode} from "./cqcode";
|
||||||
import {dbUtil} from "../common/db";
|
import {dbUtil} from "../common/db";
|
||||||
@@ -29,6 +28,12 @@ import {OB11GroupIncreaseEvent} from "./event/notice/OB11GroupIncreaseEvent";
|
|||||||
import {OB11GroupBanEvent} from "./event/notice/OB11GroupBanEvent";
|
import {OB11GroupBanEvent} from "./event/notice/OB11GroupBanEvent";
|
||||||
import {OB11GroupUploadNoticeEvent} from "./event/notice/OB11GroupUploadNoticeEvent";
|
import {OB11GroupUploadNoticeEvent} from "./event/notice/OB11GroupUploadNoticeEvent";
|
||||||
import {OB11GroupNoticeEvent} from "./event/notice/OB11GroupNoticeEvent";
|
import {OB11GroupNoticeEvent} from "./event/notice/OB11GroupNoticeEvent";
|
||||||
|
import {NTQQUserApi} from "../ntqqapi/api/user";
|
||||||
|
import {NTQQFileApi} from "../ntqqapi/api/file";
|
||||||
|
import {calcQQLevel} from "../common/utils/qqlevel";
|
||||||
|
import {log} from "../common/utils/log";
|
||||||
|
import {sleep} from "../common/utils/helper";
|
||||||
|
import {getConfigUtil} from "../common/config";
|
||||||
|
|
||||||
|
|
||||||
export class OB11Constructor {
|
export class OB11Constructor {
|
||||||
@@ -91,7 +96,7 @@ export class OB11Constructor {
|
|||||||
let atUid = element.textElement.atNtUid
|
let atUid = element.textElement.atNtUid
|
||||||
let atQQ = element.textElement.atUid
|
let atQQ = element.textElement.atUid
|
||||||
if (!atQQ || atQQ === "0") {
|
if (!atQQ || atQQ === "0") {
|
||||||
const atMember = await getGroupMember(msg.peerUin, null, atUid)
|
const atMember = await getGroupMember(msg.peerUin, atUid)
|
||||||
if (atMember) {
|
if (atMember) {
|
||||||
atQQ = atMember.uin
|
atQQ = atMember.uin
|
||||||
}
|
}
|
||||||
@@ -143,7 +148,7 @@ export class OB11Constructor {
|
|||||||
fileSize: element.picElement.fileSize.toString(),
|
fileSize: element.picElement.fileSize.toString(),
|
||||||
url: message_data["data"]["url"],
|
url: message_data["data"]["url"],
|
||||||
downloadFunc: async () => {
|
downloadFunc: async () => {
|
||||||
await NTQQApi.downloadMedia(msg.msgId, msg.chatType, msg.peerUid,
|
await NTQQFileApi.downloadMedia(msg.msgId, msg.chatType, msg.peerUid,
|
||||||
element.elementId, element.picElement.thumbPath?.get(0) || "", element.picElement.sourcePath)
|
element.elementId, element.picElement.thumbPath?.get(0) || "", element.picElement.sourcePath)
|
||||||
}
|
}
|
||||||
}).then()
|
}).then()
|
||||||
@@ -160,7 +165,7 @@ export class OB11Constructor {
|
|||||||
filePath: element.videoElement.filePath,
|
filePath: element.videoElement.filePath,
|
||||||
fileSize: element.videoElement.fileSize,
|
fileSize: element.videoElement.fileSize,
|
||||||
downloadFunc: async () => {
|
downloadFunc: async () => {
|
||||||
await NTQQApi.downloadMedia(msg.msgId, msg.chatType, msg.peerUid,
|
await NTQQFileApi.downloadMedia(msg.msgId, msg.chatType, msg.peerUid,
|
||||||
element.elementId, element.videoElement.thumbPath.get(0), element.videoElement.filePath)
|
element.elementId, element.videoElement.thumbPath.get(0), element.videoElement.filePath)
|
||||||
}
|
}
|
||||||
}).then()
|
}).then()
|
||||||
@@ -176,7 +181,7 @@ export class OB11Constructor {
|
|||||||
filePath: element.fileElement.filePath,
|
filePath: element.fileElement.filePath,
|
||||||
fileSize: element.fileElement.fileSize,
|
fileSize: element.fileElement.fileSize,
|
||||||
downloadFunc: async () => {
|
downloadFunc: async () => {
|
||||||
await NTQQApi.downloadMedia(msg.msgId, msg.chatType, msg.peerUid,
|
await NTQQFileApi.downloadMedia(msg.msgId, msg.chatType, msg.peerUid,
|
||||||
element.elementId, null, element.fileElement.filePath)
|
element.elementId, null, element.fileElement.filePath)
|
||||||
}
|
}
|
||||||
}).then()
|
}).then()
|
||||||
@@ -206,33 +211,6 @@ export class OB11Constructor {
|
|||||||
message_data["type"] = OB11MessageDataType.face;
|
message_data["type"] = OB11MessageDataType.face;
|
||||||
message_data["data"]["id"] = element.faceElement.faceIndex.toString();
|
message_data["data"]["id"] = element.faceElement.faceIndex.toString();
|
||||||
}
|
}
|
||||||
// todo: 解析入群grayTipElement
|
|
||||||
else if (element.grayTipElement?.aioOpGrayTipElement) {
|
|
||||||
log("收到 group gray tip 消息", element.grayTipElement.aioOpGrayTipElement)
|
|
||||||
}
|
|
||||||
// if (message_data.data.file) {
|
|
||||||
// let filePath: string = message_data.data.file;
|
|
||||||
// if (!enableLocalFile2Url) {
|
|
||||||
// message_data.data.file = "file://" + filePath
|
|
||||||
// } else { // 不使用本地路径
|
|
||||||
// const ignoreTypes = [OB11MessageDataType.file, OB11MessageDataType.video]
|
|
||||||
// if (!ignoreTypes.includes(message_data.type)) {
|
|
||||||
// if (message_data.data.url && !message_data.data.url.startsWith(IMAGE_HTTP_HOST + "/download")) {
|
|
||||||
// message_data.data.file = message_data.data.url
|
|
||||||
// } else {
|
|
||||||
// let { err, data } = await file2base64(filePath);
|
|
||||||
// if (err) {
|
|
||||||
// log("文件转base64失败", filePath, err)
|
|
||||||
// } else {
|
|
||||||
// message_data.data.file = "base64://" + data
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// message_data.data.file = "file://" + filePath
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (message_data.type !== "unknown" && message_data.data) {
|
if (message_data.type !== "unknown" && message_data.data) {
|
||||||
const cqCode = encodeCQCode(message_data);
|
const cqCode = encodeCQCode(message_data);
|
||||||
if (messagePostFormat === 'string') {
|
if (messagePostFormat === 'string') {
|
||||||
@@ -250,20 +228,22 @@ export class OB11Constructor {
|
|||||||
if (msg.chatType !== ChatType.group) {
|
if (msg.chatType !== ChatType.group) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// log("group msg", msg);
|
||||||
for (let element of msg.elements) {
|
for (let element of msg.elements) {
|
||||||
const groupElement = element.grayTipElement?.groupElement
|
const grayTipElement = element.grayTipElement
|
||||||
|
const groupElement = grayTipElement?.groupElement
|
||||||
if (groupElement) {
|
if (groupElement) {
|
||||||
// log("收到群提示消息", groupElement)
|
// log("收到群提示消息", groupElement)
|
||||||
if (groupElement.type == TipGroupElementType.memberIncrease) {
|
if (groupElement.type == TipGroupElementType.memberIncrease) {
|
||||||
log("收到群成员增加消息", groupElement)
|
log("收到群成员增加消息", groupElement)
|
||||||
await sleep(1000);
|
await sleep(1000);
|
||||||
const member = await getGroupMember(msg.peerUid, null, groupElement.memberUid);
|
const member = await getGroupMember(msg.peerUid, groupElement.memberUid);
|
||||||
let memberUin = member?.uin;
|
let memberUin = member?.uin;
|
||||||
if (!memberUin) {
|
if (!memberUin) {
|
||||||
memberUin = (await NTQQApi.getUserDetailInfo(groupElement.memberUid)).uin
|
memberUin = (await NTQQUserApi.getUserDetailInfo(groupElement.memberUid)).uin
|
||||||
}
|
}
|
||||||
// log("获取新群成员QQ", memberUin)
|
// log("获取新群成员QQ", memberUin)
|
||||||
const adminMember = await getGroupMember(msg.peerUid, null, groupElement.adminUid);
|
const adminMember = await getGroupMember(msg.peerUid, groupElement.adminUid);
|
||||||
// log("获取同意新成员入群的管理员", adminMember)
|
// log("获取同意新成员入群的管理员", adminMember)
|
||||||
if (memberUin) {
|
if (memberUin) {
|
||||||
const operatorUin = adminMember?.uin || memberUin
|
const operatorUin = adminMember?.uin || memberUin
|
||||||
@@ -280,7 +260,7 @@ export class OB11Constructor {
|
|||||||
let duration = parseInt(groupElement.shutUp.duration)
|
let duration = parseInt(groupElement.shutUp.duration)
|
||||||
let sub_type: "ban" | "lift_ban" = duration > 0 ? "ban" : "lift_ban"
|
let sub_type: "ban" | "lift_ban" = duration > 0 ? "ban" : "lift_ban"
|
||||||
if (memberUid){
|
if (memberUid){
|
||||||
memberUin = (await getGroupMember(msg.peerUid, null, memberUid))?.uin || (await NTQQApi.getUserDetailInfo(memberUid))?.uin
|
memberUin = (await getGroupMember(msg.peerUid, memberUid))?.uin || (await NTQQUserApi.getUserDetailInfo(memberUid))?.uin
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
memberUin = "0"; // 0表示全员禁言
|
memberUin = "0"; // 0表示全员禁言
|
||||||
@@ -288,14 +268,35 @@ export class OB11Constructor {
|
|||||||
duration = -1
|
duration = -1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const adminUin = (await getGroupMember(msg.peerUid, null, adminUid))?.uin || (await NTQQApi.getUserDetailInfo(adminUid))?.uin
|
const adminUin = (await getGroupMember(msg.peerUid, adminUid))?.uin || (await NTQQUserApi.getUserDetailInfo(adminUid))?.uin
|
||||||
if (memberUin && adminUin) {
|
if (memberUin && adminUin) {
|
||||||
return new OB11GroupBanEvent(parseInt(msg.peerUid), parseInt(memberUin), parseInt(adminUin), duration, sub_type);
|
return new OB11GroupBanEvent(parseInt(msg.peerUid), parseInt(memberUin), parseInt(adminUin), duration, sub_type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (element.fileElement){
|
else if (element.fileElement){
|
||||||
return new OB11GroupUploadNoticeEvent(parseInt(msg.peerUid), parseInt(msg.senderUin), {id: element.fileElement.fileName, name: element.fileElement.fileName, size: parseInt(element.fileElement.fileSize)})
|
return new OB11GroupUploadNoticeEvent(parseInt(msg.peerUid), parseInt(msg.senderUin), {id: element.fileElement.fileUuid, name: element.fileElement.fileName, size: parseInt(element.fileElement.fileSize)})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (grayTipElement) {
|
||||||
|
if (grayTipElement.subElementType == GrayTipElementSubType.INVITE_NEW_MEMBER){
|
||||||
|
log("收到新人被邀请进群消息", grayTipElement)
|
||||||
|
const xmlElement = grayTipElement.xmlElement
|
||||||
|
if (xmlElement?.content){
|
||||||
|
const regex = /jp="(\d+)"/g;
|
||||||
|
|
||||||
|
let matches = [];
|
||||||
|
let match = null
|
||||||
|
|
||||||
|
while ((match = regex.exec(xmlElement.content)) !== null) {
|
||||||
|
matches.push(match[1]);
|
||||||
|
}
|
||||||
|
if (matches.length === 2){
|
||||||
|
const [inviter, invitee] = matches;
|
||||||
|
return new OB11GroupIncreaseEvent(parseInt(msg.peerUid), parseInt(invitee), parseInt(inviter), "invite");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -328,16 +329,25 @@ export class OB11Constructor {
|
|||||||
}[role]
|
}[role]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static sex(sex: Sex): OB11UserSex{
|
||||||
|
const sexMap = {
|
||||||
|
[Sex.male]: OB11UserSex.male,
|
||||||
|
[Sex.female]: OB11UserSex.female,
|
||||||
|
[Sex.unknown]: OB11UserSex.unknown
|
||||||
|
}
|
||||||
|
return sexMap[sex] || OB11UserSex.unknown
|
||||||
|
}
|
||||||
static groupMember(group_id: string, member: GroupMember): OB11GroupMember {
|
static groupMember(group_id: string, member: GroupMember): OB11GroupMember {
|
||||||
return {
|
return {
|
||||||
group_id: parseInt(group_id),
|
group_id: parseInt(group_id),
|
||||||
user_id: parseInt(member.uin),
|
user_id: parseInt(member.uin),
|
||||||
nickname: member.nick,
|
nickname: member.nick,
|
||||||
card: member.cardName,
|
card: member.cardName,
|
||||||
sex: OB11UserSex.unknown,
|
sex: OB11Constructor.sex(member.sex),
|
||||||
age: 0,
|
age: 0,
|
||||||
area: "",
|
area: "",
|
||||||
level: 0,
|
level: 0,
|
||||||
|
qq_level: member.qqLevel && calcQQLevel(member.qqLevel) || 0,
|
||||||
join_time: 0, // 暂时没法获取
|
join_time: 0, // 暂时没法获取
|
||||||
last_sent_time: 0, // 暂时没法获取
|
last_sent_time: 0, // 暂时没法获取
|
||||||
title_expire_time: 0,
|
title_expire_time: 0,
|
||||||
|
@@ -1,14 +1,15 @@
|
|||||||
import {OB11GroupNoticeEvent} from "./OB11GroupNoticeEvent";
|
import {OB11GroupNoticeEvent} from "./OB11GroupNoticeEvent";
|
||||||
|
|
||||||
|
type GroupIncreaseSubType = "approve" | "invite";
|
||||||
export class OB11GroupIncreaseEvent extends OB11GroupNoticeEvent {
|
export class OB11GroupIncreaseEvent extends OB11GroupNoticeEvent {
|
||||||
notice_type = "group_increase";
|
notice_type = "group_increase";
|
||||||
sub_type = "approve"; // TODO: 实现其他几种子类型的识别 ("approve" | "invite")
|
|
||||||
operator_id: number;
|
operator_id: number;
|
||||||
|
sub_type: GroupIncreaseSubType;
|
||||||
constructor(groupId: number, userId: number, operatorId: number) {
|
constructor(groupId: number, userId: number, operatorId: number, subType: GroupIncreaseSubType = "approve") {
|
||||||
super();
|
super();
|
||||||
this.group_id = groupId;
|
this.group_id = groupId;
|
||||||
this.operator_id = operatorId;
|
this.operator_id = operatorId;
|
||||||
this.user_id = userId;
|
this.user_id = userId;
|
||||||
|
this.sub_type = subType
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
31
src/onebot11/event/notice/OB11PokeEvent.ts
Normal file
31
src/onebot11/event/notice/OB11PokeEvent.ts
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
import {OB11BaseNoticeEvent} from "./OB11BaseNoticeEvent";
|
||||||
|
import {selfInfo} from "../../../common/data";
|
||||||
|
import {OB11BaseEvent} from "../OB11BaseEvent";
|
||||||
|
|
||||||
|
class OB11PokeEvent extends OB11BaseNoticeEvent{
|
||||||
|
notice_type = "notify"
|
||||||
|
sub_type = "poke"
|
||||||
|
target_id = parseInt(selfInfo.uin)
|
||||||
|
user_id: number
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export class OB11FriendPokeEvent extends OB11PokeEvent{
|
||||||
|
sender_id: number
|
||||||
|
constructor(user_id: number) {
|
||||||
|
super();
|
||||||
|
this.user_id = user_id;
|
||||||
|
this.sender_id = user_id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class OB11GroupPokeEvent extends OB11PokeEvent{
|
||||||
|
group_id: number
|
||||||
|
|
||||||
|
constructor(group_id: number, user_id: number=0) {
|
||||||
|
super();
|
||||||
|
this.group_id = group_id;
|
||||||
|
this.target_id = user_id;
|
||||||
|
this.user_id = user_id;
|
||||||
|
}
|
||||||
|
}
|
@@ -1,8 +1,8 @@
|
|||||||
import {Response} from "express";
|
import {Response} from "express";
|
||||||
import {getConfigUtil} from "../../common/utils";
|
|
||||||
import {OB11Response} from "../action/utils";
|
import {OB11Response} from "../action/utils";
|
||||||
import {HttpServerBase} from "../../common/server/http";
|
import {HttpServerBase} from "../../common/server/http";
|
||||||
import {actionHandlers} from "../action";
|
import {actionHandlers} from "../action";
|
||||||
|
import {getConfigUtil} from "../../common/config";
|
||||||
|
|
||||||
class OB11HTTPServer extends HttpServerBase {
|
class OB11HTTPServer extends HttpServerBase {
|
||||||
name = "OneBot V11 server"
|
name = "OneBot V11 server"
|
||||||
|
@@ -1,10 +1,11 @@
|
|||||||
import {getConfigUtil, log} from "../../common/utils";
|
|
||||||
import {OB11Message} from "../types";
|
import {OB11Message} from "../types";
|
||||||
import {selfInfo} from "../../common/data";
|
import {selfInfo} from "../../common/data";
|
||||||
import {OB11BaseMetaEvent} from "../event/meta/OB11BaseMetaEvent";
|
import {OB11BaseMetaEvent} from "../event/meta/OB11BaseMetaEvent";
|
||||||
import {OB11BaseNoticeEvent} from "../event/notice/OB11BaseNoticeEvent";
|
import {OB11BaseNoticeEvent} from "../event/notice/OB11BaseNoticeEvent";
|
||||||
import {WebSocket as WebSocketClass} from "ws";
|
import {WebSocket as WebSocketClass} from "ws";
|
||||||
import {wsReply} from "./ws/reply";
|
import {wsReply} from "./ws/reply";
|
||||||
|
import {log} from "../../common/utils/log";
|
||||||
|
import {getConfigUtil} from "../../common/config";
|
||||||
|
|
||||||
export type PostEventType = OB11Message | OB11BaseMetaEvent | OB11BaseNoticeEvent
|
export type PostEventType = OB11Message | OB11BaseMetaEvent | OB11BaseNoticeEvent
|
||||||
|
|
||||||
|
@@ -1,6 +1,3 @@
|
|||||||
import {getConfigUtil, log} from "../../../common/utils";
|
|
||||||
|
|
||||||
|
|
||||||
import {selfInfo} from "../../../common/data";
|
import {selfInfo} from "../../../common/data";
|
||||||
import {LifeCycleSubType, OB11LifeCycleEvent} from "../../event/meta/OB11LifeCycleEvent";
|
import {LifeCycleSubType, OB11LifeCycleEvent} from "../../event/meta/OB11LifeCycleEvent";
|
||||||
import {ActionName} from "../../action/types";
|
import {ActionName} from "../../action/types";
|
||||||
@@ -11,6 +8,8 @@ import {postWsEvent, registerWsEventSender, unregisterWsEventSender} from "../po
|
|||||||
import {wsReply} from "./reply";
|
import {wsReply} from "./reply";
|
||||||
import {WebSocket as WebSocketClass} from "ws";
|
import {WebSocket as WebSocketClass} from "ws";
|
||||||
import {OB11HeartbeatEvent} from "../../event/meta/OB11HeartbeatEvent";
|
import {OB11HeartbeatEvent} from "../../event/meta/OB11HeartbeatEvent";
|
||||||
|
import {log} from "../../../common/utils/log";
|
||||||
|
import {getConfigUtil} from "../../../common/config";
|
||||||
|
|
||||||
export let rwsList: ReverseWebsocket[] = [];
|
export let rwsList: ReverseWebsocket[] = [];
|
||||||
|
|
||||||
|
@@ -1,5 +1,4 @@
|
|||||||
import {WebSocket} from "ws";
|
import {WebSocket} from "ws";
|
||||||
import {getConfigUtil, log} from "../../../common/utils";
|
|
||||||
import {actionMap} from "../../action";
|
import {actionMap} from "../../action";
|
||||||
import {OB11Response} from "../../action/utils";
|
import {OB11Response} from "../../action/utils";
|
||||||
import {postWsEvent, registerWsEventSender, unregisterWsEventSender} from "../postOB11Event";
|
import {postWsEvent, registerWsEventSender, unregisterWsEventSender} from "../postOB11Event";
|
||||||
@@ -11,6 +10,8 @@ import {WebsocketServerBase} from "../../../common/server/websocket";
|
|||||||
import {IncomingMessage} from "node:http";
|
import {IncomingMessage} from "node:http";
|
||||||
import {wsReply} from "./reply";
|
import {wsReply} from "./reply";
|
||||||
import {selfInfo} from "../../../common/data";
|
import {selfInfo} from "../../../common/data";
|
||||||
|
import {log} from "../../../common/utils/log";
|
||||||
|
import {getConfigUtil} from "../../../common/config";
|
||||||
|
|
||||||
let heartbeatRunning = false;
|
let heartbeatRunning = false;
|
||||||
|
|
||||||
|
@@ -1,7 +1,8 @@
|
|||||||
import {WebSocket as WebSocketClass} from "ws";
|
import {WebSocket as WebSocketClass} from "ws";
|
||||||
import {OB11Response} from "../../action/utils";
|
import {OB11Response} from "../../action/utils";
|
||||||
import {PostEventType} from "../postOB11Event";
|
import {PostEventType} from "../postOB11Event";
|
||||||
import {isNull, log} from "../../../common/utils";
|
import {log} from "../../../common/utils/log";
|
||||||
|
import {isNull} from "../../../common/utils/helper";
|
||||||
|
|
||||||
export function wsReply(wsClient: WebSocketClass, data: OB11Response | PostEventType) {
|
export function wsReply(wsClient: WebSocketClass, data: OB11Response | PostEventType) {
|
||||||
try {
|
try {
|
||||||
|
@@ -29,6 +29,7 @@ export interface OB11GroupMember {
|
|||||||
join_time?: number
|
join_time?: number
|
||||||
last_sent_time?: number
|
last_sent_time?: number
|
||||||
level?: number
|
level?: number
|
||||||
|
qq_level?: number
|
||||||
role?: OB11GroupMemberRole
|
role?: OB11GroupMemberRole
|
||||||
title?: string
|
title?: string
|
||||||
area?: string
|
area?: string
|
||||||
@@ -64,6 +65,7 @@ export enum OB11MessageType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface OB11Message {
|
export interface OB11Message {
|
||||||
|
target_id?: number; // 自己发送的消息才有此字段
|
||||||
self_id?: number,
|
self_id?: number,
|
||||||
time: number,
|
time: number,
|
||||||
message_id: number,
|
message_id: number,
|
||||||
@@ -121,6 +123,9 @@ interface OB11MessageFileBase {
|
|||||||
|
|
||||||
export interface OB11MessageImage extends OB11MessageFileBase {
|
export interface OB11MessageImage extends OB11MessageFileBase {
|
||||||
type: OB11MessageDataType.image
|
type: OB11MessageDataType.image
|
||||||
|
data: OB11MessageFileBase['data'] & {
|
||||||
|
summary ? : string; // 图片摘要
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface OB11MessageRecord extends OB11MessageFileBase {
|
export interface OB11MessageRecord extends OB11MessageFileBase {
|
||||||
|
@@ -1,8 +1,10 @@
|
|||||||
import {DATA_DIR, isGIF, log} from "../common/utils";
|
import {DATA_DIR} from "../common/utils";
|
||||||
import {v4 as uuidv4} from "uuid";
|
import {v4 as uuidv4} from "uuid";
|
||||||
import * as path from 'node:path';
|
import * as path from 'node:path';
|
||||||
import * as fileType from 'file-type';
|
import * as fileType from 'file-type';
|
||||||
import {dbUtil} from "../common/db";
|
import {dbUtil} from "../common/db";
|
||||||
|
import {isGIF} from "../common/utils/file";
|
||||||
|
import {log} from "../common/utils/log";
|
||||||
|
|
||||||
const fs = require("fs").promises;
|
const fs = require("fs").promises;
|
||||||
|
|
||||||
|
@@ -1,12 +1,14 @@
|
|||||||
// Electron 主进程 与 渲染进程 交互的桥梁
|
// Electron 主进程 与 渲染进程 交互的桥梁
|
||||||
|
|
||||||
import {Config, LLOneBotError} from "./common/types";
|
import {CheckVersion, Config, LLOneBotError} from "./common/types";
|
||||||
import {
|
import {
|
||||||
CHANNEL_ERROR,
|
CHANNEL_ERROR,
|
||||||
CHANNEL_GET_CONFIG,
|
CHANNEL_GET_CONFIG,
|
||||||
CHANNEL_LOG,
|
CHANNEL_LOG,
|
||||||
|
CHANNEL_CHECKVERSION,
|
||||||
CHANNEL_SELECT_FILE,
|
CHANNEL_SELECT_FILE,
|
||||||
CHANNEL_SET_CONFIG,
|
CHANNEL_SET_CONFIG,
|
||||||
|
CHANNEL_UPDATE,
|
||||||
} from "./common/channels";
|
} from "./common/channels";
|
||||||
|
|
||||||
const {contextBridge} = require("electron");
|
const {contextBridge} = require("electron");
|
||||||
@@ -16,6 +18,12 @@ const llonebot = {
|
|||||||
log: (data: any) => {
|
log: (data: any) => {
|
||||||
ipcRenderer.send(CHANNEL_LOG, data);
|
ipcRenderer.send(CHANNEL_LOG, data);
|
||||||
},
|
},
|
||||||
|
checkVersion:async (): Promise<CheckVersion> => {
|
||||||
|
return ipcRenderer.invoke(CHANNEL_CHECKVERSION);
|
||||||
|
},
|
||||||
|
updateLLOneBot:async (): Promise<boolean> => {
|
||||||
|
return ipcRenderer.invoke(CHANNEL_UPDATE);
|
||||||
|
},
|
||||||
setConfig: (config: Config) => {
|
setConfig: (config: Config) => {
|
||||||
ipcRenderer.send(CHANNEL_SET_CONFIG, config);
|
ipcRenderer.send(CHANNEL_SET_CONFIG, config);
|
||||||
},
|
},
|
||||||
|
@@ -90,8 +90,8 @@ async function onSettingWindowCreated(view: Element) {
|
|||||||
], 'ob11.messagePostFormat', config.ob11.messagePostFormat),
|
], 'ob11.messagePostFormat', config.ob11.messagePostFormat),
|
||||||
),
|
),
|
||||||
SettingItem(
|
SettingItem(
|
||||||
'ffmpeg 路径, 发送语音、视频需要,同时保证ffprobe和ffmpeg在一起', `<span id="config-ffmpeg-path-text">${!isEmpty(config.ffmpeg) ? config.ffmpeg : '未指定'}</span>`,
|
'ffmpeg 路径,发送语音、视频需要,同时保证ffprobe和ffmpeg在一起', ` <a href="javascript:LiteLoader.api.openExternal(\'https://llonebot.github.io/zh-CN/guide/ffmpeg\');">下载地址</a> <span id="config-ffmpeg-path-text">, 路径:${!isEmpty(config.ffmpeg) ? config.ffmpeg : '未指定'}</span>`,
|
||||||
SettingButton('选择', 'config-ffmpeg-select'),
|
SettingButton('选择ffmpeg', 'config-ffmpeg-select'),
|
||||||
),
|
),
|
||||||
SettingItem(
|
SettingItem(
|
||||||
'', null,
|
'', null,
|
||||||
@@ -99,6 +99,11 @@ async function onSettingWindowCreated(view: Element) {
|
|||||||
)
|
)
|
||||||
]),
|
]),
|
||||||
SettingList([
|
SettingList([
|
||||||
|
SettingItem(
|
||||||
|
'接收戳一戳消息, 暂时只支持Windows版的LLOneBot',
|
||||||
|
`重启QQ后生效,如果导致QQ崩溃请勿开启此项`,
|
||||||
|
SettingSwitch('enablePoke', config.enablePoke),
|
||||||
|
),
|
||||||
SettingItem(
|
SettingItem(
|
||||||
'使用 Base64 编码获取文件',
|
'使用 Base64 编码获取文件',
|
||||||
'开启后,调用 /get_image、/get_record 时,获取不到 url 时添加一个 Base64 字段',
|
'开启后,调用 /get_image、/get_record 时,获取不到 url 时添加一个 Base64 字段',
|
||||||
@@ -138,9 +143,14 @@ async function onSettingWindowCreated(view: Element) {
|
|||||||
]),
|
]),
|
||||||
SettingList([
|
SettingList([
|
||||||
SettingItem(
|
SettingItem(
|
||||||
'GitHub和文档',
|
'GitHub 仓库',
|
||||||
`https://github.com/LLOneBot/LLOneBot`,
|
`https://github.com/LLOneBot/LLOneBot`,
|
||||||
SettingButton('点个Star', 'open-github'),
|
SettingButton('点个星星', 'open-github'),
|
||||||
|
),
|
||||||
|
SettingItem(
|
||||||
|
'LLOneBot 文档',
|
||||||
|
`https://llonebot.github.io/`,
|
||||||
|
SettingButton('看看文档', 'open-docs'),
|
||||||
),
|
),
|
||||||
SettingItem(
|
SettingItem(
|
||||||
'Telegram 群',
|
'Telegram 群',
|
||||||
@@ -166,6 +176,9 @@ async function onSettingWindowCreated(view: Element) {
|
|||||||
doc.querySelector('#open-qq-group').addEventListener('click', () => {
|
doc.querySelector('#open-qq-group').addEventListener('click', () => {
|
||||||
window.LiteLoader.api.openExternal('https://qm.qq.com/q/bDnHRG38aI')
|
window.LiteLoader.api.openExternal('https://qm.qq.com/q/bDnHRG38aI')
|
||||||
})
|
})
|
||||||
|
doc.querySelector('#open-docs').addEventListener('click', () => {
|
||||||
|
window.LiteLoader.api.openExternal('https://llonebot.github.io/')
|
||||||
|
})
|
||||||
// 生成反向地址列表
|
// 生成反向地址列表
|
||||||
const buildHostListItem = (type: string, host: string, index: number, inputAttrs: any={}) => {
|
const buildHostListItem = (type: string, host: string, index: number, inputAttrs: any={}) => {
|
||||||
const dom = {
|
const dom = {
|
||||||
|
@@ -1 +1 @@
|
|||||||
export const version = "3.15.0"
|
export const version = "3.16.1"
|
Reference in New Issue
Block a user