-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
329 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
* @Blog: https://hotaru.icu | ||
* @Date: 2023-07-11 14:18:27 | ||
* @LastEditors: Hotaru [email protected] | ||
* @LastEditTime: 2024-02-11 20:20:33 | ||
* @LastEditTime: 2024-02-15 17:21:28 | ||
*/ | ||
import { Context, Tsu } from 'kotori-bot'; | ||
import os from 'os'; | ||
|
@@ -49,7 +49,7 @@ function dealRam() { | |
|
||
function dealCpu() { | ||
const cpuData = os.cpus(); | ||
let rate: number = 0; | ||
let rate = 0; | ||
const ratearr: number[] = []; | ||
cpuData.forEach((key) => { | ||
const { times } = key; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# kotori-bot-admin-server | ||
|
||
This is a website management system specifically designed for the kotori-bot project | ||
Web repository: [https://github.com/BIYUEHU/kotori-bot-admin-web](https://github.com/BIYUEHU/kotori-bot-admin-web) | ||
|
||
**Version:** 1.1.0 | ||
**Author:** hotaru | ||
**License:** GPL-3.0 | ||
|
||
## List of command | ||
|
||
- /login - Get Kotori-Amdin login url^^ | ||
|
||
## Lang Support | ||
|
||
- ja_JP | ||
- en_US | ||
- zh_TW | ||
- zh_CN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"kotori_bot_admin_server.help.login": "Get Kotori-Amdin login url", | ||
"kotori_bot_admin_server.msg.login.info": "Here are your login url:\nhttp://127.0.0.1:%port%%path%\n%face_address%:%port%%path%\nLogin url will expire after[%expire_time%Second], dont give others" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"kotori_bot_admin_server.help.login": "Kotori-Amdinログインアドレスの取得", | ||
"kotori_bot_admin_server.msg.login.info": "これがあなたのログイン先です:\nhttp://127.0.0.1:%port%%path%\n%face_address%:%port%%path%\nログインアドレスは[%expire_time%秒]後に期限切れになりますので、他人に漏らさないでください" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"kotori_bot_admin_server.help.login": "获取Kotori-Amdin后台一键登录地址", | ||
"kotori_bot_admin_server.msg.login.info": "以下是您的BOT后台管理的一键登录地址:\nhttp://127.0.0.1:%port%%path%\n%face_address%:%port%%path%\n登录地址将在[%expire_time%秒]后过期,请勿泄露给他人" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"kotori_bot_admin_server.help.login": "獲取Kotori-Amdin後臺一鍵登錄地址", | ||
"kotori_bot_admin_server.msg.login.info": "以下是您的BOT後臺管理的一鍵登錄地址:\nhttp://127.0.0.1:%port%%path%\n%face_address%:%port%%path%\n登錄地址將在[%expire_time%秒]後過期,請勿泄露給他人" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"name": "@kotori-bot/kotori-plugin-webui", | ||
"version": "1.0.0", | ||
"description": "webui plugin", | ||
"main": "lib/index.js", | ||
"scripts": { | ||
"build": "tsc --build" | ||
}, | ||
"keywords": [ | ||
"kotori", | ||
"chatbot", | ||
"kotori-plugin" | ||
], | ||
"license": "GPL-3.0", | ||
"files": [ | ||
"lib", | ||
"locales", | ||
"LICENSE", | ||
"README.md" | ||
], | ||
"author": "Hotaru <[email protected]>", | ||
"peerDependencies": { | ||
"kotori-bot": "workspace:^" | ||
}, | ||
"kotori": { | ||
"meta": { | ||
"language": [ | ||
"en_US", | ||
"ja_JP", | ||
"zh_TW", | ||
"zh_CN" | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { getUuid } from 'kotori-bot'; | ||
import os from 'os'; | ||
|
||
type Code = 500 | 501 | 502; | ||
|
||
export function response<T>(code: Code, data?: T) { | ||
return { code, data }; | ||
} | ||
export function getToken() { | ||
return getUuid().replaceAll('-', ''); | ||
} | ||
|
||
export function getRamRate() { | ||
const total = os.totalmem() / (1024 * 3); | ||
return ((total - os.freemem() / (1024 * 3)) / total) * 100; | ||
} | ||
|
||
export function getCpuRate() { | ||
let rate = 0; | ||
os.cpus().forEach((key) => { | ||
const { times } = key; | ||
const usage = (1 - times.idle / (times.idle + times.user + times.nice + times.sys + times.irq)) * 100; | ||
rate += usage; | ||
}); | ||
return rate; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const DEFAULT_USERNAME = 'kotori'; | ||
export const DEFAULT_PASSWORD = '123456'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import { type Adapter, type Context, Symbols, ModuleConfig, Tsu, stringRightSplit, PLUGIN_PREFIX } from 'kotori-bot'; | ||
import path from 'path'; | ||
import { getCpuRate, getRamRate, getToken } from './common'; | ||
import { DEFAULT_PASSWORD, DEFAULT_USERNAME } from './const'; | ||
|
||
export const inject = ['server', 'file']; | ||
|
||
export const config = Tsu.Object({ | ||
username: Tsu.String().default(DEFAULT_USERNAME), | ||
password: Tsu.String().default(DEFAULT_PASSWORD) | ||
}); | ||
|
||
export function main(ctx: Context, con: Tsu.infer<typeof config>) { | ||
const app = ctx.server; | ||
app.use(app.static(path.join('/web'))); | ||
app.use(app.json()); | ||
|
||
/* eslint @typescript-eslint/no-explicit-any: 0 */ | ||
app.all('*', (req: any, res: any, next: any) => { | ||
if (req.path !== '/api/info') ctx.logger.label(req.method).trace(req.path); | ||
res.header('Access-Control-Allow-Origin', '*'); | ||
res.header('Access-Control-Allow-Headers', 'Content-Type'); | ||
res.header('Access-Control-Allow-Methods', '*'); | ||
res.header('Content-Type', 'application/json;charset=utf-8'); | ||
next(); | ||
}); | ||
|
||
const router = app.router(); | ||
|
||
router.get('/bots', (_, res) => { | ||
const bots: (Adapter['status'] & { platform: string; identity: string; id: string | number; lang: string })[] = []; | ||
ctx[Symbols.bot].forEach((bot) => | ||
bot.forEach((api) => | ||
bots.push({ | ||
...api.adapter.status, | ||
platform: api.adapter.platform, | ||
identity: api.adapter.identity, | ||
id: api.adapter.selfId, | ||
lang: api.adapter.config.lang | ||
}) | ||
) | ||
); | ||
res.status(200).json(bots); | ||
}); | ||
|
||
router.get('/modules', (_, res) => { | ||
const modules: [object, ModuleConfig][] = []; | ||
ctx[Symbols.modules].forEach((module) => modules.push([module[0].pkg, module[1]])); | ||
res.status(200).json(modules); | ||
}); | ||
|
||
router.get('/data', (_, res) => { | ||
res.status(200).json({ | ||
midwares: ctx[Symbols.midware].size, | ||
commands: ctx[Symbols.command].size, | ||
regexps: ctx[Symbols.regexp].size, | ||
bots: ctx[Symbols.bot].size, | ||
adapters: ctx[Symbols.adapter].size, | ||
modules: ctx[Symbols.modules].size, | ||
dir: ctx.baseDir.root, | ||
pkg: ctx.pkg, | ||
node: process.version | ||
}); | ||
}); | ||
|
||
router.get('/info', (_, res) => { | ||
res.status(200).json({ cpu: getCpuRate(), ram: getRamRate() }); | ||
}); | ||
|
||
router.get('/login', (req, res) => { | ||
const { user, pwd } = req.query; | ||
if (user === con.username && pwd === con.password) { | ||
const token = getToken(); | ||
ctx.file.save('token', token); | ||
res.status(200).json({ token, default: con.username === DEFAULT_USERNAME && con.password === DEFAULT_PASSWORD }); | ||
} else { | ||
res.status(200).json({}); | ||
} | ||
}); | ||
|
||
router.get('/config', (req, res) => { | ||
const { type, id } = req.query; | ||
if (type === 'module') { | ||
if (typeof id === 'string') { | ||
const split = id.split('/'); | ||
const handle = stringRightSplit(split.length > 1 ? split[1] : split[0], PLUGIN_PREFIX); | ||
res.status(200).json(handle in ctx.config.plugin ? ctx.config.plugin[handle] : {}); | ||
} else { | ||
res.status(200).json({}); | ||
} | ||
} else if (type === 'adapter') { | ||
res.status(200).json(typeof id === 'string' && id in ctx.config.adapter ? ctx.config.adapter[id] : {}); | ||
} else { | ||
res.status(200).json(ctx.config); | ||
} | ||
}); | ||
|
||
app.use('/api', router); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"extends": "../../tsconfig.node.json", | ||
"compilerOptions": { | ||
"rootDir": "./src", | ||
"outDir": "./lib" | ||
}, | ||
"references": [ | ||
{ | ||
"path": "../../packages/kotori" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,14 +5,6 @@ | |
"license": "GPL-3.0", | ||
"main": "lib/index.js", | ||
"author": "Hotaru <[email protected]>", | ||
"dependencies": { | ||
"@kotori-bot/core": "workspace:^", | ||
"@kotori-bot/logger": "workspace:^", | ||
"express": "^4.18.2", | ||
"knex": "^3.1.0", | ||
"mysql": "^2.18.1", | ||
"sqlite3": "^5.1.7" | ||
}, | ||
"keywords": [ | ||
"kotori", | ||
"chatbot", | ||
|
@@ -31,7 +23,18 @@ | |
"url": "git+https://github.com/kotorijs/kotori.git" | ||
}, | ||
"homepage": "https://kotori.js.org", | ||
"dependencies": { | ||
"@kotori-bot/core": "workspace:^", | ||
"@kotori-bot/logger": "workspace:^", | ||
"express": "^4.18.2", | ||
"knex": "^3.1.0", | ||
"sqlite3": "^5.1.7" | ||
}, | ||
"devDependencies": { | ||
"@types/express": "^4.17.21" | ||
"@types/body-parser": "^1.19.5", | ||
"@types/connect": "^3.4.38", | ||
"@types/express": "^4.17.21", | ||
"@types/express-serve-static-core": "^4.17.43", | ||
"@types/serve-static": "^1.15.5" | ||
} | ||
} | ||
} |
Oops, something went wrong.