diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c9f6f5d --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules/ +dist/renderer.js \ No newline at end of file diff --git a/README.md b/README.md index 02dc253..c5c17f6 100644 --- a/README.md +++ b/README.md @@ -1,52 +1,3 @@ -# LiteLoaderQQNT-Plugin-Template +# LLOneBot API -LiteLoaderQQNT的插件模板,包含插件创建方法,编写建议,还有技巧 -LiteLoaderQQNT本体:[LiteLoaderQQNT](https://github.com/mo-jinran/LiteLoaderQQNT) - -Telegram闲聊群:https://t.me/LiteLoaderQQNT - - -# 关于插件从 V2 更新至 V3 说明 - -各位插件开发者,按照这条提示来更新插件 -建议参考其他已上架插件市场的插件 - -以下是插件需要的改动 -- 更改manifest.json文件,manifest_version改为3 -- 彻底移除了旧版betterQQNT对象,请使用LiteLoader对象 -- 主进程脚本onLoad函数不再提供LiteLoader对象,你可以在主进程环境任何地方使用LiteLoader对象 -- 因为Windows QQNT渲染进程无法使用file://协议请求文件,请替换为llqqnt://local-file/ - -对于上架插件市场的插件,建议开单独分支 -方便插件市场获取新与旧的插件仓库并更新插件 -(这些不是必须的,如果你不打算保留旧版,可单分支冲过去( -可继续使用Repo方式 ,或使用Release来上传插件 -Release附加的插件文件必须是.zip格式 -新版(v3)需压缩插件目录内部必要的文件 -然后在插件仓库提交issue或pr在v3分支(pr的请写在最开始) - - -# 插件编写指南文档 - -文档目前还不算完善,但能看,也欢迎各位来完善/修复错误 - -- [了解数据目录结构](https://github.com/mo-jinran/LiteLoaderQQNT-Plugin-Template/wiki/1.了解数据目录结构) - - [LiteLoader的数据目录](https://github.com/mo-jinran/LiteLoaderQQNT-Plugin-Template/wiki/1.了解数据目录结构#liteloader的数据目录) - - [plugins](https://github.com/mo-jinran/LiteLoaderQQNT-Plugin-Template/wiki/1.了解数据目录结构#plugins) - - [plugins_data](https://github.com/mo-jinran/LiteLoaderQQNT-Plugin-Template/wiki/1.了解数据目录结构#plugins_data) - - [plugins_cache](https://github.com/mo-jinran/LiteLoaderQQNT-Plugin-Template/wiki/1.了解数据目录结构#plugins_cache) - - [config.json](https://github.com/mo-jinran/LiteLoaderQQNT-Plugin-Template/wiki/1.了解数据目录结构#config.json) -- [了解插件目录结构](https://github.com/mo-jinran/LiteLoaderQQNT-Plugin-Template/wiki/1.了解插件目录结构) - - [插件的目录](https://github.com/mo-jinran/LiteLoaderQQNT-Plugin-Template/wiki/2.了解插件目录结构#插件的目录) - - [manifest.json](https://github.com/mo-jinran/LiteLoaderQQNT-Plugin-Template/wiki/2.了解插件目录结构#manifest.json) - - [README.md](https://github.com/mo-jinran/LiteLoaderQQNT-Plugin-Template/wiki/2.了解插件目录结构#README.md) - - [LICENSE](https://github.com/mo-jinran/LiteLoaderQQNT-Plugin-Template/wiki/2.了解插件目录结构#LICENSE) - - [main.js](https://github.com/mo-jinran/LiteLoaderQQNT-Plugin-Template/wiki/2.了解插件目录结构#main.js) - - [preload.js](https://github.com/mo-jinran/LiteLoaderQQNT-Plugin-Template/wiki/2.了解插件目录结构#preload.js) - - [renderer.js](https://github.com/mo-jinran/LiteLoaderQQNT-Plugin-Template/wiki/2.了解插件目录结构#renderer.js) -- [插件基本代码结构](https://github.com/mo-jinran/LiteLoaderQQNT-Plugin-Template/wiki/3.插件基本代码结构) - - [插件的结构](https://github.com/mo-jinran/LiteLoaderQQNT-Plugin-Template/wiki/3.插件基本代码结构#插件的结构) - - [Manifest](https://github.com/mo-jinran/LiteLoaderQQNT-Plugin-Template/wiki/manifest.json) - - [主进程](https://github.com/mo-jinran/LiteLoaderQQNT-Plugin-Template/wiki/main.js) - - [预加载](https://github.com/mo-jinran/LiteLoaderQQNT-Plugin-Template/wiki/preload.js) - - [渲染进程](https://github.com/mo-jinran/LiteLoaderQQNT-Plugin-Template/wiki/renderer.js) +将NTQQLiteLoaderAPI封装成OneBot标准的API diff --git a/compile.bat b/compile.bat new file mode 100755 index 0000000..4bb8305 --- /dev/null +++ b/compile.bat @@ -0,0 +1 @@ +npx tsc src/renderer.ts --outDir dist \ No newline at end of file diff --git a/icon.png b/dist/icon.png similarity index 100% rename from icon.png rename to dist/icon.png diff --git a/dist/main.js b/dist/main.js new file mode 100644 index 0000000..5fdb462 --- /dev/null +++ b/dist/main.js @@ -0,0 +1,20 @@ +// 运行在 Electron 主进程 下的插件入口 + + +// 加载插件时触发 +function onLoad(plugin) { + +} + + +// 创建窗口时触发 +function onBrowserWindowCreated(window, plugin) { + +} + + +// 这两个函数都是可选的 +module.exports = { + onLoad, + onBrowserWindowCreated +} \ No newline at end of file diff --git a/dist/manifest.json b/dist/manifest.json new file mode 100644 index 0000000..64049a3 --- /dev/null +++ b/dist/manifest.json @@ -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": "./renderer.js", + "main": "./main.js", + "preload": "./preload.js" + } +} diff --git a/dist/preload.js b/dist/preload.js new file mode 100644 index 0000000..1161aac --- /dev/null +++ b/dist/preload.js @@ -0,0 +1,8 @@ +// Electron 主进程 与 渲染进程 交互的桥梁 +const { contextBridge } = require("electron"); + + +// 在window对象下导出只读对象 +contextBridge.exposeInMainWorld("plugin_template", { + +}); \ No newline at end of file diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 341dde0..0000000 --- a/manifest.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "manifest_version": 3, - "type": "extension", - "name": "插件模板", - "slug": "plugin_template", - "description": "LiteLoaderQQNT的插件模板", - "version": "0.1.0", - "thumbnail": "./icon.png", - "author": { - "name": "LiteLoaderQQNT", - "link": "https://github.com/LiteLoaderQQNT" - }, - "repository": { - "repo": "LiteLoaderQQNT/LiteLoaderQQNT-Plugin-Template", - "branch": "main", - "use_release": { - "tag": "latest", - "name": "Plugin-Template.zip" - } - }, - "platform": [ - "win32", - "linux", - "darwin" - ], - "injects": { - "renderer": "./src/renderer.js", - "main": "./src/main.js", - "preload": "./src/preload.js" - } -} diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..f7981bc --- /dev/null +++ b/package-lock.json @@ -0,0 +1,28 @@ +{ + "name": "llonebot", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "llonebot", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "typescript": "^5.2.2" + } + }, + "node_modules/typescript": { + "version": "5.2.2", + "resolved": "https://mirrors.cloud.tencent.com/npm/typescript/-/typescript-5.2.2.tgz", + "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..0f3ebd4 --- /dev/null +++ b/package.json @@ -0,0 +1,14 @@ +{ + "name": "llonebot", + "version": "1.0.0", + "description": "NTQQLiteLoaderOneBotApi", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "dependencies": { + "typescript": "^5.2.2" + } +} diff --git a/src/global.d.ts b/src/global.d.ts new file mode 100644 index 0000000..a510f1a --- /dev/null +++ b/src/global.d.ts @@ -0,0 +1,53 @@ +declare enum AtType { + notAt = 0, + atUser = 2 +} + +declare type Peer = { + chatType: "private" | "group" + name: string + uid: string // qq号 +} + +interface MessageElement{ + elements:{ + type: "text", + content: string, + raw: { + textElement: { + atType: AtType + atUid: string + } + } + }[] + peer: Peer, + sender: { + uid: string // 一串加密的字符串 + memberName: string + nickname: string + } +} + +declare var LLAPI: { + on(event: "new-messages", callback: (data: MessageElement[]) => void): void; + getAccountInfo(): { + uid: string // qq + uin: string // 一串加密的字符串 + } + getUserInfo(uid: string):{nickName: string}; + sendMessage(peer: Peer, message: + { + type: "text", + content: string,}| + { + type: "image", + file: string, + } + ): void + getGroupList(forced: boolean): { + + }[] + getFriendList(forced: boolean): { + + }[] +}; diff --git a/src/renderer.js b/src/renderer.js index 4b85478..42a2729 100644 --- a/src/renderer.js +++ b/src/renderer.js @@ -3,7 +3,7 @@ // 页面加载完成时触发 function onLoad() { - + LLAPI.on("new-messages") } diff --git a/src/renderer.ts b/src/renderer.ts new file mode 100644 index 0000000..4c58166 --- /dev/null +++ b/src/renderer.ts @@ -0,0 +1,21 @@ +/// + + +function onLoad(){ + LLAPI.on("new-messages", (messages) => { + console.log("收到新消息", messages) + }); + console.log("getAccountInfo", LLAPI.getAccountInfo()); + console.log("getFriendList", LLAPI.getFriendList(false)); + console.log("getGroupList", LLAPI.getGroupList(false)); +} + +// 打开设置界面时触发 +function onConfigView(view: any) { + +} + +export { + onLoad, + onConfigView +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..e1bb822 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,15 @@ +{ + "compilerOptions": { + "target": "es5", + "module": "commonjs", + "outDir": "./dist", + "strict": true, + "esModuleInterop": true + }, + "include": [ + "src" + ], + "exclude": [ + "node_modules" + ] +} \ No newline at end of file