mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
feat: upload private file
This commit is contained in:
parent
ac852cc382
commit
05f0985f7f
@ -1,27 +1,32 @@
|
|||||||
import BaseAction from "../BaseAction";
|
import BaseAction from "../BaseAction";
|
||||||
import {getGroup} from "../../../common/data";
|
import {getGroup, getUidByUin} 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 fs from "fs";
|
import fs from "fs";
|
||||||
import {NTQQMsgApi} from "../../../ntqqapi/api/msg";
|
import {NTQQMsgApi, Peer} from "../../../ntqqapi/api/msg";
|
||||||
import {uri2local} from "../../../common/utils";
|
import {uri2local} from "../../../common/utils";
|
||||||
|
|
||||||
interface Payload{
|
interface Payload{
|
||||||
group_id: number
|
user_id: number
|
||||||
|
group_id?: number
|
||||||
file: string
|
file: string
|
||||||
name: string
|
name: string
|
||||||
folder: string
|
folder: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class GoCQHTTPUploadGroupFile extends BaseAction<Payload, null> {
|
class GoCQHTTPUploadFileBase extends BaseAction<Payload, null> {
|
||||||
actionName = ActionName.GoCQHTTP_UploadGroupFile
|
actionName = ActionName.GoCQHTTP_UploadGroupFile
|
||||||
|
|
||||||
protected async _handle(payload: Payload): Promise<null> {
|
|
||||||
const group = await getGroup(payload.group_id.toString());
|
getPeer(payload: Payload): Peer {
|
||||||
if (!group){
|
if (payload.user_id){
|
||||||
throw new Error(`群组${payload.group_id}不存在`)
|
return {chatType: ChatType.friend, peerUid: getUidByUin(payload.user_id.toString())}
|
||||||
}
|
}
|
||||||
|
return {chatType: ChatType.group, peerUid: payload.group_id.toString()}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async _handle(payload: Payload): Promise<null> {
|
||||||
let file = payload.file;
|
let file = payload.file;
|
||||||
if (fs.existsSync(file)){
|
if (fs.existsSync(file)){
|
||||||
file = `file://${file}`
|
file = `file://${file}`
|
||||||
@ -31,7 +36,16 @@ 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 NTQQMsgApi.sendMsg({chatType: ChatType.group, peerUid: group.groupCode}, [sendFileEle]);
|
await NTQQMsgApi.sendMsg(this.getPeer(payload), [sendFileEle]);
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export class GoCQHTTPUploadGroupFile extends GoCQHTTPUploadFileBase {
|
||||||
|
actionName = ActionName.GoCQHTTP_UploadGroupFile
|
||||||
|
}
|
||||||
|
|
||||||
|
export class GoCQHTTPUploadPrivateFile extends GoCQHTTPUploadFileBase {
|
||||||
|
actionName = ActionName.GoCQHTTP_UploadPrivateFile
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user