mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
b8aa3131b0 | ||
![]() |
320aa964f9 | ||
![]() |
0fd75b338f | ||
![]() |
9faa56ec32 | ||
![]() |
c636af0b0e | ||
![]() |
b8af582749 | ||
![]() |
8e09a9e0fd | ||
![]() |
001dfc4db2 | ||
![]() |
a164884b76 | ||
![]() |
58f0a99d0b | ||
![]() |
528c6061e2 | ||
![]() |
f5ac499861 | ||
![]() |
621d9df450 | ||
![]() |
1f657f3e84 | ||
![]() |
329dc433fb |
95
README.md
95
README.md
@@ -18,6 +18,17 @@ TG群:<https://t.me/+nLZEnpne-pQ1OWFl>
|
||||
|
||||
*插件目录:`LiteLoaderQQNT/plugins`*
|
||||
|
||||
安装后的目录结构如下
|
||||
```
|
||||
├── plugins
|
||||
│ ├── LLOneBot
|
||||
│ │ └── main.js
|
||||
│ │ └── preload.js
|
||||
│ │ └── renderer.js
|
||||
│ │ └── manifest.json
|
||||
│ │ └── node_modules/...
|
||||
```
|
||||
|
||||
## 支持的API
|
||||
|
||||
目前支持的协议
|
||||
@@ -42,6 +53,11 @@ TG群:<https://t.me/+nLZEnpne-pQ1OWFl>
|
||||
- [x] 上报好友、群消息撤回
|
||||
- [x] 上报加群请求
|
||||
- [x] 上报群员人数变动(尚不支持识别群员人数变动原因)
|
||||
- [x] 设置群管理员
|
||||
- [x] 群禁言/全体禁言
|
||||
- [x] 群踢人
|
||||
- [x] 群改群成员名片
|
||||
- [x] 修改群名
|
||||
|
||||
消息格式支持:
|
||||
- [x] cq码
|
||||
@@ -53,34 +69,19 @@ TG群:<https://t.me/+nLZEnpne-pQ1OWFl>
|
||||
- [x] 语音(支持mp3、wav等多种音频格式直接发送)
|
||||
- [x] json消息(只上报)
|
||||
- [x] 转发消息记录(目前只能发不能收)
|
||||
- [ ] 红包
|
||||
- [ ] xml
|
||||
|
||||
支持的api:
|
||||
- [x] get_login_info
|
||||
- [x] send_msg
|
||||
- [x] send_group_msg
|
||||
- [x] send_private_msg
|
||||
- [x] delete_msg
|
||||
- [x] get_group_list
|
||||
- [x] get_group_info
|
||||
- [x] get_group_member_list
|
||||
- [x] get_group_member_info
|
||||
- [x] get_friend_list
|
||||
- [x] set_friend_add_request
|
||||
- [x] get_msg
|
||||
- [x] send_like
|
||||
- [x] set_group_add_request
|
||||
- [x] set_group_leave
|
||||
- [x] get_version_info
|
||||
- [x] get_status
|
||||
- [x] can_send_image
|
||||
- [x] can_send_record
|
||||
|
||||
支持的go-cqhtp api:
|
||||
- [x] send_private_forward_msg
|
||||
- [x] send_group_forward_msg
|
||||
- [x] get_stranger_info
|
||||
- [x] 视频(上报时暂时只有个空的file)
|
||||
- [x] 文件(上报时暂时只有个空的file), type为file, data为{file: uri}, 发送时uri支持http://, file://, base64://
|
||||
```
|
||||
{
|
||||
"type": "file",
|
||||
"data": {
|
||||
"file": "file:///D:/1.txt"
|
||||
}
|
||||
}
|
||||
```
|
||||
- [ ] 发送音乐卡片
|
||||
- [ ] 红包(没有计划支持)
|
||||
- [ ] xml (没有计划支持)
|
||||
|
||||
## 示例
|
||||
|
||||
@@ -99,6 +100,7 @@ TG群:<https://t.me/+nLZEnpne-pQ1OWFl>
|
||||
<summary>调用接口报404</summary>
|
||||
<br/>
|
||||
目前没有支持全部的onebot规范接口,请检查是否调用了不支持的接口
|
||||
-
|
||||
</details>
|
||||
<br/>
|
||||
|
||||
@@ -116,12 +118,49 @@ TG群:<https://t.me/+nLZEnpne-pQ1OWFl>
|
||||
</details>
|
||||
<br/>
|
||||
|
||||
## 支持的onebot v11 api:
|
||||
- [x] get_login_info
|
||||
- [x] send_msg
|
||||
- [x] send_group_msg
|
||||
- [x] send_private_msg
|
||||
- [x] delete_msg
|
||||
- [x] get_group_list
|
||||
- [x] get_group_info
|
||||
- [x] get_group_member_list
|
||||
- [x] get_group_member_info
|
||||
- [x] get_friend_list
|
||||
- [x] set_friend_add_request
|
||||
- [x] get_msg
|
||||
- [x] send_like
|
||||
- [x] set_group_add_request
|
||||
- [x] set_group_leave
|
||||
- [x] set_group_kick
|
||||
- [x] set_group_ban
|
||||
- [x] set_group_whole_ban
|
||||
- [x] set_group_kick
|
||||
- [x] set_group_admin
|
||||
- [x] set_group_card
|
||||
- [x] set_group_name
|
||||
- [x] get_version_info
|
||||
- [x] get_status
|
||||
- [x] can_send_image
|
||||
- [x] can_send_record
|
||||
|
||||
### 支持的go-cqhtp api:
|
||||
- [x] send_private_forward_msg
|
||||
- [x] send_group_forward_msg
|
||||
- [x] get_stranger_info
|
||||
|
||||
## TODO
|
||||
- [x] 重构摆脱LLAPI,目前调用LLAPI只能在renderer进程调用,需重构成在main进程调用
|
||||
- [x] 支持正、反向websocket(感谢@disymayufei的PR)
|
||||
- [x] 转发消息记录
|
||||
- [x] 好友点赞api
|
||||
- [x] 群管理功能,禁言、踢人,改群名片等
|
||||
- [x] 视频消息
|
||||
- [x] 文件消息
|
||||
- [ ] 音乐卡片
|
||||
- [ ] 无头模式
|
||||
|
||||
## onebot11文档
|
||||
<https://11.onebot.dev/>
|
||||
|
@@ -4,7 +4,7 @@
|
||||
"name": "LLOneBot",
|
||||
"slug": "LLOneBot",
|
||||
"description": "LiteLoaderQQNT的OneBotApi",
|
||||
"version": "3.8.0",
|
||||
"version": "3.9.0",
|
||||
"thumbnail": "./icon.png",
|
||||
"authors": [
|
||||
{
|
||||
|
@@ -2,7 +2,7 @@ import fs from "fs";
|
||||
import {Config, OB11Config} from "./types";
|
||||
import {mergeNewProperties} from "./utils";
|
||||
|
||||
export const HOOK_LOG = false;
|
||||
export const HOOK_LOG= false;
|
||||
|
||||
export class ConfigUtil {
|
||||
private readonly configPath: string;
|
||||
|
@@ -5,7 +5,7 @@ import {LLOneBotError} from "./types";
|
||||
export let groups: Group[] = []
|
||||
export let friends: Friend[] = []
|
||||
export let msgHistory: Record<string, RawMessage> = {} // msgId: RawMessage
|
||||
export const version = "3.8.0"
|
||||
export const version = "3.9.0"
|
||||
export let groupNotifies: Map<string, GroupNotify> = new Map<string, GroupNotify>();
|
||||
export let friendRequests: Map<number, FriendRequest> = new Map<number, FriendRequest>();
|
||||
export let llonebotError: LLOneBotError = {
|
||||
@@ -50,7 +50,11 @@ export async function getGroup(qq: string): Promise<Group | undefined> {
|
||||
return group
|
||||
}
|
||||
|
||||
export async function getGroupMember(groupQQ: string, memberQQ: string, memberUid: string = null) {
|
||||
export async function getGroupMember(groupQQ: string | number, memberQQ: string | number, memberUid: string = null) {
|
||||
groupQQ = groupQQ.toString();
|
||||
if (memberQQ){
|
||||
memberQQ = memberQQ.toString();
|
||||
}
|
||||
const group = await getGroup(groupQQ)
|
||||
if (group) {
|
||||
let filterFunc: (member: GroupMember) => boolean
|
||||
|
@@ -232,7 +232,7 @@ function onLoad() {
|
||||
"unreadCount": number
|
||||
}>(ReceiveCmd.UNREAD_GROUP_NOTIFY, async (payload) => {
|
||||
if (payload.unreadCount) {
|
||||
log("开始获取群通知详情")
|
||||
// log("开始获取群通知详情")
|
||||
let notify: GroupNotifies;
|
||||
try {
|
||||
notify = await NTQQApi.getGroupNotifies();
|
||||
@@ -242,14 +242,23 @@ function onLoad() {
|
||||
}
|
||||
|
||||
const notifies = notify.notifies.slice(0, payload.unreadCount)
|
||||
log("获取群通知详情完成", notifies, payload);
|
||||
// log("获取群通知详情完成", notifies, payload);
|
||||
try {
|
||||
for (const notify of notifies) {
|
||||
notify.time = Date.now();
|
||||
const notifyTime = parseInt(notify.seq) / 1000
|
||||
log(`加群通知时间${notifyTime}`, `LLOneBot启动时间${startTime}`);
|
||||
// log(`加群通知时间${notifyTime}`, `LLOneBot启动时间${startTime}`);
|
||||
if (notifyTime < startTime) {
|
||||
continue;
|
||||
}
|
||||
let existNotify = groupNotifies[notify.seq];
|
||||
if (existNotify){
|
||||
if (Date.now() - existNotify.time < 3000){
|
||||
continue
|
||||
}
|
||||
}
|
||||
log("收到群通知", notify);
|
||||
groupNotifies[notify.seq] = notify;
|
||||
const member1 = await getGroupMember(notify.group.groupCode, null, notify.user1.uid);
|
||||
let member2: GroupMember;
|
||||
if (notify.user2.uid) {
|
||||
@@ -274,7 +283,6 @@ function onLoad() {
|
||||
// postEvent(groupDecreaseEvent, true);
|
||||
} else if ([GroupNotifyTypes.JOIN_REQUEST].includes(notify.type)) {
|
||||
log("有加群请求");
|
||||
groupNotifies[notify.seq] = notify;
|
||||
let groupRequestEvent = new OB11GroupRequestEvent();
|
||||
groupRequestEvent.group_id = parseInt(notify.group.groupCode);
|
||||
let requestQQ = ""
|
||||
@@ -289,6 +297,15 @@ function onLoad() {
|
||||
groupRequestEvent.flag = notify.seq;
|
||||
postOB11Event(groupRequestEvent);
|
||||
}
|
||||
else if(notify.type == GroupNotifyTypes.INVITE_ME){
|
||||
let groupInviteEvent = new OB11GroupRequestEvent();
|
||||
groupInviteEvent.group_id = parseInt(notify.group.groupCode);
|
||||
let user_id = (await NTQQApi.getUserDetailInfo(notify.user2.uid))?.uin
|
||||
groupInviteEvent.user_id = parseInt(user_id);
|
||||
groupInviteEvent.sub_type = "invite";
|
||||
groupInviteEvent.flag = notify.seq;
|
||||
postOB11Event(groupInviteEvent);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
log("解析群通知失败", e.stack);
|
||||
@@ -326,7 +343,7 @@ function onLoad() {
|
||||
// 检查ffmpeg
|
||||
checkFFMPEG(config.ffmpeg).then(exist => {
|
||||
if (!exist) {
|
||||
llonebotError.ffmpegError = `环境变量${process.env.PATH}中不存在ffmpeg,音频只能发送wav和silk`
|
||||
llonebotError.ffmpegError = `没有找到ffmpeg,音频只能发送wav和silk`
|
||||
}
|
||||
})
|
||||
if (config.ob11.enableHttp) {
|
||||
|
@@ -2,6 +2,7 @@ import {
|
||||
AtType,
|
||||
ElementType,
|
||||
SendFaceElement,
|
||||
SendFileElement,
|
||||
SendPicElement,
|
||||
SendPttElement,
|
||||
SendReplyElement,
|
||||
@@ -55,7 +56,7 @@ export class SendMsgElementConstructor {
|
||||
}
|
||||
|
||||
static async pic(picPath: string): Promise<SendPicElement> {
|
||||
const {md5, fileName, path, fileSize} = await NTQQApi.uploadFile(picPath);
|
||||
const {md5, fileName, path, fileSize} = await NTQQApi.uploadFile(picPath, ElementType.PIC);
|
||||
const imageSize = await NTQQApi.getImageSize(picPath);
|
||||
const picElement = {
|
||||
md5HexStr: md5,
|
||||
@@ -80,12 +81,40 @@ export class SendMsgElementConstructor {
|
||||
};
|
||||
}
|
||||
|
||||
static async file(filePath: string, isVideo: boolean = false): Promise<SendFileElement> {
|
||||
let picHeight = 0;
|
||||
let picWidth = 0;
|
||||
if (isVideo) {
|
||||
picHeight = 1024;
|
||||
picWidth = 768;
|
||||
}
|
||||
const {md5, fileName, path, fileSize} = await NTQQApi.uploadFile(filePath, ElementType.FILE);
|
||||
let element: SendFileElement = {
|
||||
elementType: ElementType.FILE,
|
||||
elementId: "",
|
||||
fileElement: {
|
||||
fileName,
|
||||
"filePath": path,
|
||||
"fileSize": (fileSize).toString(),
|
||||
picHeight,
|
||||
picWidth
|
||||
}
|
||||
}
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
static video(filePath: string): Promise<SendFileElement> {
|
||||
return SendMsgElementConstructor.file(filePath, true);
|
||||
}
|
||||
|
||||
static async ptt(pttPath: string): Promise<SendPttElement> {
|
||||
const {converted, path: silkPath, duration} = await encodeSilk(pttPath);
|
||||
// log("生成语音", silkPath, duration);
|
||||
const {md5, fileName, path, fileSize} = await NTQQApi.uploadFile(silkPath, ElementType.PTT);
|
||||
if (converted){
|
||||
fs.unlink(silkPath, ()=>{});
|
||||
if (converted) {
|
||||
fs.unlink(silkPath, () => {
|
||||
});
|
||||
}
|
||||
return {
|
||||
elementType: ElementType.PTT,
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import {ipcMain} from "electron";
|
||||
import {hookApiCallbacks, ReceiveCmd, registerReceiveHook, removeReceiveHook} from "./hook";
|
||||
import {log} from "../common/utils";
|
||||
import {log, sleep} from "../common/utils";
|
||||
import {
|
||||
ChatType,
|
||||
ElementType,
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
FriendRequest,
|
||||
Group,
|
||||
GroupMember,
|
||||
GroupMemberRole,
|
||||
GroupNotifies,
|
||||
GroupNotify,
|
||||
GroupRequestOperateTypes,
|
||||
@@ -19,6 +20,7 @@ import {
|
||||
import * as fs from "fs";
|
||||
import {addHistoryMsg, friendRequests, groupNotifies, msgHistory, selfInfo} from "../common/data";
|
||||
import {v4 as uuidv4} from "uuid"
|
||||
import path from "path";
|
||||
|
||||
interface IPCReceiveEvent {
|
||||
eventName: string
|
||||
@@ -62,6 +64,13 @@ export enum NTQQApiMethod {
|
||||
QUIT_GROUP = "nodeIKernelGroupService/quitGroup",
|
||||
// READ_FRIEND_REQUEST = "nodeIKernelBuddyListener/onDoubtBuddyReqUnreadNumChange"
|
||||
HANDLE_FRIEND_REQUEST = "nodeIKernelBuddyService/approvalFriendRequest",
|
||||
KICK_MEMBER = "nodeIKernelGroupService/kickMember",
|
||||
MUTE_MEMBER = "nodeIKernelGroupService/setMemberShutUp",
|
||||
MUTE_GROUP = "nodeIKernelGroupService/setGroupShutUp",
|
||||
SET_MEMBER_CARD = "nodeIKernelGroupService/modifyMemberCardName",
|
||||
SET_MEMBER_ROLE = "nodeIKernelGroupService/modifyMemberRole",
|
||||
PUBLISH_GROUP_BULLETIN = "nodeIKernelGroupService/publishGroupBulletinBulletin",
|
||||
SET_GROUP_NAME = "nodeIKernelGroupService/modifyGroupName",
|
||||
}
|
||||
|
||||
enum NTQQApiChannel {
|
||||
@@ -331,7 +340,7 @@ export class NTQQApi {
|
||||
}
|
||||
|
||||
// 上传文件到QQ的文件夹
|
||||
static async uploadFile(filePath: string, elementType: ElementType=ElementType.PIC) {
|
||||
static async uploadFile(filePath: string, elementType: ElementType = ElementType.PIC) {
|
||||
const md5 = await NTQQApi.getFileMd5(filePath);
|
||||
let ext = (await NTQQApi.getFileType(filePath))?.ext
|
||||
if (ext) {
|
||||
@@ -339,7 +348,10 @@ export class NTQQApi {
|
||||
} else {
|
||||
ext = ""
|
||||
}
|
||||
const fileName = `${md5}${ext}`;
|
||||
let fileName = `${path.basename(filePath)}`;
|
||||
if (fileName.indexOf(".") === -1) {
|
||||
fileName += ext;
|
||||
}
|
||||
const mediaPath = await callNTQQApi<string>({
|
||||
methodName: NTQQApiMethod.MEDIA_FILE_PATH,
|
||||
args: [{
|
||||
@@ -407,71 +419,57 @@ export class NTQQApi {
|
||||
})
|
||||
}
|
||||
|
||||
static sendMsg(peer: Peer, msgElements: SendMessageElement[], waitComplete = false, timeout = 10000) {
|
||||
const sendTimeout = timeout
|
||||
static async sendMsg(peer: Peer, msgElements: SendMessageElement[], waitComplete = false, timeout = 10000) {
|
||||
const peerUid = peer.peerUid;
|
||||
|
||||
return new Promise<RawMessage>((resolve, reject) => {
|
||||
const peerUid = peer.peerUid;
|
||||
let usingTime = 0;
|
||||
let success = false;
|
||||
let isTimeout = false;
|
||||
|
||||
const checkSuccess = () => {
|
||||
if (!success) {
|
||||
sendMessagePool[peerUid] = null;
|
||||
isTimeout = true;
|
||||
reject("发送超时")
|
||||
}
|
||||
// 等待上一个相同的peer发送完
|
||||
let checkLastSendUsingTime = 0;
|
||||
const waitLastSend = async () => {
|
||||
if (checkLastSendUsingTime > timeout) {
|
||||
throw ("发送超时")
|
||||
}
|
||||
setTimeout(checkSuccess, sendTimeout);
|
||||
|
||||
const checkLastSend = () => {
|
||||
let lastSending = sendMessagePool[peerUid]
|
||||
if (sendTimeout < usingTime) {
|
||||
sendMessagePool[peerUid] = null;
|
||||
isTimeout = true;
|
||||
reject("发送超时")
|
||||
}
|
||||
if (!!lastSending) {
|
||||
// log("有正在发送的消息,等待中...")
|
||||
usingTime += 500;
|
||||
setTimeout(checkLastSend, 500);
|
||||
} else {
|
||||
log("可以进行发送消息,设置发送成功回调", sendMessagePool)
|
||||
sendMessagePool[peerUid] = (rawMessage: RawMessage) => {
|
||||
sendMessagePool[peerUid] = null;
|
||||
const checkSendComplete = () => {
|
||||
if (isTimeout) {
|
||||
return reject("发送超时")
|
||||
}
|
||||
if (msgHistory[rawMessage.msgId]?.sendStatus == 2) {
|
||||
log(`给${peerUid}发送消息成功`)
|
||||
success = true;
|
||||
resolve(rawMessage);
|
||||
} else {
|
||||
setTimeout(checkSendComplete, 500)
|
||||
}
|
||||
}
|
||||
if (waitComplete) {
|
||||
checkSendComplete();
|
||||
} else {
|
||||
success = true;
|
||||
log(`给${peerUid}发送消息成功`)
|
||||
resolve(rawMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
let lastSending = sendMessagePool[peer.peerUid]
|
||||
if (lastSending) {
|
||||
// log("有正在发送的消息,等待中...")
|
||||
await sleep(500);
|
||||
checkLastSendUsingTime += 500;
|
||||
return await waitLastSend();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
checkLastSend()
|
||||
callNTQQApi({
|
||||
methodName: NTQQApiMethod.SEND_MSG,
|
||||
args: [{
|
||||
msgId: "0",
|
||||
peer, msgElements,
|
||||
msgAttributeInfos: new Map(),
|
||||
}, null]
|
||||
}).then()
|
||||
})
|
||||
}
|
||||
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 && msgHistory[sentMessage.msgId]?.sendStatus == 2) {
|
||||
// log(`给${peerUid}发送消息成功`)
|
||||
return sentMessage;
|
||||
} else {
|
||||
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 checkSendComplete();
|
||||
}
|
||||
|
||||
static multiForwardMsg(srcPeer: Peer, destPeer: Peer, msgIds: string[]) {
|
||||
@@ -550,6 +548,7 @@ export class NTQQApi {
|
||||
if (!notify) {
|
||||
throw `${seq}对应的加群通知不存在`
|
||||
}
|
||||
delete groupNotifies[seq];
|
||||
return await callNTQQApi<GeneralCallResult>({
|
||||
methodName: NTQQApiMethod.HANDLE_GROUP_REQUEST,
|
||||
args: [
|
||||
@@ -582,7 +581,7 @@ export class NTQQApi {
|
||||
|
||||
static async handleFriendRequest(sourceId: number, accept: boolean,) {
|
||||
const request: FriendRequest = friendRequests[sourceId]
|
||||
if (!request){
|
||||
if (!request) {
|
||||
throw `sourceId ${sourceId}, 对应的好友请求不存在`
|
||||
}
|
||||
const result = await callNTQQApi<GeneralCallResult>({
|
||||
@@ -600,4 +599,89 @@ export class NTQQApi {
|
||||
delete friendRequests[sourceId];
|
||||
return result;
|
||||
}
|
||||
|
||||
static kickMember(groupQQ: string, kickUids: string[], refuseForever: boolean = false, kickReason: string = "") {
|
||||
return callNTQQApi<GeneralCallResult>(
|
||||
{
|
||||
methodName: NTQQApiMethod.KICK_MEMBER,
|
||||
args: [
|
||||
{
|
||||
groupCode: groupQQ,
|
||||
kickUids,
|
||||
refuseForever,
|
||||
kickReason,
|
||||
}
|
||||
]
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
static banMember(groupQQ: string, memList: { uid: string, timeStamp: number }[]) {
|
||||
// timeStamp为秒数, 0为解除禁言
|
||||
return callNTQQApi<GeneralCallResult>(
|
||||
{
|
||||
methodName: NTQQApiMethod.MUTE_MEMBER,
|
||||
args: [
|
||||
{
|
||||
groupCode: groupQQ,
|
||||
memList,
|
||||
}
|
||||
]
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
static banGroup(groupQQ: string, shutUp: boolean) {
|
||||
return callNTQQApi<GeneralCallResult>({
|
||||
methodName: NTQQApiMethod.MUTE_GROUP,
|
||||
args: [
|
||||
{
|
||||
groupCode: groupQQ,
|
||||
shutUp
|
||||
}, null
|
||||
]
|
||||
})
|
||||
}
|
||||
|
||||
static setMemberCard(groupQQ: string, memberUid: string, cardName: string) {
|
||||
return callNTQQApi<GeneralCallResult>({
|
||||
methodName: NTQQApiMethod.SET_MEMBER_CARD,
|
||||
args: [
|
||||
{
|
||||
groupCode: groupQQ,
|
||||
uid: memberUid,
|
||||
cardName
|
||||
}, null
|
||||
]
|
||||
})
|
||||
}
|
||||
|
||||
static setMemberRole(groupQQ: string, memberUid: string, role: GroupMemberRole) {
|
||||
return callNTQQApi<GeneralCallResult>({
|
||||
methodName: NTQQApiMethod.SET_MEMBER_ROLE,
|
||||
args: [
|
||||
{
|
||||
groupCode: groupQQ,
|
||||
uid: memberUid,
|
||||
role
|
||||
}, null
|
||||
]
|
||||
})
|
||||
}
|
||||
|
||||
static setGroupName(groupQQ: string, groupName: string) {
|
||||
return callNTQQApi<GeneralCallResult>({
|
||||
methodName: NTQQApiMethod.SET_GROUP_NAME,
|
||||
args: [
|
||||
{
|
||||
groupCode: groupQQ,
|
||||
groupName
|
||||
}, null
|
||||
]
|
||||
})
|
||||
}
|
||||
|
||||
static publishGroupBulletin(groupQQ: string, title: string, content: string) {
|
||||
|
||||
}
|
||||
}
|
@@ -45,6 +45,12 @@ export interface Group {
|
||||
members: GroupMember[] // 原始数据是没有这个的,为了方便自己加了这个字段
|
||||
}
|
||||
|
||||
export enum GroupMemberRole {
|
||||
normal = 2,
|
||||
admin = 3,
|
||||
owner = 4
|
||||
}
|
||||
|
||||
export interface GroupMember {
|
||||
avatarPath: string;
|
||||
cardName: string;
|
||||
@@ -53,7 +59,7 @@ export interface GroupMember {
|
||||
nick: string;
|
||||
qid: string;
|
||||
remark: string;
|
||||
role: number; // 群主:4, 管理员:3,群员:2
|
||||
role: GroupMemberRole; // 群主:4, 管理员:3,群员:2
|
||||
shutUpTime: number; // 禁言时间,单位是什么暂时不清楚
|
||||
uid: string; // 加密的字符串
|
||||
uin: string; // QQ号
|
||||
@@ -62,6 +68,7 @@ export interface GroupMember {
|
||||
export enum ElementType {
|
||||
TEXT = 1,
|
||||
PIC = 2,
|
||||
FILE = 3,
|
||||
PTT = 4,
|
||||
FACE = 6,
|
||||
REPLY = 7,
|
||||
@@ -136,7 +143,30 @@ export interface SendFaceElement {
|
||||
faceElement: FaceElement
|
||||
}
|
||||
|
||||
export type SendMessageElement = SendTextElement | SendPttElement | SendPicElement | SendReplyElement | SendFaceElement
|
||||
export interface FileElement {
|
||||
"fileMd5"?: "",
|
||||
"fileName": string,
|
||||
"filePath": string,
|
||||
"fileSize": string,
|
||||
"picHeight"?: number,
|
||||
"picWidth"?: number,
|
||||
"picThumbPath"?: {},
|
||||
"file10MMd5"?: "",
|
||||
"fileSha"?: "",
|
||||
"fileSha3"?: "",
|
||||
"fileUuid"?: "",
|
||||
"fileSubId"?: "",
|
||||
"thumbFileSize"?: number
|
||||
}
|
||||
|
||||
export interface SendFileElement {
|
||||
"elementType": ElementType.FILE,
|
||||
"elementId": "",
|
||||
"fileElement": FileElement
|
||||
}
|
||||
|
||||
export type SendMessageElement = SendTextElement | SendPttElement |
|
||||
SendPicElement | SendReplyElement | SendFaceElement | SendFileElement
|
||||
|
||||
export enum AtType {
|
||||
notAt = 0,
|
||||
@@ -206,6 +236,31 @@ export interface FaceElement {
|
||||
faceType: 1
|
||||
}
|
||||
|
||||
export interface VideoElement {
|
||||
"filePath": string,
|
||||
"fileName": string,
|
||||
"videoMd5": string,
|
||||
"thumbMd5": string
|
||||
"fileTime": 87, // second
|
||||
"thumbSize": 314235, // byte
|
||||
"fileFormat": 2, // 2表示mp4?
|
||||
"fileSize": string, // byte
|
||||
"thumbWidth": number,
|
||||
"thumbHeight": number,
|
||||
"busiType": 0, // 未知
|
||||
"subBusiType": 0, // 未知
|
||||
"thumbPath": {},
|
||||
"transferStatus": 0, // 未知
|
||||
"progress": 0, // 下载进度?
|
||||
"invalidState": 0, // 未知
|
||||
"fileUuid": string, // 可以用于下载链接?
|
||||
"fileSubId": "",
|
||||
"fileBizId": null,
|
||||
"originVideoMd5": "",
|
||||
"import_rich_media_context": null,
|
||||
"sourceVideoCodecFormat": 0
|
||||
}
|
||||
|
||||
export interface RawMessage {
|
||||
msgId: string;
|
||||
msgShortId?: number; // 自己维护的消息id
|
||||
@@ -239,10 +294,13 @@ export interface RawMessage {
|
||||
arkElement: ArkElement;
|
||||
grayTipElement: GrayTipElement;
|
||||
faceElement: FaceElement;
|
||||
videoElement: VideoElement;
|
||||
fileElement: FileElement;
|
||||
}[];
|
||||
}
|
||||
|
||||
export enum GroupNotifyTypes {
|
||||
INVITE_ME = 1,
|
||||
INVITED_JOIN = 4, // 有人接受了邀请入群
|
||||
JOIN_REQUEST = 7,
|
||||
ADMIN_SET = 8,
|
||||
@@ -258,7 +316,7 @@ export interface GroupNotifies {
|
||||
}
|
||||
|
||||
export interface GroupNotify {
|
||||
|
||||
time: number; // 自己添加的字段,时间戳,毫秒, 用于判断收到短时间内收到重复的notify
|
||||
seq: string, // 转成数字,再除以1000应该就是时间戳?
|
||||
type: GroupNotifyTypes,
|
||||
status: 0, // 未知
|
||||
@@ -276,12 +334,12 @@ export interface GroupNotify {
|
||||
warningTips: string
|
||||
}
|
||||
|
||||
export enum GroupRequestOperateTypes{
|
||||
export enum GroupRequestOperateTypes {
|
||||
approve = 1,
|
||||
reject = 2
|
||||
}
|
||||
|
||||
export interface FriendRequest{
|
||||
export interface FriendRequest {
|
||||
friendUid: string,
|
||||
reqTime: string, // 时间戳,秒
|
||||
extWords: string, // 申请人填写的验证消息
|
||||
@@ -290,7 +348,8 @@ export interface FriendRequest{
|
||||
sourceId: number,
|
||||
groupCode: string
|
||||
}
|
||||
export interface FriendRequestNotify{
|
||||
|
||||
export interface FriendRequestNotify {
|
||||
data: {
|
||||
unreadNums: number,
|
||||
buddyReqs: FriendRequest[]
|
||||
|
@@ -10,6 +10,7 @@ import * as fs from "fs";
|
||||
import {log} from "../../common/utils";
|
||||
import {v4 as uuidv4} from "uuid"
|
||||
import {decodeCQCode} from "../cqcode";
|
||||
import {Send} from "express";
|
||||
|
||||
function checkSendMessage(sendMsgList: OB11MessageData[]) {
|
||||
function checkUri(uri: string): boolean {
|
||||
@@ -145,13 +146,13 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
||||
peerUid: selfInfo.uid
|
||||
}
|
||||
let nodeIds: string[] = []
|
||||
for (const messageNode of messageNodes){
|
||||
for (const messageNode of messageNodes) {
|
||||
// 一个node表示一个人的消息
|
||||
let nodeId = messageNode.data.id;
|
||||
// 有nodeId表示一个子转发消息卡片
|
||||
if (nodeId) {
|
||||
let nodeMsg = getHistoryMsgByShortId(nodeId);
|
||||
if (nodeMsg){
|
||||
if (nodeMsg) {
|
||||
nodeIds.push(nodeMsg.msgId);
|
||||
}
|
||||
} else {
|
||||
@@ -230,19 +231,23 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
||||
}
|
||||
break;
|
||||
case OB11MessageDataType.image:
|
||||
case OB11MessageDataType.file:
|
||||
case OB11MessageDataType.video:
|
||||
case OB11MessageDataType.voice: {
|
||||
const file = sendMsg.data?.file
|
||||
if (file) {
|
||||
const {path, isLocal} = (await uri2local(uuidv4(), file))
|
||||
const {path, isLocal} = (await uri2local(file))
|
||||
if (path) {
|
||||
if (!isLocal) { // 只删除http和base64转过来的文件
|
||||
deleteAfterSentFiles.push(path)
|
||||
}
|
||||
if (sendMsg.type === OB11MessageDataType.image) {
|
||||
sendElements.push(await SendMsgElementConstructor.pic(path))
|
||||
} else {
|
||||
sendElements.push(await SendMsgElementConstructor.ptt(path))
|
||||
const constructorMap = {
|
||||
[OB11MessageDataType.image]: SendMsgElementConstructor.pic,
|
||||
[OB11MessageDataType.voice]: SendMsgElementConstructor.ptt,
|
||||
[OB11MessageDataType.video]: SendMsgElementConstructor.video,
|
||||
[OB11MessageDataType.file]: SendMsgElementConstructor.file,
|
||||
}
|
||||
sendElements.push(await constructorMap[sendMsg.type](path));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
23
src/onebot11/action/SetGroupAdmin.ts
Normal file
23
src/onebot11/action/SetGroupAdmin.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import BaseAction from "./BaseAction";
|
||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
||||
import {getGroupMember} from "../../common/data";
|
||||
import {GroupMemberRole} from "../../ntqqapi/types";
|
||||
import {ActionName} from "./types";
|
||||
|
||||
interface Payload{
|
||||
group_id: number,
|
||||
user_id: number,
|
||||
enable: boolean
|
||||
}
|
||||
|
||||
export default class SetGroupAdmin extends BaseAction<Payload, null>{
|
||||
actionName = ActionName.SetGroupAdmin
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
const member = await getGroupMember(payload.group_id, payload.user_id)
|
||||
if(!member){
|
||||
throw `群成员${payload.user_id}不存在`
|
||||
}
|
||||
await NTQQApi.setMemberRole(payload.group_id.toString(), member.uid, payload.enable ? GroupMemberRole.admin : GroupMemberRole.normal)
|
||||
return null
|
||||
}
|
||||
}
|
23
src/onebot11/action/SetGroupBan.ts
Normal file
23
src/onebot11/action/SetGroupBan.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import BaseAction from "./BaseAction";
|
||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
||||
import {getGroupMember} from "../../common/data";
|
||||
import {ActionName} from "./types";
|
||||
|
||||
interface Payload{
|
||||
group_id: number,
|
||||
user_id: number,
|
||||
duration: number
|
||||
}
|
||||
|
||||
export default class SetGroupBan extends BaseAction<Payload, null>{
|
||||
actionName = ActionName.SetGroupBan
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
const member = await getGroupMember(payload.group_id, payload.user_id)
|
||||
if(!member){
|
||||
throw `群成员${payload.user_id}不存在`
|
||||
}
|
||||
await NTQQApi.banMember(payload.group_id.toString(),
|
||||
[{uid:member.uid, timeStamp: parseInt(payload.duration.toString())}])
|
||||
return null
|
||||
}
|
||||
}
|
23
src/onebot11/action/SetGroupCard.ts
Normal file
23
src/onebot11/action/SetGroupCard.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import BaseAction from "./BaseAction";
|
||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
||||
import {getGroupMember} from "../../common/data";
|
||||
import {GroupMemberRole} from "../../ntqqapi/types";
|
||||
import {ActionName} from "./types";
|
||||
|
||||
interface Payload{
|
||||
group_id: number,
|
||||
user_id: number,
|
||||
card: string
|
||||
}
|
||||
|
||||
export default class SetGroupCard extends BaseAction<Payload, null>{
|
||||
actionName = ActionName.SetGroupCard
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
const member = await getGroupMember(payload.group_id, payload.user_id)
|
||||
if(!member){
|
||||
throw `群成员${payload.user_id}不存在`
|
||||
}
|
||||
await NTQQApi.setMemberCard(payload.group_id.toString(), member.uid, payload.card || "")
|
||||
return null
|
||||
}
|
||||
}
|
22
src/onebot11/action/SetGroupKick.ts
Normal file
22
src/onebot11/action/SetGroupKick.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import BaseAction from "./BaseAction";
|
||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
||||
import {getGroupMember} from "../../common/data";
|
||||
import {ActionName} from "./types";
|
||||
|
||||
interface Payload{
|
||||
group_id: number,
|
||||
user_id: number,
|
||||
reject_add_request: boolean
|
||||
}
|
||||
|
||||
export default class SetGroupKick extends BaseAction<Payload, null>{
|
||||
actionName = ActionName.SetGroupKick
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
const member = await getGroupMember(payload.group_id, payload.user_id)
|
||||
if(!member){
|
||||
throw `群成员${payload.user_id}不存在`
|
||||
}
|
||||
await NTQQApi.kickMember(payload.group_id.toString(), [member.uid], !!payload.reject_add_request);
|
||||
return null
|
||||
}
|
||||
}
|
18
src/onebot11/action/SetGroupName.ts
Normal file
18
src/onebot11/action/SetGroupName.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import BaseAction from "./BaseAction";
|
||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
||||
import {ActionName} from "./types";
|
||||
|
||||
interface Payload {
|
||||
group_id: number,
|
||||
group_name: string
|
||||
}
|
||||
|
||||
export default class SetGroupName extends BaseAction<Payload, null> {
|
||||
actionName = ActionName.SetGroupName
|
||||
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
|
||||
await NTQQApi.setGroupName(payload.group_id.toString(), payload.group_name)
|
||||
return null
|
||||
}
|
||||
}
|
18
src/onebot11/action/SetGroupWholeBan.ts
Normal file
18
src/onebot11/action/SetGroupWholeBan.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import BaseAction from "./BaseAction";
|
||||
import {NTQQApi} from "../../ntqqapi/ntcall";
|
||||
import {ActionName} from "./types";
|
||||
|
||||
interface Payload {
|
||||
group_id: number,
|
||||
enable: boolean
|
||||
}
|
||||
|
||||
export default class SetGroupWholeBan extends BaseAction<Payload, null> {
|
||||
actionName = ActionName.SetGroupWholeBan
|
||||
|
||||
protected async _handle(payload: Payload): Promise<null> {
|
||||
|
||||
await NTQQApi.banGroup(payload.group_id.toString(), !!payload.enable)
|
||||
return null
|
||||
}
|
||||
}
|
@@ -22,6 +22,12 @@ import SetGroupLeave from "./SetGroupLeave";
|
||||
import GetGuildList from "./GetGuildList";
|
||||
import Debug from "./Debug";
|
||||
import SetFriendAddRequest from "./SetFriendAddRequest";
|
||||
import SetGroupWholeBan from "./SetGroupWholeBan";
|
||||
import SetGroupName from "./SetGroupName";
|
||||
import SetGroupBan from "./SetGroupBan";
|
||||
import SetGroupKick from "./SetGroupKick";
|
||||
import SetGroupAdmin from "./SetGroupAdmin";
|
||||
import SetGroupCard from "./SetGroupCard";
|
||||
|
||||
export const actionHandlers = [
|
||||
new Debug(),
|
||||
@@ -39,6 +45,12 @@ export const actionHandlers = [
|
||||
new CanSendRecord(),
|
||||
new CanSendImage(),
|
||||
new GetStatus(),
|
||||
new SetGroupWholeBan(),
|
||||
new SetGroupBan(),
|
||||
new SetGroupKick(),
|
||||
new SetGroupAdmin(),
|
||||
new SetGroupName(),
|
||||
new SetGroupCard(),
|
||||
|
||||
//以下为go-cqhttp api
|
||||
new GoCQHTTPSendGroupForwardMsg(),
|
||||
|
@@ -34,6 +34,12 @@ export enum ActionName {
|
||||
GetStatus = "get_status",
|
||||
CanSendRecord = "can_send_record",
|
||||
CanSendImage = "can_send_image",
|
||||
SetGroupKick = "set_group_kick",
|
||||
SetGroupBan = "set_group_ban",
|
||||
SetGroupWholeBan = "set_group_whole_ban",
|
||||
SetGroupAdmin = "set_group_admin",
|
||||
SetGroupCard = "set_group_card",
|
||||
SetGroupName = "set_group_name",
|
||||
// 以下为go-cqhttp api
|
||||
GoCQHTTP_SendGroupForwardMsg = "send_group_forward_msg",
|
||||
GoCQHTTP_SendPrivateForwardMsg = "send_private_forward_msg",
|
||||
|
@@ -23,7 +23,7 @@ export class OB11Constructor {
|
||||
const resMsg: OB11Message = {
|
||||
self_id: parseInt(selfInfo.uin),
|
||||
user_id: parseInt(msg.senderUin),
|
||||
time: parseInt(msg.msgTime) || 0,
|
||||
time: parseInt(msg.msgTime) * 1000 || Date.now(), // 13位时间戳,毫秒
|
||||
message_id: msg.msgShortId,
|
||||
real_id: msg.msgId,
|
||||
message_type: msg.chatType == ChatType.group ? "group" : "private",
|
||||
@@ -88,6 +88,14 @@ export class OB11Constructor {
|
||||
continue;
|
||||
}
|
||||
message_data["data"]["text"] = text
|
||||
} else if (element.replyElement) {
|
||||
message_data["type"] = "reply"
|
||||
const replyMsg = getHistoryMsgBySeq(element.replyElement.replayMsgSeq)
|
||||
if (replyMsg) {
|
||||
message_data["data"]["id"] = replyMsg.msgShortId.toString()
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
} else if (element.picElement) {
|
||||
message_data["type"] = "image"
|
||||
message_data["data"]["file_id"] = element.picElement.fileUuid
|
||||
@@ -99,15 +107,19 @@ export class OB11Constructor {
|
||||
element.elementId, element.picElement.thumbPath.get(0), element.picElement.sourcePath)
|
||||
} catch (e) {
|
||||
}
|
||||
} else if (element.replyElement) {
|
||||
message_data["type"] = "reply"
|
||||
const replyMsg = getHistoryMsgBySeq(element.replyElement.replayMsgSeq)
|
||||
if (replyMsg) {
|
||||
message_data["data"]["id"] = replyMsg.msgShortId.toString()
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
} else if (element.pttElement) {
|
||||
} else if (element.videoElement) {
|
||||
message_data["type"] = OB11MessageDataType.video;
|
||||
message_data["data"]["file"] = element.videoElement.filePath
|
||||
message_data["data"]["file_id"] = element.videoElement.fileUuid
|
||||
// 怎么拿到url呢
|
||||
} else if (element.fileElement) {
|
||||
message_data["type"] = OB11MessageDataType.file;
|
||||
message_data["data"]["file"] = element.fileElement.filePath
|
||||
message_data["data"]["file_id"] = element.fileElement.fileUuid
|
||||
message_data["data"]["file_size"] = element.fileElement.fileSize
|
||||
// 怎么拿到url呢
|
||||
}
|
||||
else if (element.pttElement) {
|
||||
message_data["type"] = OB11MessageDataType.voice;
|
||||
message_data["data"]["file"] = element.pttElement.filePath
|
||||
message_data["data"]["file_id"] = element.pttElement.fileUuid
|
||||
@@ -125,20 +137,26 @@ export class OB11Constructor {
|
||||
message_data["type"] = OB11MessageDataType.face;
|
||||
message_data["data"]["id"] = element.faceElement.faceIndex.toString();
|
||||
}
|
||||
|
||||
if (message_data.data.file) {
|
||||
let filePath: string = message_data.data.file;
|
||||
if (!enableLocalFile2Url) {
|
||||
message_data.data.file = "file://" + filePath
|
||||
} else { // 不使用本地路径
|
||||
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)
|
||||
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 {
|
||||
message_data.data.file = "base64://" + data
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -10,7 +10,7 @@ export enum EventType {
|
||||
|
||||
|
||||
export abstract class OB11BaseEvent {
|
||||
time = new Date().getTime();
|
||||
time = Date.now();
|
||||
self_id = parseInt(selfInfo.uin);
|
||||
post_type: EventType;
|
||||
}
|
@@ -1,7 +1,9 @@
|
||||
import {OB11GroupNoticeEvent} from "../notice/OB11GroupNoticeEvent";
|
||||
import {EventType} from "../OB11BaseEvent";
|
||||
|
||||
|
||||
export class OB11GroupRequestEvent extends OB11GroupNoticeEvent{
|
||||
post_type = EventType.REQUEST;
|
||||
request_type: "group" = "group";
|
||||
sub_type: "add" | "invite" = "add";
|
||||
comment: string;
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import {AtType, RawMessage} from "../ntqqapi/types";
|
||||
import {RawMessage} from "../ntqqapi/types";
|
||||
import {EventType} from "./event/OB11BaseEvent";
|
||||
|
||||
export interface OB11User {
|
||||
@@ -85,7 +85,9 @@ export interface OB11Return<DataType> {
|
||||
export enum OB11MessageDataType {
|
||||
text = "text",
|
||||
image = "image",
|
||||
video = "video",
|
||||
voice = "record",
|
||||
file = "file",
|
||||
at = "at",
|
||||
reply = "reply",
|
||||
json = "json",
|
||||
@@ -115,6 +117,14 @@ export interface OB11MessageRecord extends OB11MessageFileBase {
|
||||
type: OB11MessageDataType.voice
|
||||
}
|
||||
|
||||
export interface OB11MessageFile extends OB11MessageFileBase {
|
||||
type: OB11MessageDataType.file
|
||||
}
|
||||
|
||||
export interface OB11MessageVideo extends OB11MessageFileBase {
|
||||
type: OB11MessageDataType.video
|
||||
}
|
||||
|
||||
export interface OB11MessageAt {
|
||||
type: OB11MessageDataType.at
|
||||
data: {
|
||||
@@ -152,7 +162,7 @@ export type OB11MessageData =
|
||||
OB11MessageText |
|
||||
OB11MessageFace |
|
||||
OB11MessageAt | OB11MessageReply |
|
||||
OB11MessageImage | OB11MessageRecord |
|
||||
OB11MessageImage | OB11MessageRecord | OB11MessageFile | OB11MessageVideo |
|
||||
OB11MessageNode
|
||||
|
||||
export interface OB11PostSendMsg {
|
||||
|
@@ -1,10 +1,13 @@
|
||||
import {CONFIG_DIR, isGIF} from "../common/utils";
|
||||
import {v4 as uuidv4} from "uuid";
|
||||
import * as path from 'path';
|
||||
import {OB11MessageData} from "./types";
|
||||
|
||||
const fs = require("fs").promises;
|
||||
|
||||
export async function uri2local(fileName: string, uri: string){
|
||||
export async function uri2local(uri: string, fileName: string=null){
|
||||
if (!fileName){
|
||||
fileName = uuidv4();
|
||||
}
|
||||
let filePath = path.join(CONFIG_DIR, fileName)
|
||||
let url = new URL(uri);
|
||||
let res = {
|
||||
@@ -33,6 +36,8 @@ export async function uri2local(fileName: string, uri: string){
|
||||
let blob = await fetchRes.blob();
|
||||
let buffer = await blob.arrayBuffer();
|
||||
try {
|
||||
fileName = path.basename(url.pathname) || fileName
|
||||
filePath = path.join(CONFIG_DIR, fileName)
|
||||
await fs.writeFile(filePath, Buffer.from(buffer));
|
||||
} catch (e: any) {
|
||||
res.errMsg = `${url}下载失败,` + e.toString()
|
||||
|
@@ -117,19 +117,20 @@ async function onSettingWindowCreated(view: Element) {
|
||||
<setting-text>Access Token</setting-text>
|
||||
<input id="token" type="text" placeholder="可为空" value="${config.token}"/>
|
||||
</setting-item>
|
||||
<setting-item data-direction="row" class="vertical-list-item">
|
||||
<setting-item data-direction="row" class="vertical-list-item" style="width: 80%">
|
||||
<setting-text>ffmpeg路径</setting-text>
|
||||
<input id="ffmpegPath" class="input-text" type="text"
|
||||
style="width:80%;padding: 5px"
|
||||
value="${config.ffmpeg || ''}"/>
|
||||
</setting-item>
|
||||
<button id="selectFFMPEG" class="q-button q-button--small q-button--secondary">选择ffmpeg</button>
|
||||
</setting-item>
|
||||
<button id="save" class="q-button">保存</button>
|
||||
</setting-list>
|
||||
</setting-panel>
|
||||
<setting-panel>
|
||||
<setting-item data-direction="row" class="vertical-list-item">
|
||||
<setting-item data-direction="row" class="vertical-list-item" style="width: 80%">
|
||||
<setting-text>ffmpeg路径</setting-text>
|
||||
<input id="ffmpegPath" class="input-text" type="text"
|
||||
style="width:80%;padding: 5px"
|
||||
value="${config.ffmpeg || ''}"/>
|
||||
</setting-item>
|
||||
<button id="selectFFMPEG" class="q-button q-button--small q-button--secondary">选择ffmpeg</button>
|
||||
</setting-item>
|
||||
|
||||
<setting-item data-direction="row" class="vertical-list-item">
|
||||
<div>
|
||||
<setting-text>消息上报数据类型</setting-text>
|
||||
@@ -331,7 +332,8 @@ async function onSettingWindowCreated(view: Element) {
|
||||
doc.getElementById("selectFFMPEG")?.addEventListener("click", ()=>{
|
||||
window.llonebot.selectFile().then(selectPath=>{
|
||||
if (selectPath){
|
||||
(document.getElementById("ffmpegPath") as HTMLInputElement).value = selectPath;
|
||||
config.ffmpeg = (document.getElementById("ffmpegPath") as HTMLInputElement).value = selectPath;
|
||||
// window.llonebot.setConfig(config);
|
||||
}
|
||||
});
|
||||
})
|
||||
|
Reference in New Issue
Block a user