mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
成功加载express
This commit is contained in:
parent
a404b369c3
commit
ab17e3cd30
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,2 +1,2 @@
|
||||
node_modules/
|
||||
dist/renderer.js
|
||||
dist/
|
@ -1 +0,0 @@
|
||||
npx tsc src/renderer.ts --outDir dist
|
31
manifest.json
Normal file
31
manifest.json
Normal file
@ -0,0 +1,31 @@
|
||||
{
|
||||
"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": "./dist/renderer.js",
|
||||
"main": "./dist/main.js",
|
||||
"preload": "./dist/preload.js"
|
||||
}
|
||||
}
|
1535
package-lock.json
generated
1535
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
12
package.json
12
package.json
@ -5,16 +5,22 @@
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"build": " tsc src/renderer.ts --outDir dist && vite build"
|
||||
"build": "tsc"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"express": "^4.18.2",
|
||||
"typescript": "^5.2.2"
|
||||
"path": "^0.12.7",
|
||||
"stream": "^0.0.2",
|
||||
"typescript": "^5.2.2",
|
||||
"url": "^0.11.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/express": "^4.17.20",
|
||||
"vite": "^4.5.0"
|
||||
"ts-loader": "^9.5.0",
|
||||
"vite": "^4.5.0",
|
||||
"webpack": "^5.89.0",
|
||||
"webpack-cli": "^5.1.4"
|
||||
}
|
||||
}
|
||||
|
0
src/global.d.ts → src/llapi.d.ts
vendored
0
src/global.d.ts → src/llapi.d.ts
vendored
20
src/main.js
20
src/main.js
@ -1,20 +0,0 @@
|
||||
// 运行在 Electron 主进程 下的插件入口
|
||||
|
||||
|
||||
// 加载插件时触发
|
||||
function onLoad(plugin) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
// 创建窗口时触发
|
||||
function onBrowserWindowCreated(window, plugin) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
// 这两个函数都是可选的
|
||||
module.exports = {
|
||||
onLoad,
|
||||
onBrowserWindowCreated
|
||||
}
|
81
src/main.ts
Normal file
81
src/main.ts
Normal file
@ -0,0 +1,81 @@
|
||||
// 运行在 Electron 主进程 下的插件入口
|
||||
const express = require("express");
|
||||
|
||||
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(plugin: any) {
|
||||
|
||||
const app = express();
|
||||
const port = 3000;
|
||||
|
||||
// 中间件,用于解析POST请求的请求体
|
||||
app.use(express.urlencoded({ extended: true }));
|
||||
app.use(express.json());
|
||||
|
||||
app.get('/', (req: any, res: any) => {
|
||||
res.send('llonebot已启动');
|
||||
})
|
||||
// 处理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}`);
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
// 创建窗口时触发
|
||||
function onBrowserWindowCreated(window: any, plugin: any) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
// 这两个函数都是可选的
|
||||
module.exports = {
|
||||
onLoad,
|
||||
onBrowserWindowCreated
|
||||
}
|
@ -1,8 +1,5 @@
|
||||
// Electron 主进程 与 渲染进程 交互的桥梁
|
||||
const { contextBridge } = require("electron");
|
||||
|
||||
|
||||
// 在window对象下导出只读对象
|
||||
contextBridge.exposeInMainWorld("plugin_template", {
|
||||
|
||||
});
|
@ -1,25 +1,13 @@
|
||||
/// <reference path="./global.d.ts" />
|
||||
/// <reference path="./llapi.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
|
||||
@ -29,53 +17,7 @@ function onLoad(){
|
||||
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)
|
||||
|
@ -1,9 +1,9 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "esnext",
|
||||
"target": "es6",
|
||||
"module": "es6",
|
||||
"outDir": "./dist",
|
||||
"strict": true,
|
||||
"declaration": true,
|
||||
"esModuleInterop": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"moduleResolution": "node"
|
||||
|
@ -1,12 +1,12 @@
|
||||
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') // 入口文件的路径
|
||||
// renderer: resolve(__dirname, 'dist/renderer.js') // 入口文件的路径
|
||||
renderer: resolve(__dirname, 'src/renderer.ts') // 入口文件的路径
|
||||
},
|
||||
output: {
|
||||
entryFileNames: '[name].js', // 打包后的文件名
|
||||
|
31
webpack.config.js
Normal file
31
webpack.config.js
Normal file
@ -0,0 +1,31 @@
|
||||
const path = require('path');
|
||||
|
||||
module.exports = {
|
||||
target: 'node',
|
||||
entry: './src/renderer.ts', // 入口文件路径
|
||||
output: { // 输出文件配置
|
||||
path: path.resolve(__dirname, 'dist'), // 输出目录路径
|
||||
filename: 'bundle.js' // 输出文件名
|
||||
},
|
||||
module: { // 模块配置
|
||||
rules: [ // 模块规则
|
||||
{
|
||||
test: /\.js$/, // 匹配.js文件
|
||||
exclude: /node_modules/, // 排除node_modules目录
|
||||
use: { // 使用的loader
|
||||
loader: 'babel-loader',
|
||||
options: {
|
||||
presets: ['@babel/preset-env']
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
test: /\.ts$/, // 匹配.ts文件
|
||||
exclude: /node_modules/, // 排除node_modules目录
|
||||
use: { // 使用的loader
|
||||
loader: 'ts-loader'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user