This commit is contained in:
linyuchen 2023-10-25 17:34:12 +08:00
parent 5ae95e8263
commit cc7d869c84
14 changed files with 196 additions and 83 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
node_modules/
dist/renderer.js

View File

@ -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

1
compile.bat Executable file
View File

@ -0,0 +1 @@
npx tsc src/renderer.ts --outDir dist

View File

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

20
dist/main.js vendored Normal file
View File

@ -0,0 +1,20 @@
// 运行在 Electron 主进程 下的插件入口
// 加载插件时触发
function onLoad(plugin) {
}
// 创建窗口时触发
function onBrowserWindowCreated(window, plugin) {
}
// 这两个函数都是可选的
module.exports = {
onLoad,
onBrowserWindowCreated
}

31
dist/manifest.json vendored Normal file
View 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": "./renderer.js",
"main": "./main.js",
"preload": "./preload.js"
}
}

8
dist/preload.js vendored Normal file
View File

@ -0,0 +1,8 @@
// Electron 主进程 与 渲染进程 交互的桥梁
const { contextBridge } = require("electron");
// 在window对象下导出只读对象
contextBridge.exposeInMainWorld("plugin_template", {
});

View File

@ -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"
}
}

28
package-lock.json generated Normal file
View File

@ -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"
}
}
}
}

14
package.json Normal file
View File

@ -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"
}
}

53
src/global.d.ts vendored Normal file
View File

@ -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): {
}[]
};

View File

@ -3,7 +3,7 @@
// 页面加载完成时触发
function onLoad() {
LLAPI.on("new-messages")
}

21
src/renderer.ts Normal file
View File

@ -0,0 +1,21 @@
/// <reference path="./global.d.ts" />
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
}

15
tsconfig.json Normal file
View File

@ -0,0 +1,15 @@
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"outDir": "./dist",
"strict": true,
"esModuleInterop": true
},
"include": [
"src"
],
"exclude": [
"node_modules"
]
}