Skip to content

Commit

Permalink
feat: webui
Browse files Browse the repository at this point in the history
  • Loading branch information
BIYUEHU committed May 4, 2024
1 parent 7e696fe commit b4bd053
Show file tree
Hide file tree
Showing 36 changed files with 1,710 additions and 412 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ kotori.dev.yml

data

request.http
test.http
12 changes: 6 additions & 6 deletions modules/adapter-qq/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class QQAdapter extends Adapter<QQApi> {
}

public start() {
this.getToken();
this.generateToken();
this.connect();
}

Expand Down Expand Up @@ -192,7 +192,7 @@ export class QQAdapter extends Adapter<QQApi> {
this.socket.on('message', (data) => this.handle(JSON.parse(data.toString())));
}

private async getToken() {
private async generateToken() {
const data = (await this.ctx.http.post('https://bots.qq.com/app/getAppAccessToken', {
appId: this.config.appid,
clientSecret: this.config.secret
Expand All @@ -203,10 +203,10 @@ export class QQAdapter extends Adapter<QQApi> {
return;
}
this.token = data.access_token;
this.getTokenTimerId = setTimeout(
this.generateTokenTimerId = setTimeout(
() => {
if (this.getTokenTimerId) clearInterval(this.getTokenTimerId);
this.getToken();
if (this.generateTokenTimerId) clearInterval(this.generateTokenTimerId);
this.generateToken();
},
(parseInt(data.expires_in, 10) - 30) * 1000
);
Expand All @@ -224,7 +224,7 @@ export class QQAdapter extends Adapter<QQApi> {
}

/* global NodeJS */
private getTokenTimerId?: NodeJS.Timeout;
private generateTokenTimerId?: NodeJS.Timeout;

private heartbeatTimerId?: NodeJS.Timeout;
}
Expand Down
19 changes: 12 additions & 7 deletions modules/testing/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ const plugin = plugins([__dirname, '../']);

@plugin.import
export default class Plugin {
private ctx: Context;

private config: Tsu.infer<typeof Plugin.schema>;

@plugin.lang
public static lang = [__dirname, '../locales'];

Expand All @@ -17,13 +21,13 @@ export default class Plugin {
@plugin.inject
public static inject = ['database'];

public constructor(
private ctx: Context,
private config: Tsu.infer<typeof Plugin.schema>
) {}
public constructor(ctx: Context, config: Tsu.infer<typeof Plugin.schema>) {
this.ctx = ctx;
this.config = config;
}

@plugin.on({ type: 'on_group_decrease' })
public groupDecrease(session: SessionData) {
public static groupDecrease(session: SessionData) {
session.quick([
session.userId === session.operatorId ? '%target% 默默的退出了群聊' : '%target% 被 %target% 制裁了...',
{
Expand All @@ -34,7 +38,8 @@ export default class Plugin {
}

@plugin.midware({ priority: 10 })
public midware(next: () => void, s: SessionData) {
public static midware(next: () => void, session: SessionData) {
const s = session;
if (s.message.startsWith('说')) {
s.message = `${s.api.adapter.config['command-prefix']}echo ${s.message.split('说 ')[1]}`;
}
Expand All @@ -52,7 +57,7 @@ export default class Plugin {
}

@plugin.regexp({ match: /^(.*)#print$/ })
public print(match: RegExpExecArray) {
public static print(match: RegExpExecArray) {
return match[1];
}
}
4 changes: 2 additions & 2 deletions modules/webui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kotori-bot/kotori-plugin-webui",
"version": "1.0.0",
"version": "1.1.0",
"description": "webui plugin",
"main": "lib/index.js",
"scripts": {
Expand Down Expand Up @@ -33,4 +33,4 @@
]
}
}
}
}
218 changes: 218 additions & 0 deletions modules/webui/request.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
###
## @Author: Hotaru biyuehuya@gmail.com
## @Blog: https://hotaru.icu
## @Date: 2024-05-03 19:13:44
## @LastEditors: Hotaru biyuehuya@gmail.com
## @LastEditTime: 2024-05-04 16:49:18
###

# Kotori Bot - WebUI Api Documentation

@URL = http://localhost:720
@KEY = 43cd1101c9ea4285a7baff52336adaad

### 获取所有插件配置信息

GET {{URL}}/api/config/plugins HTTP/1.1
Authorization: Bearer {{KEY}}

Response:
[
{
"name": "menu",
"origin": {
"content": "请发送 /help",
"filter": {}
},
"schema": {}
}
// ...
]

### 获取插件配置信息

@pluginName = @kotori-bot/kotori-plugin-webui
GET {{URL}}/api/config/plugins/{{pluginName}} HTTP/1.1
Authorization: Bearer {{KEY}}

Response:
{
"name": "webui",
"origin": {
"username": "himeno",
"password": "0517",
"filter": {}
},
"schema": {}
}

### 获取所有机器人实例配置信息

GET {{URL}}/api/config/bots HTTP/1.1
Authorization: Bearer {{KEY}}

Response:
[
{
"id": "cmd-test",
"origin": {
"extends": "cmd",
"master": 2333,
},
"schema": {}
}
// ...
]

### 获取单个机器人实例配置信息

@botName = cmd-test
GET {{URL}}/api/config/bots/{{botName}} HTTP/1.1
Authorization: Bearer {{KEY}}

Response:
{
"id": "cmd-test",
"origin": {
"extends": "cmd",
"master": 2333,
},
"schema": {}
}

### 获取全局配置信息
GET {{URL}}/api/config/global HTTP/1.1
Authorization: Bearer {{KEY}}

Response:
{
"port": 720,
"lang": "zh_CN",
"command-prefix": "/",
"dirs": []
}

### 获取所有模块信息

GET {{URL}}/api/data/modules HTTP/1.1
Authorization: Bearer {{KEY}}

Response:
[
{
"name": "@kotori-bot/kotori-plugin-webui",
"version": "1.1.0",
"description": "webui plugin",
"main": "lib/index.js",
}
// ...
]

### 获取单个模块信息

@moduleName = kotori-plugin-adapter-minecraft
GET {{URL}}/api/data/modules/{{moduleName}} HTTP/1.1
Authorization: Bearer {{KEY}}

Response:
{
"name": "@kotori-bot/kotori-plugin-webui",
"version": "1.1.0",
"description": "webui plugin",
"main": "lib/index.js",
}

### 获取所有机器人实例信息

GET {{URL}}/api/data/bots HTTP/1.1
Authorization: Bearer {{KEY}}

Response:
[
{
"status": {},
"platform": "cmd",
"identity": "cmd-test",
"id": "720",
"lang": "zh_CN"
}
]

### 获取单个机器人实例信息

@botName2 = cmd-test
GET {{URL}}/api/data/bots/{{botName2}} HTTP/1.1
Authorization: Bearer {{KEY}}

Response:
{
"status": {},
"platform": "cmd",
"identity": "cmd-test",
"id": "720",
"lang": "zh_CN"
}

### 获取统计数据

GET {{URL}}/api/data/stats HTTP/1.1
Authorization: Bearer {{KEY}}

Response:
{
"chats": {
"received": [0,0,0,0,0,0,0],
"sent": [0,0,0,0,0,0,0]
},
"count": {
"midwares": 5,
"commands": 51,
"regexps": 25,
"bots": 4,
"adapters": 5,
"modules": 33
},
"env": {
"dirs": {
"root": "F:\\project-self\\javascript\\nodejs\\kotori-bot",
"modules": "F:\\project-self\\javascript\\nodejs\\kotori-bot\\modules",
"data": "F:\\project-self\\javascript\\nodejs\\kotori-bot\\data",
"logs": "F:\\project-self\\javascript\\nodejs\\kotori-bot\\logs"
},
"options": {
"mode": "dev-source"
}
},
"version": {
"node": "v18.18.1",
"core": "1.4.0"
},
"system": {
"type": "Windows_NT",
"platform": "win32",
"arch": "x64",
"uptime": 38815.64,
"hostname": "BIYUEHU",
"homedir": "C:\\Users\\BIYUEHU"
},
"status": {
"ram": {
"total": 23.89745330810547,
"unused": 13.024009704589844,
"used": 10.873443603515625,
"rate": 45.500428281316495
},
"cpu": {
"rate": 47.57456763586952,
"speed": 2592
},
"chats": {
"received": 0,
"sent": 0
}
}
}

### WebSocket 连接


26 changes: 0 additions & 26 deletions modules/webui/src/common.ts

This file was deleted.

File renamed without changes.
Loading

0 comments on commit b4bd053

Please sign in to comment.