mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
研究编译export
This commit is contained in:
parent
27a6ddb554
commit
a404b369c3
BIN
dist/icon.png
vendored
BIN
dist/icon.png
vendored
Binary file not shown.
Before Width: | Height: | Size: 1.3 KiB |
20
dist/main.js
vendored
20
dist/main.js
vendored
@ -1,20 +0,0 @@
|
||||
// 运行在 Electron 主进程 下的插件入口
|
||||
|
||||
|
||||
// 加载插件时触发
|
||||
function onLoad(plugin) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
// 创建窗口时触发
|
||||
function onBrowserWindowCreated(window, plugin) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
// 这两个函数都是可选的
|
||||
module.exports = {
|
||||
onLoad,
|
||||
onBrowserWindowCreated
|
||||
}
|
31
dist/manifest.json
vendored
31
dist/manifest.json
vendored
@ -1,31 +0,0 @@
|
||||
{
|
||||
"manifest_version": 3,
|
||||
"type": "extension",
|
||||
"name": "LLOneBot",
|
||||
"slug": "LLOneBot",
|
||||
"description": "LiteLoaderQQNT的OneBotApi",
|
||||
"version": "0.1.0",
|
||||
"thumbnail": "./icon.png",
|
||||
"author": {
|
||||
"name": "linyuchen",
|
||||
"link": "https://github.com/linyuchen"
|
||||
},
|
||||
"repository": {
|
||||
"repo": "linyuchen/LLOneBot",
|
||||
"branch": "main",
|
||||
"use_release": {
|
||||
"tag": "latest",
|
||||
"name": "LLOneBot.zip"
|
||||
}
|
||||
},
|
||||
"platform": [
|
||||
"win32",
|
||||
"linux",
|
||||
"darwin"
|
||||
],
|
||||
"injects": {
|
||||
"renderer": "./renderer.js",
|
||||
"main": "./main.js",
|
||||
"preload": "./preload.js"
|
||||
}
|
||||
}
|
8
dist/preload.js
vendored
8
dist/preload.js
vendored
@ -1,8 +0,0 @@
|
||||
// Electron 主进程 与 渲染进程 交互的桥梁
|
||||
const { contextBridge } = require("electron");
|
||||
|
||||
|
||||
// 在window对象下导出只读对象
|
||||
contextBridge.exposeInMainWorld("plugin_template", {
|
||||
|
||||
});
|
1284
package-lock.json
generated
1284
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -4,11 +4,17 @@
|
||||
"description": "NTQQLiteLoaderOneBotApi",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"build": " tsc src/renderer.ts --outDir dist && vite build"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"express": "^4.18.2",
|
||||
"typescript": "^5.2.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/express": "^4.17.20",
|
||||
"vite": "^4.5.0"
|
||||
}
|
||||
}
|
||||
|
52
src/global.d.ts
vendored
52
src/global.d.ts
vendored
@ -10,16 +10,32 @@ declare type Peer = {
|
||||
}
|
||||
|
||||
interface MessageElement{
|
||||
elements:{
|
||||
type: "text",
|
||||
content: string,
|
||||
raw: {
|
||||
textElement: {
|
||||
atType: AtType
|
||||
atUid: string
|
||||
raw: {
|
||||
elements:{
|
||||
raw: {
|
||||
replyElement: {
|
||||
senderUid: string, // 原消息发送者QQ号
|
||||
sourceMsgIsIncPic: boolean; // 原消息是否有图片
|
||||
sourceMsgText: string;
|
||||
sourceMsgIdInRecords: string; // 原消息id
|
||||
},
|
||||
textElement: {
|
||||
atType: AtType
|
||||
atUid: string,
|
||||
content: string
|
||||
},
|
||||
picElement: {
|
||||
sourcePath: string // 图片本地路径
|
||||
picWidth: number
|
||||
picHeight: number
|
||||
fileSize: number
|
||||
fileName: string
|
||||
fileUuid: string
|
||||
}
|
||||
}
|
||||
}
|
||||
}[]
|
||||
}[]
|
||||
}
|
||||
|
||||
peer: Peer,
|
||||
sender: {
|
||||
uid: string // 一串加密的字符串
|
||||
@ -41,6 +57,14 @@ declare type Group = {
|
||||
name: string;
|
||||
}
|
||||
|
||||
declare type SendMessage = {
|
||||
type: "text",
|
||||
content: string,
|
||||
} | {
|
||||
type: "image",
|
||||
file: string,
|
||||
}
|
||||
|
||||
declare var LLAPI: {
|
||||
on(event: "new-messages", callback: (data: MessageElement[]) => void): void;
|
||||
getAccountInfo(): Promise<{
|
||||
@ -50,15 +74,7 @@ declare var LLAPI: {
|
||||
|
||||
// uid是一串加密的字符串, 收到群消息的时候,可以用此函数获取群成员的qq号
|
||||
getUserInfo(uid: string): Promise<User>;
|
||||
sendMessage(peer: Peer, message:
|
||||
{
|
||||
type: "text",
|
||||
content: string,}|
|
||||
{
|
||||
type: "image",
|
||||
file: string,
|
||||
}
|
||||
): void
|
||||
sendMessage(peer: Peer, message: SendMessage[]): Promise<void>;
|
||||
getGroupsList(forced: boolean): Promise<Group[]>
|
||||
getFriendsList(forced: boolean): Promise<User[]>
|
||||
};
|
||||
|
@ -1,20 +0,0 @@
|
||||
// 运行在 Electron 渲染进程 下的页面脚本
|
||||
|
||||
|
||||
// 页面加载完成时触发
|
||||
function onLoad() {
|
||||
LLAPI.on("new-messages")
|
||||
}
|
||||
|
||||
|
||||
// 打开设置界面时触发
|
||||
function onConfigView(view) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
// 这两个函数都是可选的
|
||||
export {
|
||||
onLoad,
|
||||
onConfigView
|
||||
}
|
133
src/renderer.ts
133
src/renderer.ts
@ -1,13 +1,140 @@
|
||||
/// <reference path="./global.d.ts" />
|
||||
|
||||
// import express from "express";
|
||||
|
||||
|
||||
const host = "http://localhost:5000"
|
||||
|
||||
let self_qq: string = ""
|
||||
|
||||
let uid_maps: Record<string, string> = {} // 一串加密的字符串 -> qq号
|
||||
|
||||
let groups: Group[] = []
|
||||
let friends: User[] = []
|
||||
|
||||
function getFriend(qq: string){
|
||||
return friends.find(friend => friend.uid == qq)
|
||||
}
|
||||
|
||||
function getGroup(qq: string){
|
||||
return groups.find(group => group.uid == qq)
|
||||
}
|
||||
|
||||
function onLoad(){
|
||||
LLAPI.getAccountInfo().then(accountInfo => {
|
||||
self_qq = accountInfo.uid
|
||||
})
|
||||
|
||||
LLAPI.getGroupsList(false).then(groupsList => {
|
||||
groups = groupsList
|
||||
})
|
||||
|
||||
// const app = express();
|
||||
// const port = 3000;
|
||||
//
|
||||
// // 中间件,用于解析POST请求的请求体
|
||||
// app.use(express.urlencoded({ extended: true }));
|
||||
// app.use(express.json());
|
||||
//
|
||||
// // 处理POST请求的路由
|
||||
// app.post('/', (req: any, res: any) => {
|
||||
// let json_data: {action: string, params: {
|
||||
// user_id: string,
|
||||
// group_id: string,
|
||||
// message: SendMessage[];
|
||||
// }} = req.body;
|
||||
// let peer: Peer| null = null;
|
||||
// if (json_data.action == "send_private_msg"){
|
||||
// let friend = getFriend(json_data.params.user_id)
|
||||
// if (friend) {
|
||||
// peer = {
|
||||
// chatType: "private",
|
||||
// name: friend.nickName,
|
||||
// uid: friend.uin
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// else if (json_data.action == "send_group_msg"){
|
||||
// let group = getGroup(json_data.params.group_id)
|
||||
// if (group){
|
||||
// peer = {
|
||||
// chatType: "group",
|
||||
// name: group.name,
|
||||
// uid: group.uid
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if (peer) {
|
||||
// LLAPI.sendMessage(peer, json_data.params.message).then(res => console.log("消息发送成功:", res),
|
||||
// err => console.log("消息发送失败", json_data, err))
|
||||
// }
|
||||
// console.log(req.body); // 输出POST请求的请求体数据
|
||||
// res.send('POST请求已收到');
|
||||
// });
|
||||
//
|
||||
// // 启动服务器监听指定端口
|
||||
// app.listen(port, () => {
|
||||
// console.log(`服务器已启动,监听端口 ${port}`);
|
||||
// });
|
||||
|
||||
LLAPI.on("new-messages", (messages) => {
|
||||
console.log("收到新消息", messages)
|
||||
messages.forEach(message => {
|
||||
let onebot_message_data: any = {
|
||||
self: {
|
||||
platform: "qq",
|
||||
user_id: self_qq
|
||||
},
|
||||
time: 0,
|
||||
type: "message",
|
||||
detail_type: message.peer.chatType,
|
||||
sub_type: "",
|
||||
message: message.raw.elements.map(element=>{
|
||||
let message_data: any = {
|
||||
data: {}
|
||||
}
|
||||
if (element.raw.textElement?.atType == AtType.atUser){
|
||||
message_data["type"] = "at"
|
||||
message_data["data"]["mention"] = element.raw.textElement.atUid
|
||||
}
|
||||
else if (element.raw.textElement){
|
||||
message_data["type"] = "text"
|
||||
message_data["data"]["text"] = element.raw.textElement.content
|
||||
}
|
||||
else if (element.raw.picElement){
|
||||
message_data["type"] = "image"
|
||||
message_data["data"]["file_id"] = element.raw.picElement.fileUuid
|
||||
message_data["data"]["path"] = element.raw.picElement.sourcePath
|
||||
}
|
||||
else if (element.raw.replyElement){
|
||||
message_data["type"] = "reply"
|
||||
message_data["data"]["reply"] = element.raw.replyElement.sourceMsgIdInRecords
|
||||
}
|
||||
return message_data
|
||||
})
|
||||
}
|
||||
|
||||
if (message.peer.chatType == "group"){
|
||||
onebot_message_data["group_id"] = message.peer.uid
|
||||
// todo: 将加密的uid转成qq号
|
||||
onebot_message_data["user_id"] = message.sender.uid
|
||||
}
|
||||
else if (message.peer.chatType == "private"){
|
||||
onebot_message_data["user_id"] = message.peer.uid
|
||||
}
|
||||
|
||||
fetch(host + "", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify(onebot_message_data)
|
||||
}).then(res => {}, err => {
|
||||
console.log(err)
|
||||
})
|
||||
});
|
||||
});
|
||||
console.log("getAccountInfo", LLAPI.getAccountInfo());
|
||||
console.log("getFriendList", LLAPI.getFriendList(false));
|
||||
console.log("getGroupList", LLAPI.getGroupList(false));
|
||||
// console.log("getAccountInfo", LLAPI.getAccountInfo());
|
||||
}
|
||||
|
||||
// 打开设置界面时触发
|
||||
|
@ -1,10 +1,12 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"module": "commonjs",
|
||||
"module": "esnext",
|
||||
"outDir": "./dist",
|
||||
"strict": true,
|
||||
"esModuleInterop": true
|
||||
"declaration": true,
|
||||
"esModuleInterop": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"moduleResolution": "node"
|
||||
},
|
||||
"include": [
|
||||
"src"
|
||||
|
16
vite.config.js
Normal file
16
vite.config.js
Normal file
@ -0,0 +1,16 @@
|
||||
import { defineConfig } from 'vite';
|
||||
import { resolve } from 'path';
|
||||
|
||||
console.log(resolve(__dirname, 'src/renderer.ts'))
|
||||
export default defineConfig({
|
||||
build: {
|
||||
rollupOptions: {
|
||||
input: {
|
||||
renderer: resolve(__dirname, 'dist/renderer.js') // 入口文件的路径
|
||||
},
|
||||
output: {
|
||||
entryFileNames: '[name].js', // 打包后的文件名
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user