Skip to content

Commit 098da6c

Browse files
committed
v:0.0.1+2
1 parent 2952adf commit 098da6c

27 files changed

+761
-236
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
一款kook平台机器人,快速的查询案件状态以及生成widget
33

44

5-
[官网](https://bot.bfban.com) | [反馈]()
5+
[官网](https://cabbagelol.github.io/kook-bot-docs)
66

77
支持: [kBotify](https://github.com/fi6/kBotify) | [kbotify-template](https://github.com/fi6/kbotify-template)
88

@@ -24,7 +24,7 @@ npm start
2424

2525
## 如何使用
2626

27-
参考docs下指令大全 [链接](/docs/command.md)
27+
参考docs下指令大全 [链接](https://cabbagelol.github.io/kook-bot-docs)
2828

2929

3030
---

bot.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ export const bot = new KBotify({
77
port: config.port,
88
verifyToken: config.kookAuth.khlverify,
99
key: config.kookAuth.khlkey,
10-
ignoreDecryptError: true,
10+
ignoreDecryptError: false,
11+
debug: config.__DEBUG__
1112
});

docs/command.md

-37
This file was deleted.

index.ts

+41-11
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,54 @@
1+
import * as fs from "fs";
2+
import upath, { parse } from "upath";
3+
14
import config from "./config";
25

36
import { bot } from "./bot";
47
import { exampleMenu } from "./src/commands/example/example.menu";
58
import { checkbanMenu } from "./src/commands/checkban/checkban.menu";
69
import { sitestatsMenu } from "./src/commands/sitestats/sitestats.menu";
10+
import { helpMenu } from "./src/commands/help/help.menu";
11+
import { invitationMenu } from "./src/commands/invitation/invitation.menu";
712

13+
import botEvent from "./src/lib/botEvent";
814
import botStatus from "./src/lib/botStatus";
915

10-
botStatus();
16+
class Main {
17+
protected mode: any = [botStatus, botEvent];
18+
protected commands: any = [checkbanMenu, sitestatsMenu, helpMenu, invitationMenu];
1119

12-
bot.messageSource.on("message", (e) => {
13-
bot.logger.debug("received:", e);
14-
});
20+
constructor() {
21+
this.ready();
22+
}
1523

16-
const commands = [checkbanMenu, sitestatsMenu];
17-
if (config.__DEBUG__) {
18-
commands.concat(exampleMenu);
19-
}
24+
ready() {
25+
try {
26+
if (config.__DEBUG__) {
27+
this.commands.concat(exampleMenu);
28+
}
29+
// const logFolderPath = upath.join(__dirname, "", "logs", new Date().toISOString());
30+
// if (!fs.existsSync(logFolderPath)) {
31+
// fs.mkdirSync(logFolderPath, { recursive: true });
32+
// }
33+
// const errorLogStream = fs.createWriteStream(upath.join(logFolderPath, `${config.name}-error.log`), { flags: "a" });
34+
// const infoLogStream = fs.createWriteStream(upath.join(logFolderPath, `${config.name}-info.log`), { flags: "a" });
35+
36+
this.mode.forEach((m: new () => any) => new m());
2037

21-
bot.addCommands(...commands);
22-
bot.connect();
38+
bot.logger.fields.name = config.name;
39+
// bot.logger.addStream({ level: "error", stream: errorLogStream });
40+
// bot.logger.addStream({ level: "info", stream: infoLogStream });
41+
42+
bot.addCommands(...this.commands);
43+
bot.connect();
44+
45+
bot.logger.info("Initialization: " + config.name + " initialization start");
46+
console.log("Initialization: " + config.name + " initialization start");
47+
} catch (err) {
48+
bot.connect();
49+
bot.logger.error(err);
50+
}
51+
}
52+
}
2353

24-
bot.logger.debug(`bot init success`);
54+
new Main();

package.json

+5-13
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,20 @@
11
{
2-
"name": "kbotify-template",
2+
"name": "bfban",
33
"version": "0.0.1",
4-
"description": "Starter kit for kBotify bots",
4+
"description": "bfban kook bot",
55
"main": "src/index.ts",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1",
87
"start": "node --nolazy -r ts-node/register -r tsconfig-paths/register index.ts"
98
},
10-
"repository": {
11-
"type": "git",
12-
"url": "git+https://github.com/fi6/kbotify-template.git"
13-
},
14-
"keywords": [
15-
"kbotify",
16-
"kaiheila",
17-
"bot"
18-
],
9+
"keywords": [],
1910
"author": "FlappyIce",
2011
"license": "MIT",
2112
"dependencies": {
2213
"axios": "^1.3.4",
2314
"i18n": "^0.15.1",
2415
"i18n-ts": "^1.0.5",
25-
"kbotify": "^0.2.5"
16+
"kbotify": "^0.2.5",
17+
"upath": "^2.0.1"
2618
},
2719
"devDependencies": {
2820
"@types/bunyan": "^1.8.6",
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { AppCommand, AppFunc, BaseSession } from "kbotify";
2+
import { bot } from "../../../bot";
3+
4+
class AdminBotOffline extends AppCommand {
5+
code = "botoffline"; // 只是用作标记
6+
trigger = "botoffline"; // 用于触发的文字
7+
help = `下线机器人`; // 帮助文字
8+
intro = ".admin botoffline";
9+
func: AppFunc<BaseSession> = async (session) => {
10+
if (!session.args.length) {
11+
await bot.API.directMessage.create(1, session.userId, "", this.help);
12+
return;
13+
}
14+
15+
return session.quote(`${session.args}`);
16+
};
17+
}
18+
19+
export const adminBotOffline = new AdminBotOffline();

src/commands/admin/admin.menu.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Card, MenuCommand } from "kbotify";
2+
import { adminBotOffline } from "./admin.botoffline";
3+
4+
class AdminMenu extends MenuCommand {
5+
code = "admin";
6+
trigger = "admin";
7+
help = "管理机器人";
8+
9+
menu = new Card().addText(this.help).toString();
10+
useCardMenu = true; // 使用卡片菜单
11+
}
12+
13+
export const adminMenu = new AdminMenu(adminBotOffline);

src/commands/checkban/checkban.id.ts

+32-25
Original file line numberDiff line numberDiff line change
@@ -6,51 +6,61 @@ import Http from "../../lib/http";
66
import { AppCommand, AppFunc, BaseSession, Card } from "kbotify";
77
import { bot } from "../../../bot";
88
import { PlayerCardTemplate } from "../../template/playerCardTemplate";
9+
import { ErrorTemplate } from "../../template/errorTemplate";
910

1011
class CheckbanId extends AppCommand {
1112
code = "id";
1213
trigger = "id";
13-
help = "`.checkban id [案件id]`";
14-
intro = "";
14+
help = ".cheackban id [id:number]";
15+
intro = "使用id查询案件";
1516
http = new Http();
1617

1718
func: AppFunc<BaseSession> = async (session) => {
18-
console.log(session);
19-
if (!session.args.length) {
20-
return session.reply(this.help);
21-
}
19+
try {
20+
if (!session.args.length) {
21+
return session.reply(this.help);
22+
}
2223

23-
const { mainValue, other } = new commandPack.CommandFactory().pack(session.args);
24+
const { mainValue, other } = new commandPack.CommandFactory().pack(session.args);
2425

25-
if (typeof mainValue != "number") {
26-
session.reply("not id");
27-
}
26+
if (!new RegExp(/^[0-9]+.?[0-9]*/).test(mainValue)) {
27+
session.reply(`检查您的参数非数字`);
28+
return;
29+
}
30+
31+
let player_info = await this.getPlayerInfo(mainValue);
2832

29-
let player_info = await this.getPlayerInfo(mainValue);
33+
if (!player_info) {
34+
session.reply("没有找到玩家");
35+
return;
36+
}
3037

31-
if (player_info) {
3238
// send playerCard message
33-
session.replyCard(new PlayerCardTemplate(player_info).generation());
34-
return;
35-
}
39+
let id = await session.replyCard(new PlayerCardTemplate(player_info).generation());
40+
41+
setTimeout(function() {
42+
session.updateMessage(<string>id.msgSent?.msgId, "test");
43+
}, 30000);
3644

37-
session.reply(":( I have an error");
45+
} catch (err) {
46+
session.replyCard(new ErrorTemplate(err).generation());
47+
bot.logger.error(err);
48+
}
3849
};
3950

4051
/**
4152
* 获取案件状态
4253
* @param id
4354
* @protected
4455
*/
45-
protected async getPlayerInfo(id: number): Promise<AxiosResponse> {
56+
protected async getPlayerInfo(id: number) {
4657
try {
4758
if (!id) {
48-
throw "id";
59+
throw "缺少id";
4960
}
5061

5162
return new Promise(async (resolve, reject) => {
52-
53-
let res = await axios({
63+
await axios({
5464
url: this.http.address + "api/" + api.player,
5565
method: "get",
5666
params: {
@@ -63,14 +73,11 @@ class CheckbanId extends AppCommand {
6373
}
6474
reject(res);
6575
}).catch(err => {
66-
bot.logger.debug(err);
6776
return reject(err);
6877
});
69-
7078
});
71-
} catch (e) {
72-
bot.logger.debug(e);
73-
throw e;
79+
} catch (err) {
80+
bot.logger.error(err);
7481
}
7582
}
7683
}

src/commands/checkban/checkban.menu.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { checkbanName } from "./checkban.name";
55
class CheckbanMenu extends MenuCommand {
66
code = "checkban";
77
trigger = "checkban";
8-
help = ".checkban 菜单";
8+
help = "";
99
}
1010

1111
export const checkbanMenu = new CheckbanMenu(checkbanId, checkbanName);

0 commit comments

Comments
 (0)