mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
f07f0111cd | ||
![]() |
923f72e5d3 | ||
![]() |
5b4001e411 | ||
![]() |
b950f01d51 |
@@ -4,7 +4,7 @@
|
|||||||
"name": "LLOneBot",
|
"name": "LLOneBot",
|
||||||
"slug": "LLOneBot",
|
"slug": "LLOneBot",
|
||||||
"description": "LiteLoaderQQNT的OneBotApi",
|
"description": "LiteLoaderQQNT的OneBotApi",
|
||||||
"version": "1.2.3",
|
"version": "1.2.5",
|
||||||
"thumbnail": "./icon.png",
|
"thumbnail": "./icon.png",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "linyuchen",
|
"name": "linyuchen",
|
||||||
|
@@ -8,4 +8,5 @@ export const CHANNEL_UPDATE_FRIENDS = "llonebot_update_friends"
|
|||||||
export const CHANNEL_LOG = "llonebot_log"
|
export const CHANNEL_LOG = "llonebot_log"
|
||||||
export const CHANNEL_POST_ONEBOT_DATA = "llonebot_post_onebot_data"
|
export const CHANNEL_POST_ONEBOT_DATA = "llonebot_post_onebot_data"
|
||||||
export const CHANNEL_SET_SELF_INFO= "llonebot_set_self_info"
|
export const CHANNEL_SET_SELF_INFO= "llonebot_set_self_info"
|
||||||
export const CHANNEL_DOWNLOAD_FILE= "llonebot_download_file"
|
export const CHANNEL_DOWNLOAD_FILE= "llonebot_download_file"
|
||||||
|
export const CHANNEL_DELETE_FILE= "llonebot_delete_file"
|
||||||
|
1
src/global.d.ts
vendored
1
src/global.d.ts
vendored
@@ -44,6 +44,7 @@ declare var llonebot: {
|
|||||||
getConfig():Promise<Config>;
|
getConfig():Promise<Config>;
|
||||||
setSelfInfo(selfInfo: SelfInfo):void;
|
setSelfInfo(selfInfo: SelfInfo):void;
|
||||||
downloadFile(arg: {uri: string, localFilePath: string}):Promise<string>;
|
downloadFile(arg: {uri: string, localFilePath: string}):Promise<string>;
|
||||||
|
deleteFile(path: string[]):Promise<void>;
|
||||||
};
|
};
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
@@ -1,10 +1,49 @@
|
|||||||
import {sendIPCRecallQQMsg, sendIPCSendQQMsg} from "./IPCSend";
|
|
||||||
|
|
||||||
const express = require("express");
|
const express = require("express");
|
||||||
const bodyParser = require('body-parser');
|
const bodyParser = require('body-parser');
|
||||||
import {OnebotGroupMemberRole, PostDataAction, PostDataSendMsg} from "../common/types";
|
import {sendIPCRecallQQMsg, sendIPCSendQQMsg} from "./IPCSend";
|
||||||
|
import {OnebotGroupMemberRole, PostDataAction, PostDataSendMsg, SendMessage} from "../common/types";
|
||||||
import {friends, groups, selfInfo} from "./data";
|
import {friends, groups, selfInfo} from "./data";
|
||||||
|
|
||||||
|
// @SiberianHusky 2021-08-15
|
||||||
|
function checkSendMessage(sendMsgList: SendMessage[]) {
|
||||||
|
function checkUri(uri: string): boolean {
|
||||||
|
const pattern = /^(file:\/\/|http:\/\/|https:\/\/|base64:\/\/)/;
|
||||||
|
return pattern.test(uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let msg of sendMsgList) {
|
||||||
|
if (msg["type"] && msg["data"]) {
|
||||||
|
let type = msg["type"];
|
||||||
|
let data = msg["data"];
|
||||||
|
if (type === "text" && !data["text"]) {
|
||||||
|
return 400;
|
||||||
|
} else if (["image", "voice"].includes(type)) {
|
||||||
|
if (!data["file"]) {
|
||||||
|
return 400;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
if (checkUri(data["file"])) {
|
||||||
|
return 200;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return 400;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (type === "at" && !data["qq"]) {
|
||||||
|
return 400;
|
||||||
|
} else if (type === "reply" && !data["id"]) {
|
||||||
|
return 400;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return 400
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 200;
|
||||||
|
}
|
||||||
|
// ==end==
|
||||||
|
|
||||||
function handlePost(jsonData: any) {
|
function handlePost(jsonData: any) {
|
||||||
if (!jsonData.params) {
|
if (!jsonData.params) {
|
||||||
jsonData.params = jsonData
|
jsonData.params = jsonData
|
||||||
@@ -21,11 +60,20 @@ function handlePost(jsonData: any) {
|
|||||||
} else if (jsonData.action == "send_private_msg" || jsonData.action == "send_group_msg") {
|
} else if (jsonData.action == "send_private_msg" || jsonData.action == "send_group_msg") {
|
||||||
if (jsonData.action == "send_private_msg") {
|
if (jsonData.action == "send_private_msg") {
|
||||||
jsonData.message_type = "private"
|
jsonData.message_type = "private"
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
jsonData.message_type = "group"
|
jsonData.message_type = "group"
|
||||||
}
|
}
|
||||||
sendIPCSendQQMsg(jsonData);
|
// @SiberianHuskY 2021-10-20 22:00:00
|
||||||
|
resData.status = checkSendMessage(jsonData.message);
|
||||||
|
if (resData.status == 200) {
|
||||||
|
resData.message = "发送成功";
|
||||||
|
resData.data = jsonData.message;
|
||||||
|
sendIPCSendQQMsg(jsonData);
|
||||||
|
} else {
|
||||||
|
resData.message = "发送失败, 请检查消息格式";
|
||||||
|
resData.data = jsonData.message;
|
||||||
|
}
|
||||||
|
// == end ==
|
||||||
} else if (jsonData.action == "get_group_list") {
|
} else if (jsonData.action == "get_group_list") {
|
||||||
resData["data"] = groups.map(group => {
|
resData["data"] = groups.map(group => {
|
||||||
return {
|
return {
|
||||||
@@ -41,8 +89,7 @@ function handlePost(jsonData: any) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
} else if (jsonData.action == "get_group_info") {
|
||||||
else if (jsonData.action == "get_group_info") {
|
|
||||||
let group = groups.find(group => group.uid == jsonData.params.group_id)
|
let group = groups.find(group => group.uid == jsonData.params.group_id)
|
||||||
if (group) {
|
if (group) {
|
||||||
resData["data"] = {
|
resData["data"] = {
|
||||||
@@ -51,10 +98,9 @@ function handlePost(jsonData: any) {
|
|||||||
member_count: group.members.length,
|
member_count: group.members.length,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else if (jsonData.action == "get_group_member_info") {
|
||||||
else if (jsonData.action == "get_group_member_info") {
|
|
||||||
let member = groups.find(group => group.uid == jsonData.params.group_id)?.members?.find(member => member.uin == jsonData.params.user_id)
|
let member = groups.find(group => group.uid == jsonData.params.group_id)?.members?.find(member => member.uin == jsonData.params.user_id)
|
||||||
resData["data"] ={
|
resData["data"] = {
|
||||||
user_id: member.uin,
|
user_id: member.uin,
|
||||||
user_name: member.nick,
|
user_name: member.nick,
|
||||||
user_display_name: member.cardName || member.nick,
|
user_display_name: member.cardName || member.nick,
|
||||||
@@ -62,8 +108,7 @@ function handlePost(jsonData: any) {
|
|||||||
card: member.cardName,
|
card: member.cardName,
|
||||||
role: OnebotGroupMemberRole[member.role],
|
role: OnebotGroupMemberRole[member.role],
|
||||||
}
|
}
|
||||||
}
|
} else if (jsonData.action == "get_group_member_list") {
|
||||||
else if (jsonData.action == "get_group_member_list") {
|
|
||||||
let group = groups.find(group => group.uid == jsonData.params.group_id)
|
let group = groups.find(group => group.uid == jsonData.params.group_id)
|
||||||
if (group) {
|
if (group) {
|
||||||
resData["data"] = group?.members?.map(member => {
|
resData["data"] = group?.members?.map(member => {
|
||||||
@@ -109,6 +154,7 @@ export function startExpress(port: number) {
|
|||||||
res.send(resData)
|
res.send(resData)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const actionList: PostDataAction[] = ["get_login_info", "send_private_msg", "send_group_msg",
|
const actionList: PostDataAction[] = ["get_login_info", "send_private_msg", "send_group_msg",
|
||||||
"get_group_list", "get_friend_list", "delete_msg", "get_group_member_list", "get_group_member_info"]
|
"get_group_list", "get_friend_list", "delete_msg", "get_group_member_list", "get_group_member_info"]
|
||||||
|
|
||||||
|
@@ -13,7 +13,7 @@ import {
|
|||||||
CHANNEL_SET_CONFIG,
|
CHANNEL_SET_CONFIG,
|
||||||
CHANNEL_START_HTTP_SERVER,
|
CHANNEL_START_HTTP_SERVER,
|
||||||
CHANNEL_UPDATE_FRIENDS,
|
CHANNEL_UPDATE_FRIENDS,
|
||||||
CHANNEL_UPDATE_GROUPS
|
CHANNEL_UPDATE_GROUPS, CHANNEL_DELETE_FILE
|
||||||
} from "../common/IPCChannel";
|
} from "../common/IPCChannel";
|
||||||
import {ConfigUtil} from "./config";
|
import {ConfigUtil} from "./config";
|
||||||
import {startExpress} from "./HttpServer";
|
import {startExpress} from "./HttpServer";
|
||||||
@@ -123,6 +123,12 @@ function onLoad(plugin: any) {
|
|||||||
selfInfo.user_id = arg.user_id;
|
selfInfo.user_id = arg.user_id;
|
||||||
selfInfo.nickname = arg.nickname;
|
selfInfo.nickname = arg.nickname;
|
||||||
})
|
})
|
||||||
|
|
||||||
|
ipcMain.on(CHANNEL_DELETE_FILE, (event: any, arg: string[]) => {
|
||||||
|
for (const path of arg) {
|
||||||
|
fs.unlinkSync(path);
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -6,7 +6,7 @@ import {
|
|||||||
CHANNEL_GET_CONFIG, CHANNEL_SET_SELF_INFO, CHANNEL_LOG, CHANNEL_POST_ONEBOT_DATA,
|
CHANNEL_GET_CONFIG, CHANNEL_SET_SELF_INFO, CHANNEL_LOG, CHANNEL_POST_ONEBOT_DATA,
|
||||||
CHANNEL_RECALL_MSG, CHANNEL_SEND_MSG,
|
CHANNEL_RECALL_MSG, CHANNEL_SEND_MSG,
|
||||||
CHANNEL_SET_CONFIG,
|
CHANNEL_SET_CONFIG,
|
||||||
CHANNEL_START_HTTP_SERVER, CHANNEL_UPDATE_FRIENDS, CHANNEL_UPDATE_GROUPS
|
CHANNEL_START_HTTP_SERVER, CHANNEL_UPDATE_FRIENDS, CHANNEL_UPDATE_GROUPS, CHANNEL_DELETE_FILE
|
||||||
} from "./common/IPCChannel";
|
} from "./common/IPCChannel";
|
||||||
|
|
||||||
|
|
||||||
@@ -50,8 +50,11 @@ contextBridge.exposeInMainWorld("llonebot", {
|
|||||||
setSelfInfo(selfInfo: SelfInfo){
|
setSelfInfo(selfInfo: SelfInfo){
|
||||||
ipcRenderer.invoke(CHANNEL_SET_SELF_INFO, selfInfo)
|
ipcRenderer.invoke(CHANNEL_SET_SELF_INFO, selfInfo)
|
||||||
},
|
},
|
||||||
downloadFile: async (arg: {uri: string, localFilePath: string}) => {
|
downloadFile: (arg: {uri: string, localFilePath: string}) => {
|
||||||
return ipcRenderer.invoke(CHANNEL_DOWNLOAD_FILE, arg);
|
return ipcRenderer.invoke(CHANNEL_DOWNLOAD_FILE, arg);
|
||||||
},
|
},
|
||||||
|
deleteFile: async (localFilePath: string[]) => {
|
||||||
|
ipcRenderer.send(CHANNEL_DELETE_FILE, localFilePath);
|
||||||
|
}
|
||||||
// startExpress,
|
// startExpress,
|
||||||
});
|
});
|
@@ -20,7 +20,7 @@ async function getUserInfo(uid: string): Promise<User> {
|
|||||||
return user
|
return user
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getFriends(){
|
async function getFriends() {
|
||||||
let _friends = await window.LLAPI.getFriendsList(false)
|
let _friends = await window.LLAPI.getFriendsList(false)
|
||||||
for (let friend of _friends) {
|
for (let friend of _friends) {
|
||||||
let existFriend = friends.find(f => f.uin == friend.uin)
|
let existFriend = friends.find(f => f.uin == friend.uin)
|
||||||
@@ -210,6 +210,7 @@ async function listenSendMessage(postData: PostDataSendMsg) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (peer) {
|
if (peer) {
|
||||||
|
let sendFiles: string[] = [];
|
||||||
for (let message of postData.params.message) {
|
for (let message of postData.params.message) {
|
||||||
if (message.type == "at") {
|
if (message.type == "at") {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
@@ -242,6 +243,7 @@ async function listenSendMessage(postData: PostDataSendMsg) {
|
|||||||
await window.llonebot.downloadFile({uri: url, localFilePath: localFilePath})
|
await window.llonebot.downloadFile({uri: url, localFilePath: localFilePath})
|
||||||
}
|
}
|
||||||
message.file = localFilePath
|
message.file = localFilePath
|
||||||
|
sendFiles.push(localFilePath);
|
||||||
} else if (message.type == "reply") {
|
} else if (message.type == "reply") {
|
||||||
let msgId = message.data?.id || message.msgId
|
let msgId = message.data?.id || message.msgId
|
||||||
let replyMessage = msgHistory.find(msg => msg.raw.msgId == msgId)
|
let replyMessage = msgHistory.find(msg => msg.raw.msgId == msgId)
|
||||||
@@ -249,9 +251,11 @@ async function listenSendMessage(postData: PostDataSendMsg) {
|
|||||||
message.msgSeq = replyMessage?.raw.msgSeq || ""
|
message.msgSeq = replyMessage?.raw.msgSeq || ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 发送完之后要删除下载的文件
|
|
||||||
console.log("发送消息", postData)
|
console.log("发送消息", postData)
|
||||||
window.LLAPI.sendMessage(peer, postData.params.message).then(res => console.log("消息发送成功:", peer, postData.params.message),
|
window.LLAPI.sendMessage(peer, postData.params.message).then(res => {
|
||||||
|
console.log("消息发送成功:", peer, postData.params.message)
|
||||||
|
window.llonebot.deleteFile(sendFiles);
|
||||||
|
},
|
||||||
err => console.log("消息发送失败", postData, err))
|
err => console.log("消息发送失败", postData, err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -305,6 +309,7 @@ function onLoad() {
|
|||||||
})
|
})
|
||||||
console.log("chatListEle", chatListEle)
|
console.log("chatListEle", chatListEle)
|
||||||
}
|
}
|
||||||
|
|
||||||
getFriends().then();
|
getFriends().then();
|
||||||
getGroups().then(() => {
|
getGroups().then(() => {
|
||||||
getGroupsMembers(groups).then(() => {
|
getGroupsMembers(groups).then(() => {
|
||||||
|
Reference in New Issue
Block a user