koishi-plugin-dew-bot 1.0.188
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/html/css/body.css +287 -0
- package/lib/html/css/equip.css +115 -0
- package/lib/html/css/skill.css +75 -0
- package/lib/html/css/talent.css +58 -0
- package/lib/html/page/body.html +96 -0
- package/lib/html/page/equip.html +98 -0
- package/lib/html/page/mini_texas.html +493 -0
- package/lib/html/page/skill.html +76 -0
- package/lib/html/page/talent.html +76 -0
- package/lib/html/res/avatar.jpg +0 -0
- package/lib/html/res/body/box.png +0 -0
- package/lib/html/res/body/share/test.png +0 -0
- package/lib/html/res/body/title/test.png +0 -0
- package/lib/html/res/body/title/test1.png +0 -0
- package/lib/html/res/equip/equip_border.png +0 -0
- package/lib/html/res/equip/icon/none.png +0 -0
- package/lib/html/res/equip/icon/test.png +0 -0
- package/lib/html/res/equip/quality/0.png +0 -0
- package/lib/html/res/equip/quality/1.png +0 -0
- package/lib/html/res/equip/quality/2.png +0 -0
- package/lib/html/res/equip/quality/3.png +0 -0
- package/lib/html/res/equip/quality/4.png +0 -0
- package/lib/html/res/equip/quality/5.png +0 -0
- package/lib/html/res/equip/quality/6.png +0 -0
- package/lib/html/res/equip/quality/7.png +0 -0
- package/lib/html/res/equip/quality/8.png +0 -0
- package/lib/html/res/equip/quality/9.png +0 -0
- package/lib/html/res/font/cn.ttf +0 -0
- package/lib/html/res/font/xiaomai.ttf +0 -0
- package/lib/html/res/mini/chip/chip0.png +0 -0
- package/lib/html/res/mini/chip/chip1.png +0 -0
- package/lib/html/res/mini/chip/chip2.png +0 -0
- package/lib/html/res/mini/chip/chip3.png +0 -0
- package/lib/html/res/mini/chip/chip4.png +0 -0
- package/lib/html/res/mini/chip/chip5.png +0 -0
- package/lib/html/res/mini/poker/backPoker.png +0 -0
- package/lib/html/res/mini/poker/poker_0_10.png +0 -0
- package/lib/html/res/mini/poker/poker_0_11.png +0 -0
- package/lib/html/res/mini/poker/poker_0_12.png +0 -0
- package/lib/html/res/mini/poker/poker_0_13.png +0 -0
- package/lib/html/res/mini/poker/poker_0_14.png +0 -0
- package/lib/html/res/mini/poker/poker_0_2.png +0 -0
- package/lib/html/res/mini/poker/poker_0_3.png +0 -0
- package/lib/html/res/mini/poker/poker_0_4.png +0 -0
- package/lib/html/res/mini/poker/poker_0_5.png +0 -0
- package/lib/html/res/mini/poker/poker_0_6.png +0 -0
- package/lib/html/res/mini/poker/poker_0_7.png +0 -0
- package/lib/html/res/mini/poker/poker_0_8.png +0 -0
- package/lib/html/res/mini/poker/poker_0_9.png +0 -0
- package/lib/html/res/mini/poker/poker_1_10.png +0 -0
- package/lib/html/res/mini/poker/poker_1_11.png +0 -0
- package/lib/html/res/mini/poker/poker_1_12.png +0 -0
- package/lib/html/res/mini/poker/poker_1_13.png +0 -0
- package/lib/html/res/mini/poker/poker_1_14.png +0 -0
- package/lib/html/res/mini/poker/poker_1_2.png +0 -0
- package/lib/html/res/mini/poker/poker_1_3.png +0 -0
- package/lib/html/res/mini/poker/poker_1_4.png +0 -0
- package/lib/html/res/mini/poker/poker_1_5.png +0 -0
- package/lib/html/res/mini/poker/poker_1_6.png +0 -0
- package/lib/html/res/mini/poker/poker_1_7.png +0 -0
- package/lib/html/res/mini/poker/poker_1_8.png +0 -0
- package/lib/html/res/mini/poker/poker_1_9.png +0 -0
- package/lib/html/res/mini/poker/poker_2_10.png +0 -0
- package/lib/html/res/mini/poker/poker_2_11.png +0 -0
- package/lib/html/res/mini/poker/poker_2_12.png +0 -0
- package/lib/html/res/mini/poker/poker_2_13.png +0 -0
- package/lib/html/res/mini/poker/poker_2_14.png +0 -0
- package/lib/html/res/mini/poker/poker_2_2.png +0 -0
- package/lib/html/res/mini/poker/poker_2_3.png +0 -0
- package/lib/html/res/mini/poker/poker_2_4.png +0 -0
- package/lib/html/res/mini/poker/poker_2_5.png +0 -0
- package/lib/html/res/mini/poker/poker_2_6.png +0 -0
- package/lib/html/res/mini/poker/poker_2_7.png +0 -0
- package/lib/html/res/mini/poker/poker_2_8.png +0 -0
- package/lib/html/res/mini/poker/poker_2_9.png +0 -0
- package/lib/html/res/mini/poker/poker_3_10.png +0 -0
- package/lib/html/res/mini/poker/poker_3_11.png +0 -0
- package/lib/html/res/mini/poker/poker_3_12.png +0 -0
- package/lib/html/res/mini/poker/poker_3_13.png +0 -0
- package/lib/html/res/mini/poker/poker_3_14.png +0 -0
- package/lib/html/res/mini/poker/poker_3_2.png +0 -0
- package/lib/html/res/mini/poker/poker_3_3.png +0 -0
- package/lib/html/res/mini/poker/poker_3_4.png +0 -0
- package/lib/html/res/mini/poker/poker_3_5.png +0 -0
- package/lib/html/res/mini/poker/poker_3_6.png +0 -0
- package/lib/html/res/mini/poker/poker_3_7.png +0 -0
- package/lib/html/res/mini/poker/poker_3_8.png +0 -0
- package/lib/html/res/mini/poker/poker_3_9.png +0 -0
- package/lib/html/res/mini/texas/bg.jpg +0 -0
- package/lib/html/res/mini/texas/win.png +0 -0
- package/lib/html/res/quality/test.png +0 -0
- package/lib/html/res/skill/att/dark.png +0 -0
- package/lib/html/res/skill/att/divine.png +0 -0
- package/lib/html/res/skill/att/earth.png +0 -0
- package/lib/html/res/skill/att/fire.png +0 -0
- package/lib/html/res/skill/att/light.png +0 -0
- package/lib/html/res/skill/att/spell.png +0 -0
- package/lib/html/res/skill/att/trap.png +0 -0
- package/lib/html/res/skill/att/water.png +0 -0
- package/lib/html/res/skill/att/wind.png +0 -0
- package/lib/html/res/skill/frame/0.jpg +0 -0
- package/lib/html/res/skill/frame/1.jpg +0 -0
- package/lib/html/res/skill/frame/2.jpg +0 -0
- package/lib/html/res/skill/frame/3.jpg +0 -0
- package/lib/html/res/skill/frame/4.jpg +0 -0
- package/lib/html/res/skill/frame/5.jpg +0 -0
- package/lib/html/res/skill/frame/6.jpg +0 -0
- package/lib/html/res/skill/frame/7.jpg +0 -0
- package/lib/html/res/skill/frame/8.jpg +0 -0
- package/lib/html/res/skill/frame/9.jpg +0 -0
- package/lib/html/res/skill/star/level.png +0 -0
- package/lib/html/res/skill/star/rank.png +0 -0
- package/lib/html/res/skill/test.jpg +0 -0
- package/lib/html/res/vue2.js +11 -0
- package/lib/index.js +46 -0
- package/lib/inits.js +43 -0
- package/lib/msgCsl.js +97 -0
- package/lib/plugin/console.js +17 -0
- package/lib/plugin/messageQueue.js +134 -0
- package/lib/plugin/puppeteer.js +81 -0
- package/lib/plugin/rateLimiter.js +104 -0
- package/lib/plugin/server.js +206 -0
- package/lib/plugin/serverHandel/handel_base.js +27 -0
- package/lib/plugin/serverHandel/image.js +19 -0
- package/lib/plugin/serverHandel/none.js +15 -0
- package/lib/plugin/serverHandel/text.js +20 -0
- package/lib/plugin/sessions.js +33 -0
- package/lib/shared/IBody.js +2 -0
- package/lib/shared/IMassage.js +9 -0
- package/lib/shared/MsgMessage.js +4 -0
- package/lib/shared/PtlMessage.js +4 -0
- package/lib/shared/PtlTest.js +4 -0
- package/lib/shared/base.js +2 -0
- package/lib/shared/face/index.js +47 -0
- package/lib/shared/serviceProto.js +328 -0
- package/package.json +36 -0
- package/readme.md +9 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const fs_1 = __importDefault(require("fs"));
|
|
7
|
+
const koishi_1 = require("koishi");
|
|
8
|
+
const path = require('path');
|
|
9
|
+
const console_1 = require("./console");
|
|
10
|
+
class puppeteer extends console_1.console {
|
|
11
|
+
commonCss;
|
|
12
|
+
pageContents = new Map();
|
|
13
|
+
ctx;
|
|
14
|
+
tempDir;
|
|
15
|
+
init(ctx, config) {
|
|
16
|
+
super.init(ctx);
|
|
17
|
+
this.ctx = ctx;
|
|
18
|
+
this.log('初始化 puppeteer');
|
|
19
|
+
const pagesDir = path.resolve(__dirname, '../html/page');
|
|
20
|
+
const files = fs_1.default.readdirSync(pagesDir);
|
|
21
|
+
this.tempDir = path.resolve(path.resolve(__dirname, '../html/'), 'temp');
|
|
22
|
+
files.forEach(file => {
|
|
23
|
+
const filePath = path.join(pagesDir, file);
|
|
24
|
+
if (fs_1.default.lstatSync(filePath).isFile()) {
|
|
25
|
+
let content = fs_1.default.readFileSync(filePath, 'utf-8');
|
|
26
|
+
// 移除HTML注释
|
|
27
|
+
content = content.replace(/<!--[\s\S]*?-->/g, '');
|
|
28
|
+
let key = file.replace('.html', '');
|
|
29
|
+
this.pageContents.set(key, content);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
// 如果tempDir不存在,则创建
|
|
33
|
+
if (!fs_1.default.existsSync(this.tempDir)) {
|
|
34
|
+
fs_1.default.mkdirSync(this.tempDir, { recursive: true });
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
// 删除tempDir下的所有文件
|
|
38
|
+
fs_1.default.readdirSync(this.tempDir).forEach(file => {
|
|
39
|
+
fs_1.default.unlinkSync(path.resolve(this.tempDir, file));
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
async render(name, data) {
|
|
44
|
+
let tempHtml = this.pageContents.get(name).replace(/let data = \{[^]*?\};/, `let data = ${JSON.stringify(data)};`);
|
|
45
|
+
// 随机生成一个文件名
|
|
46
|
+
let randomName = `${name}_${Math.random().toString(36).substring(2, 15)}.html`;
|
|
47
|
+
const savePath = path.resolve(this.tempDir, randomName);
|
|
48
|
+
fs_1.default.writeFileSync(savePath, tempHtml, 'utf-8');
|
|
49
|
+
const page = await this.ctx.puppeteer.page();
|
|
50
|
+
const filePath = path.resolve(this.tempDir, randomName);
|
|
51
|
+
await page.goto(`file://${filePath}`, { waitUntil: 'networkidle2' });
|
|
52
|
+
const leaderboardElement = await page.$('body');
|
|
53
|
+
const boundingBox = await leaderboardElement.boundingBox();
|
|
54
|
+
if (boundingBox.height > 0 || boundingBox.width > 0) {
|
|
55
|
+
await page.setViewport({
|
|
56
|
+
width: Math.ceil(boundingBox.width),
|
|
57
|
+
height: Math.ceil(boundingBox.height),
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
try {
|
|
61
|
+
const imgBuf = await leaderboardElement.screenshot({ captureBeyondViewport: false, type: 'jpeg' });
|
|
62
|
+
let sendBuff = new Uint8Array(imgBuf);
|
|
63
|
+
page.close();
|
|
64
|
+
let leaderboardImage;
|
|
65
|
+
// if (sendBuff.length < 200 * 1024) { // 如果小于200kb
|
|
66
|
+
this.log(`not compress ${sendBuff.length / 1024}KB`);
|
|
67
|
+
leaderboardImage = koishi_1.h.image(sendBuff, 'image/jpeg');
|
|
68
|
+
// } else {
|
|
69
|
+
// let req = await server.api('open/CompressImg', { imgBuf: sendBuff });
|
|
70
|
+
// this.log(`compress ${req.imgBuf.length / 1024}KB`);
|
|
71
|
+
// leaderboardImage = h.image(req.imgBuf, 'image/jpeg');
|
|
72
|
+
// }
|
|
73
|
+
return leaderboardImage;
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
page.close();
|
|
77
|
+
this.log(error);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exports.default = new puppeteer();
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RateLimiter = void 0;
|
|
4
|
+
class RateLimiter {
|
|
5
|
+
userMessageTimes = new Map();
|
|
6
|
+
blacklist = new Map();
|
|
7
|
+
cleanupInterval = null;
|
|
8
|
+
blacklistDuration; // 拉黑时长(分钟)
|
|
9
|
+
maxMessagesPerMinute = 60; // 每分钟最大消息数
|
|
10
|
+
ctx;
|
|
11
|
+
constructor(blacklistDurationMinutes = 5) {
|
|
12
|
+
this.blacklistDuration = blacklistDurationMinutes * 60 * 1000; // 转换为毫秒
|
|
13
|
+
}
|
|
14
|
+
// 设置 Koishi 上下文
|
|
15
|
+
setContext(ctx) {
|
|
16
|
+
this.ctx = ctx;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* 检查用户是否可以发送消息
|
|
20
|
+
*/
|
|
21
|
+
canSendMessage(userId) {
|
|
22
|
+
const now = Date.now();
|
|
23
|
+
// 检查是否在黑名单中
|
|
24
|
+
if (this.isBlacklisted(userId)) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
// 获取用户的消息时间记录
|
|
28
|
+
const userTimes = this.userMessageTimes.get(userId) || [];
|
|
29
|
+
// 清理1分钟之前的记录
|
|
30
|
+
const oneMinuteAgo = now - 60 * 1000;
|
|
31
|
+
const recentMessages = userTimes.filter(time => time > oneMinuteAgo);
|
|
32
|
+
// 检查是否超过频率限制
|
|
33
|
+
if (recentMessages.length >= this.maxMessagesPerMinute) {
|
|
34
|
+
// 拉黑用户
|
|
35
|
+
this.blacklist.set(userId, now + this.blacklistDuration);
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
// 记录这次消息时间
|
|
39
|
+
recentMessages.push(now);
|
|
40
|
+
this.userMessageTimes.set(userId, recentMessages);
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* 检查用户是否被拉黑
|
|
45
|
+
*/
|
|
46
|
+
isBlacklisted(userId) {
|
|
47
|
+
const blacklistEnd = this.blacklist.get(userId);
|
|
48
|
+
if (!blacklistEnd)
|
|
49
|
+
return false;
|
|
50
|
+
const now = Date.now();
|
|
51
|
+
if (now > blacklistEnd) {
|
|
52
|
+
// 拉黑时间已过,移除黑名单
|
|
53
|
+
this.blacklist.delete(userId);
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* 启动定期清理
|
|
60
|
+
*/
|
|
61
|
+
startCleanup() {
|
|
62
|
+
if (this.ctx) {
|
|
63
|
+
const scheduleNext = () => {
|
|
64
|
+
this.cleanupInterval = this.ctx?.setTimeout(() => {
|
|
65
|
+
this.cleanup();
|
|
66
|
+
if (this.cleanupInterval) {
|
|
67
|
+
scheduleNext(); // 递归调度下一次清理
|
|
68
|
+
}
|
|
69
|
+
}, 5 * 60 * 1000); // 每5分钟清理一次
|
|
70
|
+
};
|
|
71
|
+
scheduleNext();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* 停止定期清理
|
|
76
|
+
*/
|
|
77
|
+
stopCleanup() {
|
|
78
|
+
this.cleanupInterval = null; // 停止递归调度
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* 清理过期数据
|
|
82
|
+
*/
|
|
83
|
+
cleanup() {
|
|
84
|
+
const now = Date.now();
|
|
85
|
+
const oneHourAgo = now - 60 * 60 * 1000;
|
|
86
|
+
// 清理消息时间记录
|
|
87
|
+
for (const [userId, times] of this.userMessageTimes.entries()) {
|
|
88
|
+
const recentTimes = times.filter(time => time > oneHourAgo);
|
|
89
|
+
if (recentTimes.length === 0) {
|
|
90
|
+
this.userMessageTimes.delete(userId);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
this.userMessageTimes.set(userId, recentTimes);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
// 清理过期的黑名单
|
|
97
|
+
for (const [userId, blacklistEnd] of this.blacklist.entries()) {
|
|
98
|
+
if (now > blacklistEnd) {
|
|
99
|
+
this.blacklist.delete(userId);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
exports.RateLimiter = RateLimiter;
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tsrpc_1 = require("tsrpc");
|
|
4
|
+
const console_1 = require("./console");
|
|
5
|
+
const serviceProto_1 = require("../shared/serviceProto");
|
|
6
|
+
class server extends console_1.console {
|
|
7
|
+
httpClient;
|
|
8
|
+
apiUrl;
|
|
9
|
+
wsClient;
|
|
10
|
+
ctx;
|
|
11
|
+
onConnectedCallback;
|
|
12
|
+
messageListenerSetup = false; // 标记消息监听器是否已设置
|
|
13
|
+
_init = false;
|
|
14
|
+
constructor() {
|
|
15
|
+
super();
|
|
16
|
+
}
|
|
17
|
+
async init(ctx, config) {
|
|
18
|
+
super.init(ctx, config);
|
|
19
|
+
this.ctx = ctx;
|
|
20
|
+
// 设置 dispose 事件监听器
|
|
21
|
+
ctx.on('dispose', () => {
|
|
22
|
+
// 修复热重载 监听残留
|
|
23
|
+
this.dispose();
|
|
24
|
+
});
|
|
25
|
+
// 确保重新初始化时先清理旧连接
|
|
26
|
+
if (this.wsClient) {
|
|
27
|
+
await this.dispose();
|
|
28
|
+
}
|
|
29
|
+
// 根据服务器环境选择对应的地址
|
|
30
|
+
const serverUrlMap = {
|
|
31
|
+
'测试服': 'ws://127.0.0.1:3000',
|
|
32
|
+
'开发服': 'ws://dev-bot.cn:3000',
|
|
33
|
+
'正式服': 'ws://dew-bot.cn:3000'
|
|
34
|
+
};
|
|
35
|
+
const serverUrl = serverUrlMap[config.服务器环境];
|
|
36
|
+
if (!serverUrl) {
|
|
37
|
+
throw new Error(`未知的服务器环境: ${config.服务器环境}`);
|
|
38
|
+
}
|
|
39
|
+
this.log(`选择环境: ${config.服务器环境}`);
|
|
40
|
+
this.log(`尝试连接到: ${serverUrl}`);
|
|
41
|
+
// 异步连接但不阻塞初始化
|
|
42
|
+
this.setWsUrl(serverUrl).catch(error => {
|
|
43
|
+
this.log('初始化连接失败:', error);
|
|
44
|
+
this.log('请检查服务器地址是否正确,以及服务器是否正在运行');
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
// 设置连接成功的回调
|
|
48
|
+
onConnected(callback) {
|
|
49
|
+
this.onConnectedCallback = callback;
|
|
50
|
+
// 如果已经连接且监听器未设置,立即调用回调
|
|
51
|
+
if (this._init && this.wsClient && !this.messageListenerSetup) {
|
|
52
|
+
callback();
|
|
53
|
+
this.messageListenerSetup = true;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
// 卸载
|
|
57
|
+
async dispose() {
|
|
58
|
+
this.log('卸载:server');
|
|
59
|
+
this._init = false;
|
|
60
|
+
if (this.wsClient) {
|
|
61
|
+
this.wsClient.unlistenMsgAll(/.*/);
|
|
62
|
+
this.wsClient.disconnect();
|
|
63
|
+
// 清除对 wsClient 的引用
|
|
64
|
+
this.wsClient = null;
|
|
65
|
+
}
|
|
66
|
+
// 清除回调和监听器状态
|
|
67
|
+
this.onConnectedCallback = undefined;
|
|
68
|
+
this.messageListenerSetup = false;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* 设置服务器地址
|
|
72
|
+
* @param link
|
|
73
|
+
*/
|
|
74
|
+
async setApiUrl(link) {
|
|
75
|
+
return new Promise((resolve, reject) => {
|
|
76
|
+
this.apiUrl = `${link}`;
|
|
77
|
+
this.httpClient = new tsrpc_1.HttpClient(serviceProto_1.serviceProto, { server: this.apiUrl });
|
|
78
|
+
this.flowsToken(this.httpClient);
|
|
79
|
+
resolve(true);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
flowsToken(client) {
|
|
83
|
+
client.flows.preApiReturnFlow.push((v) => {
|
|
84
|
+
if (v.return.isSucc) {
|
|
85
|
+
if (v.return.res.__token) {
|
|
86
|
+
// tokenMap.set('_token', v.return.res.__token)
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return v;
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
flowsResConnect(client) {
|
|
93
|
+
if (!client || !client.flows) {
|
|
94
|
+
this.log('客户端无效,无法设置断线重连');
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
client.flows.postDisconnectFlow.push((v) => {
|
|
98
|
+
if (!v.isManual && this._init) {
|
|
99
|
+
this.connect();
|
|
100
|
+
this.log('开始断线重连');
|
|
101
|
+
}
|
|
102
|
+
// Bot_client.emit(Emitter_bot.server_off);
|
|
103
|
+
return v;
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
async connect() {
|
|
107
|
+
if (!this._init) {
|
|
108
|
+
this.log('插件已卸载,停止重连');
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
if (!this.wsClient) {
|
|
112
|
+
this.log('WebSocket 客户端未初始化,无法重连');
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
let res = await this.wsClient.connect();
|
|
116
|
+
if (!res.isSucc) {
|
|
117
|
+
this.log('重试断线准备重连');
|
|
118
|
+
if (this._init) {
|
|
119
|
+
this.ctx.setTimeout(async () => {
|
|
120
|
+
this.connect();
|
|
121
|
+
}, 5000);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
this.log('断线重连成功');
|
|
126
|
+
// 断线重连成功时不需要重新设置监听器
|
|
127
|
+
}
|
|
128
|
+
return res;
|
|
129
|
+
}
|
|
130
|
+
lisentMsg(msgName, handler, self) {
|
|
131
|
+
if (!this._init || !this.wsClient) {
|
|
132
|
+
this.log('WebSocket 未连接,无法监听消息');
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
return this.wsClient.listenMsg(msgName, ((data) => { handler.call(self, data); }));
|
|
136
|
+
}
|
|
137
|
+
async setWsUrl(link, maxRetries = 99999) {
|
|
138
|
+
this.log(`server link:${link}`);
|
|
139
|
+
this._init = true;
|
|
140
|
+
return new Promise(async (resolve, reject) => {
|
|
141
|
+
this.apiUrl = link;
|
|
142
|
+
if (this.wsClient && this.wsClient.unlistenMsgAll) {
|
|
143
|
+
this.wsClient.unlistenMsgAll(/.*/);
|
|
144
|
+
this.wsClient.disconnect();
|
|
145
|
+
}
|
|
146
|
+
this.wsClient = new tsrpc_1.WsClient(serviceProto_1.serviceProto, { server: this.apiUrl });
|
|
147
|
+
let connect;
|
|
148
|
+
let retryCount = 0;
|
|
149
|
+
const attemptConnect = async () => {
|
|
150
|
+
connect = await this.wsClient.connect();
|
|
151
|
+
if (connect.isSucc) {
|
|
152
|
+
// this.flowsToken(this.wsClient);
|
|
153
|
+
if (this.wsClient) {
|
|
154
|
+
this.flowsResConnect(this.wsClient);
|
|
155
|
+
}
|
|
156
|
+
this.log('connect success');
|
|
157
|
+
// 调用连接成功的回调(仅第一次连接)
|
|
158
|
+
if (this.onConnectedCallback && !this.messageListenerSetup) {
|
|
159
|
+
this.onConnectedCallback();
|
|
160
|
+
this.messageListenerSetup = true;
|
|
161
|
+
}
|
|
162
|
+
resolve(true);
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
retryCount++;
|
|
166
|
+
if (retryCount < maxRetries) {
|
|
167
|
+
this.log(`连接失败,${retryCount}/${maxRetries},5秒后重试...`);
|
|
168
|
+
this.ctx.setTimeout(attemptConnect, 5000);
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
this.log('connect failed', connect.errMsg);
|
|
172
|
+
this._init = false; // 连接失败时设置为未初始化状态
|
|
173
|
+
reject(connect.errMsg);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
attemptConnect();
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
async api(apiName, posData) {
|
|
181
|
+
if (!this._init) {
|
|
182
|
+
this.log('插件未初始化,无法调用 API');
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
let client = this.wsClient || this.httpClient;
|
|
186
|
+
if (!client) {
|
|
187
|
+
this.log('客户端未连接,无法调用 API');
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
try {
|
|
191
|
+
let start = Date.now();
|
|
192
|
+
let req = await client.callApi(apiName, posData);
|
|
193
|
+
if (req.isSucc) {
|
|
194
|
+
this.log('apiReq', apiName, (Date.now() - start) / 1000, 's');
|
|
195
|
+
return req.res;
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
this.log('请求出错', apiName, req.err.message);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
catch (error) {
|
|
202
|
+
this.log('API 调用异常:', apiName, error.message);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
exports.default = new server();
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const sessions_1 = __importDefault(require("../sessions"));
|
|
7
|
+
class handel_base {
|
|
8
|
+
ctx;
|
|
9
|
+
constructor(data) {
|
|
10
|
+
console.log('handel_base:::', data);
|
|
11
|
+
}
|
|
12
|
+
set(ctx) {
|
|
13
|
+
this.ctx = ctx;
|
|
14
|
+
}
|
|
15
|
+
async send(data, content) {
|
|
16
|
+
let sendInfo = data.Message;
|
|
17
|
+
let session = sessions_1.default.get(sendInfo.userId);
|
|
18
|
+
if (session.bot.platform) {
|
|
19
|
+
content = '\n' + content;
|
|
20
|
+
}
|
|
21
|
+
await session.send(content);
|
|
22
|
+
}
|
|
23
|
+
start(data) {
|
|
24
|
+
console.log('handel_base:::', data);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.default = handel_base;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const puppeteer_1 = __importDefault(require("../puppeteer"));
|
|
7
|
+
const handel_base_1 = __importDefault(require("./handel_base"));
|
|
8
|
+
class handelr_image extends handel_base_1.default {
|
|
9
|
+
constructor(data) {
|
|
10
|
+
super(data);
|
|
11
|
+
}
|
|
12
|
+
async start(data) {
|
|
13
|
+
let renderName = data.info.render;
|
|
14
|
+
puppeteer_1.default.render(renderName, data.data || {}).then(async (e) => {
|
|
15
|
+
await this.send(data, e);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.default = handelr_image;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const handel_base_1 = __importDefault(require("./handel_base"));
|
|
7
|
+
class handelr_none extends handel_base_1.default {
|
|
8
|
+
constructor(data) {
|
|
9
|
+
super(data);
|
|
10
|
+
}
|
|
11
|
+
async start(data) {
|
|
12
|
+
console.log('handelr_none:::', data);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.default = handelr_none;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const handel_base_1 = __importDefault(require("./handel_base"));
|
|
7
|
+
class handelr_text extends handel_base_1.default {
|
|
8
|
+
constructor(data) {
|
|
9
|
+
super(data);
|
|
10
|
+
}
|
|
11
|
+
async start(data) {
|
|
12
|
+
if (data.info.type == 'text') {
|
|
13
|
+
await this.send(data, data.data);
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
console.log('未知类型的文本消息');
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.default = handelr_text;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class sessions {
|
|
4
|
+
sessions = new Map();
|
|
5
|
+
constructor() {
|
|
6
|
+
this.sessions = new Map();
|
|
7
|
+
}
|
|
8
|
+
init(ctx) {
|
|
9
|
+
ctx.on('dispose', () => {
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* @param key userid
|
|
15
|
+
* @param value 会话
|
|
16
|
+
*/
|
|
17
|
+
set(key, value) {
|
|
18
|
+
this.sessions.set(key, value);
|
|
19
|
+
}
|
|
20
|
+
get(key) {
|
|
21
|
+
return this.sessions.get(key);
|
|
22
|
+
}
|
|
23
|
+
delete(key) {
|
|
24
|
+
this.sessions.delete(key);
|
|
25
|
+
}
|
|
26
|
+
clear() {
|
|
27
|
+
this.sessions.clear();
|
|
28
|
+
}
|
|
29
|
+
size() {
|
|
30
|
+
return this.sessions.size;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.default = new sessions();
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ClientAction = void 0;
|
|
4
|
+
var ClientAction;
|
|
5
|
+
(function (ClientAction) {
|
|
6
|
+
ClientAction["none"] = "none";
|
|
7
|
+
ClientAction["image"] = "image";
|
|
8
|
+
ClientAction["text"] = "text";
|
|
9
|
+
})(ClientAction || (exports.ClientAction = ClientAction = {}));
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.quality = exports.EquipAttType = exports.UserLevel = exports.ItemType = void 0;
|
|
4
|
+
var ItemType;
|
|
5
|
+
(function (ItemType) {
|
|
6
|
+
ItemType["\u8D44\u6E90"] = "prop_\u8D44\u6E90";
|
|
7
|
+
// 装备
|
|
8
|
+
ItemType["\u88C5\u5907"] = "equipment";
|
|
9
|
+
// 消耗品
|
|
10
|
+
ItemType["\u9053\u5177"] = "prop_\u9053\u5177";
|
|
11
|
+
// 消耗品 - 不可叠加
|
|
12
|
+
ItemType["\u6280\u80FD\u4E66"] = "skill_book";
|
|
13
|
+
// 宠物蛋
|
|
14
|
+
ItemType["\u5BA0\u7269\u86CB"] = "pet_egg";
|
|
15
|
+
// 血统卷轴
|
|
16
|
+
ItemType["\u8840\u7EDF\u5377\u8F74"] = "talent_book";
|
|
17
|
+
// 盲盒
|
|
18
|
+
ItemType["\u76F2\u76D2"] = "prop_\u76F2\u76D2";
|
|
19
|
+
// 形象卡
|
|
20
|
+
ItemType["\u5F62\u8C61\u5361"] = "image_card";
|
|
21
|
+
})(ItemType || (exports.ItemType = ItemType = {}));
|
|
22
|
+
var UserLevel;
|
|
23
|
+
(function (UserLevel) {
|
|
24
|
+
UserLevel[UserLevel["\u73A9\u5BB6"] = 0] = "\u73A9\u5BB6";
|
|
25
|
+
UserLevel[UserLevel["\u8D5E\u52A9\u4F1A\u5458"] = 1] = "\u8D5E\u52A9\u4F1A\u5458";
|
|
26
|
+
UserLevel[UserLevel["\u7BA1\u7406\u5458"] = 2] = "\u7BA1\u7406\u5458";
|
|
27
|
+
UserLevel[UserLevel["\u5F00\u53D1\u8005"] = 3] = "\u5F00\u53D1\u8005";
|
|
28
|
+
})(UserLevel || (exports.UserLevel = UserLevel = {}));
|
|
29
|
+
var EquipAttType;
|
|
30
|
+
(function (EquipAttType) {
|
|
31
|
+
EquipAttType["\u9B54\u6CD5\u6B66\u5668"] = "\u9B54\u6CD5\u6B66\u5668";
|
|
32
|
+
})(EquipAttType || (exports.EquipAttType = EquipAttType = {}));
|
|
33
|
+
//品质
|
|
34
|
+
var quality;
|
|
35
|
+
(function (quality) {
|
|
36
|
+
quality[quality["F"] = 0] = "F";
|
|
37
|
+
quality[quality["D"] = 1] = "D";
|
|
38
|
+
quality[quality["C"] = 2] = "C";
|
|
39
|
+
quality[quality["B"] = 3] = "B";
|
|
40
|
+
quality[quality["A"] = 4] = "A";
|
|
41
|
+
quality[quality["S"] = 5] = "S";
|
|
42
|
+
// 常规顶级
|
|
43
|
+
quality[quality["SS"] = 6] = "SS";
|
|
44
|
+
quality[quality["SSS"] = 7] = "SSS";
|
|
45
|
+
quality[quality["SR"] = 8] = "SR";
|
|
46
|
+
quality[quality["SSR"] = 9] = "SSR";
|
|
47
|
+
})(quality || (exports.quality = quality = {}));
|