koishi-plugin-bilirice 0.0.3 → 0.0.4
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/index.d.ts +16 -3
- package/lib/index.js +160 -149
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
import { Context, Schema } from 'koishi';
|
|
2
2
|
export declare const name = "bilirice";
|
|
3
|
+
interface BiliriceConfig {
|
|
4
|
+
anchors: [string, string][];
|
|
5
|
+
pollInterval?: number;
|
|
6
|
+
templates?: {
|
|
7
|
+
liveStart?: string;
|
|
8
|
+
liveEnd?: string;
|
|
9
|
+
};
|
|
10
|
+
timeout?: number;
|
|
11
|
+
bilibiliCookie?: string;
|
|
12
|
+
}
|
|
3
13
|
export declare const Config: Schema<Schemastery.ObjectS<{
|
|
4
14
|
anchors: Schema<[string?, string?, ...any[]][], [string?, string?, ...any[]][]>;
|
|
5
15
|
pollInterval: Schema<number, number>;
|
|
16
|
+
timeout: Schema<number, number>;
|
|
17
|
+
bilibiliCookie: Schema<string, string>;
|
|
6
18
|
templates: Schema<Schemastery.ObjectS<{
|
|
7
19
|
liveStart: Schema<string, string>;
|
|
8
20
|
liveEnd: Schema<string, string>;
|
|
@@ -10,10 +22,11 @@ export declare const Config: Schema<Schemastery.ObjectS<{
|
|
|
10
22
|
liveStart: Schema<string, string>;
|
|
11
23
|
liveEnd: Schema<string, string>;
|
|
12
24
|
}>>;
|
|
13
|
-
timeout: Schema<number, number>;
|
|
14
25
|
}>, Schemastery.ObjectT<{
|
|
15
26
|
anchors: Schema<[string?, string?, ...any[]][], [string?, string?, ...any[]][]>;
|
|
16
27
|
pollInterval: Schema<number, number>;
|
|
28
|
+
timeout: Schema<number, number>;
|
|
29
|
+
bilibiliCookie: Schema<string, string>;
|
|
17
30
|
templates: Schema<Schemastery.ObjectS<{
|
|
18
31
|
liveStart: Schema<string, string>;
|
|
19
32
|
liveEnd: Schema<string, string>;
|
|
@@ -21,6 +34,6 @@ export declare const Config: Schema<Schemastery.ObjectS<{
|
|
|
21
34
|
liveStart: Schema<string, string>;
|
|
22
35
|
liveEnd: Schema<string, string>;
|
|
23
36
|
}>>;
|
|
24
|
-
timeout: Schema<number, number>;
|
|
25
37
|
}>>;
|
|
26
|
-
export declare function apply(ctx: Context, config:
|
|
38
|
+
export declare function apply(ctx: Context, config: BiliriceConfig): void;
|
|
39
|
+
export {};
|
package/lib/index.js
CHANGED
|
@@ -37,104 +37,121 @@ __export(src_exports, {
|
|
|
37
37
|
module.exports = __toCommonJS(src_exports);
|
|
38
38
|
var import_koishi = require("koishi");
|
|
39
39
|
var import_axios = __toESM(require("axios"));
|
|
40
|
+
var import_https = __toESM(require("https"));
|
|
40
41
|
var name = "bilirice";
|
|
41
42
|
var Config = import_koishi.Schema.object({
|
|
42
43
|
anchors: import_koishi.Schema.array(import_koishi.Schema.tuple([
|
|
43
|
-
import_koishi.Schema.string().description("
|
|
44
|
-
import_koishi.Schema.string().description("
|
|
45
|
-
])).required().description("
|
|
46
|
-
pollInterval: import_koishi.Schema.number().default(10).description("
|
|
44
|
+
import_koishi.Schema.string().description("B站主播UID(数字,如老番茄14663353)"),
|
|
45
|
+
import_koishi.Schema.string().description("通知群号(OneBot格式加group_前缀,如group_123456789)")
|
|
46
|
+
])).required().description("监听的主播列表 → 点击「添加项」可配置多个主播").role("table"),
|
|
47
|
+
pollInterval: import_koishi.Schema.number().default(10).description("轮询间隔(秒),建议≥5秒(避免触发B站API风控)").role("slider", { min: 5, max: 30, step: 1 }),
|
|
48
|
+
// 控制台显示滑块,更易用
|
|
49
|
+
timeout: import_koishi.Schema.number().default(1e4).description("API请求超时时间(毫秒),建议5000-15000").role("number", { min: 5e3, max: 3e4 }),
|
|
50
|
+
// 核心:Cookie字段适配控制台(密码类型,输入隐藏 + 详细说明)
|
|
51
|
+
bilibiliCookie: import_koishi.Schema.string().description(`【必填】B站登录Cookie(解决-352错误)
|
|
52
|
+
获取方式:
|
|
53
|
+
1. 登录B站直播页 https://live.bilibili.com/
|
|
54
|
+
2. F12 → 网络 → 搜索 getInfoByRoom
|
|
55
|
+
3. 复制请求头中的「Cookie」完整值
|
|
56
|
+
(包含SESSDATA/bili_jct/DedeUserID等核心字段)`).required().role("password"),
|
|
57
|
+
// 控制台显示为密码输入框,输入内容隐藏
|
|
58
|
+
// 通知模板:控制台支持多行文本编辑
|
|
47
59
|
templates: import_koishi.Schema.object({
|
|
48
|
-
liveStart: import_koishi.Schema.string().default("【{uname} 开播啦】\n标题:{title}\n分区:{area}\n链接:{url}\n开播时间:{startTime}\n封面:{cover}").description("
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
60
|
+
liveStart: import_koishi.Schema.string().default("【{uname} 开播啦】\n标题:{title}\n分区:{area}\n链接:{url}\n开播时间:{startTime}\n封面:{cover}").description("开播通知模板,支持占位符:{uname}/{title}/{area}/{url}/{startTime}/{cover}").role("textarea"),
|
|
61
|
+
// 控制台显示多行文本框
|
|
62
|
+
liveEnd: import_koishi.Schema.string().default("【{uname} 下播啦】\n直播时长:{liveTime}\n最高在线:{peakOnline}\n观看人数:{watchCount}\n弹幕数:{dmCount}\n人均弹幕:{avgDmPerUser}\n下播时间:{endTime}").description("下播通知模板,额外支持:{liveTime}/{peakOnline}/{watchCount}/{dmCount}/{avgDmPerUser}/{endTime}").role("textarea")
|
|
63
|
+
}).description("自定义通知模板(保留占位符即可自动替换数据)")
|
|
52
64
|
});
|
|
53
65
|
function apply(ctx, config) {
|
|
54
66
|
const finalConfig = {
|
|
55
67
|
pollInterval: config.pollInterval || 10,
|
|
56
|
-
timeout: config.timeout ||
|
|
68
|
+
timeout: config.timeout || 1e4,
|
|
57
69
|
templates: {
|
|
58
70
|
liveStart: config.templates?.liveStart || "【{uname} 开播啦】\n标题:{title}\n分区:{area}\n链接:{url}\n开播时间:{startTime}\n封面:{cover}",
|
|
59
71
|
liveEnd: config.templates?.liveEnd || "【{uname} 下播啦】\n直播时长:{liveTime}\n最高在线:{peakOnline}\n观看人数:{watchCount}\n弹幕数:{dmCount}\n人均弹幕:{avgDmPerUser}\n下播时间:{endTime}"
|
|
60
72
|
},
|
|
61
|
-
anchors: config.anchors || []
|
|
73
|
+
anchors: config.anchors || [],
|
|
74
|
+
bilibiliCookie: config.bilibiliCookie || ""
|
|
62
75
|
};
|
|
63
76
|
const anchorStateCache = /* @__PURE__ */ new Map();
|
|
64
77
|
const api = import_axios.default.create({
|
|
65
78
|
baseURL: "https://api.live.bilibili.com",
|
|
66
79
|
timeout: finalConfig.timeout,
|
|
80
|
+
httpsAgent: new import_https.default.Agent({ rejectUnauthorized: false }),
|
|
67
81
|
headers: {
|
|
68
|
-
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/
|
|
69
|
-
"Referer": "https://live.bilibili.com/"
|
|
70
|
-
|
|
71
|
-
|
|
82
|
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36 Edg/130.0.0.0",
|
|
83
|
+
"Referer": "https://live.bilibili.com/",
|
|
84
|
+
"Origin": "https://live.bilibili.com",
|
|
85
|
+
"Accept": "application/json, text/plain, */*",
|
|
86
|
+
"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-US;q=0.7",
|
|
87
|
+
"Cache-Control": "no-cache",
|
|
88
|
+
"Pragma": "no-cache",
|
|
89
|
+
"Sec-Fetch-Dest": "empty",
|
|
90
|
+
"Sec-Fetch-Mode": "cors",
|
|
91
|
+
"Sec-Fetch-Site": "same-site",
|
|
92
|
+
"Cookie": finalConfig.bilibiliCookie
|
|
93
|
+
// 读取控制台配置的Cookie
|
|
94
|
+
},
|
|
95
|
+
transformResponse: [(data) => data]
|
|
72
96
|
});
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
97
|
+
api.interceptors.response.use(
|
|
98
|
+
(response) => {
|
|
99
|
+
try {
|
|
100
|
+
response.data = JSON.parse(response.data);
|
|
101
|
+
return response;
|
|
102
|
+
} catch (err) {
|
|
103
|
+
throw new Error(`API响应解析失败: ${err.message}`);
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
(error) => {
|
|
107
|
+
throw new Error(`API请求失败: ${error.message || error.code}`);
|
|
81
108
|
}
|
|
109
|
+
);
|
|
110
|
+
async function getRoomIdByMid(mid) {
|
|
111
|
+
const res = await api.get("/room/v1/Room/getRoomInfoOld", {
|
|
112
|
+
params: { mid: Number(mid) }
|
|
113
|
+
});
|
|
114
|
+
if (res.data.code !== 0) throw new Error(`获取直播间ID失败: ${res.data.code} ${res.data.message || ""}`);
|
|
115
|
+
return res.data.data.roomid.toString();
|
|
82
116
|
}
|
|
83
117
|
__name(getRoomIdByMid, "getRoomIdByMid");
|
|
84
118
|
async function getRoomBaseInfo(roomId) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
ctx.logger.error(`获取直播间基础信息失败(roomId=${roomId}):`, err);
|
|
91
|
-
throw err;
|
|
92
|
-
}
|
|
119
|
+
const res = await api.get("/room/v1/Room/get_info", {
|
|
120
|
+
params: { room_id: Number(roomId) }
|
|
121
|
+
});
|
|
122
|
+
if (res.data.code !== 0) throw new Error(`获取直播间基础信息失败: ${res.data.code} ${res.data.message || ""}`);
|
|
123
|
+
return res.data.data;
|
|
93
124
|
}
|
|
94
125
|
__name(getRoomBaseInfo, "getRoomBaseInfo");
|
|
95
126
|
async function getRoomStat(roomId) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
// 舰队数
|
|
117
|
-
fans_count: data.anchor_info.base_info.fans_count || 0,
|
|
118
|
-
// 粉丝数
|
|
119
|
-
live_time: data.room_info.live_time || 0
|
|
120
|
-
// 开播时间戳
|
|
121
|
-
};
|
|
122
|
-
return stat;
|
|
123
|
-
} catch (err) {
|
|
124
|
-
ctx.logger.error(`获取直播间统计失败(roomId=${roomId}):`, err);
|
|
125
|
-
throw err;
|
|
126
|
-
}
|
|
127
|
+
const res = await api.get("/xlive/web-room/v1/index/getInfoByRoom", {
|
|
128
|
+
params: {
|
|
129
|
+
room_id: Number(roomId),
|
|
130
|
+
platform: "web",
|
|
131
|
+
version: "1.0.0",
|
|
132
|
+
ts: Date.now()
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
if (res.data.code !== 0) throw new Error(`获取直播间统计失败: ${res.data.code} ${res.data.message || ""}`);
|
|
136
|
+
const data = res.data.data;
|
|
137
|
+
if (!data || !data.room_info) throw new Error("获取直播间统计失败: 返回数据结构异常");
|
|
138
|
+
return {
|
|
139
|
+
online: data.room_info.online || 0,
|
|
140
|
+
watch_num: data.room_info.watch_num || 0,
|
|
141
|
+
interact_num: data.room_info.interact_num || 0,
|
|
142
|
+
dm_count: data.room_info.dm_count || 0,
|
|
143
|
+
medal_count: data.room_info.medal_count || 0,
|
|
144
|
+
fans_count: data.anchor_info?.base_info?.fans_count || 0,
|
|
145
|
+
live_time: data.room_info.live_time || 0
|
|
146
|
+
};
|
|
127
147
|
}
|
|
128
148
|
__name(getRoomStat, "getRoomStat");
|
|
129
149
|
async function getAnchorInfo(roomId) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
ctx.logger.error(`获取主播信息失败(roomId=${roomId}):`, err);
|
|
136
|
-
throw err;
|
|
137
|
-
}
|
|
150
|
+
const res = await api.get("/live_user/v1/UserInfo/get_anchor_in_room", {
|
|
151
|
+
params: { roomid: Number(roomId) }
|
|
152
|
+
});
|
|
153
|
+
if (res.data.code !== 0) throw new Error(`获取主播信息失败: ${res.data.code} ${res.data.message || ""}`);
|
|
154
|
+
return res.data.data;
|
|
138
155
|
}
|
|
139
156
|
__name(getAnchorInfo, "getAnchorInfo");
|
|
140
157
|
function formatTime(timestamp) {
|
|
@@ -157,11 +174,7 @@ function apply(ctx, config) {
|
|
|
157
174
|
__name(formatSeconds, "formatSeconds");
|
|
158
175
|
function calcLiveStat(startTime, endTime, lastStat, currentStat) {
|
|
159
176
|
let fansChange = 0;
|
|
160
|
-
|
|
161
|
-
fansChange = currentStat.fans_count - (lastStat?.fans_count || currentStat.fans_count);
|
|
162
|
-
} catch (e) {
|
|
163
|
-
fansChange = Math.floor(Math.random() * 100);
|
|
164
|
-
}
|
|
177
|
+
if (lastStat && currentStat) fansChange = currentStat.fans_count - lastStat.fans_count;
|
|
165
178
|
return {
|
|
166
179
|
liveTime: endTime - startTime,
|
|
167
180
|
peakOnline: currentStat.online,
|
|
@@ -181,33 +194,23 @@ function apply(ctx, config) {
|
|
|
181
194
|
__name(renderTemplate, "renderTemplate");
|
|
182
195
|
async function sendGroupMessage(groupId, message) {
|
|
183
196
|
const bot = ctx.bots.values().next().value;
|
|
184
|
-
if (!bot)
|
|
185
|
-
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
try {
|
|
189
|
-
await bot.sendMessage(groupId, message);
|
|
190
|
-
} catch (err) {
|
|
191
|
-
ctx.logger.error(`发送群消息失败(群号=${groupId}):`, err);
|
|
192
|
-
}
|
|
197
|
+
if (!bot) throw new Error("未找到可用的Bot实例");
|
|
198
|
+
await bot.sendMessage(groupId, message);
|
|
193
199
|
}
|
|
194
200
|
__name(sendGroupMessage, "sendGroupMessage");
|
|
195
201
|
async function initAnchorState(mid) {
|
|
196
202
|
if (anchorStateCache.has(mid)) return;
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
} catch (err) {
|
|
209
|
-
ctx.logger.error(`初始化主播状态失败(mid=${mid}):`, err);
|
|
210
|
-
}
|
|
203
|
+
const roomId = await getRoomIdByMid(mid);
|
|
204
|
+
const roomInfo = await getRoomBaseInfo(roomId);
|
|
205
|
+
const isOnline = roomInfo.live_status === 1;
|
|
206
|
+
const lastStat = isOnline ? await getRoomStat(roomId) : null;
|
|
207
|
+
anchorStateCache.set(mid, {
|
|
208
|
+
mid,
|
|
209
|
+
roomId,
|
|
210
|
+
isOnline,
|
|
211
|
+
liveStartTime: isOnline ? roomInfo.live_time : 0,
|
|
212
|
+
lastStat
|
|
213
|
+
});
|
|
211
214
|
}
|
|
212
215
|
__name(initAnchorState, "initAnchorState");
|
|
213
216
|
async function checkAnchorState(mid, groupIds) {
|
|
@@ -216,75 +219,83 @@ function apply(ctx, config) {
|
|
|
216
219
|
await initAnchorState(mid);
|
|
217
220
|
return;
|
|
218
221
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
222
|
+
const roomInfo = await getRoomBaseInfo(state.roomId);
|
|
223
|
+
const currentOnline = roomInfo.live_status === 1;
|
|
224
|
+
const anchorInfo = await getAnchorInfo(state.roomId);
|
|
225
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
226
|
+
if (!state.isOnline && currentOnline) {
|
|
223
227
|
const currentStat = await getRoomStat(state.roomId);
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
state.lastStat = currentStat;
|
|
262
|
-
}
|
|
263
|
-
} catch (err) {
|
|
264
|
-
ctx.logger.error(`检查主播状态失败(mid=${mid}):`, err);
|
|
228
|
+
state.isOnline = true;
|
|
229
|
+
state.liveStartTime = roomInfo.live_time || now;
|
|
230
|
+
state.lastStat = currentStat;
|
|
231
|
+
const templateData = {
|
|
232
|
+
uname: anchorInfo.info.uname,
|
|
233
|
+
title: roomInfo.title,
|
|
234
|
+
area: `${roomInfo.parent_area_name || ""} - ${roomInfo.area_name || ""}`,
|
|
235
|
+
url: `https://live.bilibili.com/${state.roomId}`,
|
|
236
|
+
startTime: formatTime(state.liveStartTime),
|
|
237
|
+
cover: import_koishi.segment.image(roomInfo.user_cover || "")
|
|
238
|
+
};
|
|
239
|
+
const message = renderTemplate(finalConfig.templates.liveStart, templateData);
|
|
240
|
+
for (const gid of groupIds) await sendGroupMessage(gid, message);
|
|
241
|
+
ctx.logger.info(`主播${mid}开播,已发送通知到指定群聊`);
|
|
242
|
+
} else if (state.isOnline && !currentOnline && state.liveStartTime > 0) {
|
|
243
|
+
const currentStat = await getRoomStat(state.roomId);
|
|
244
|
+
const liveStat = calcLiveStat(state.liveStartTime, now, state.lastStat, currentStat);
|
|
245
|
+
state.isOnline = false;
|
|
246
|
+
state.liveStartTime = 0;
|
|
247
|
+
const templateData = {
|
|
248
|
+
uname: anchorInfo.info.uname,
|
|
249
|
+
liveTime: formatSeconds(liveStat.liveTime),
|
|
250
|
+
peakOnline: liveStat.peakOnline.toLocaleString(),
|
|
251
|
+
watchCount: liveStat.watchCount.toLocaleString(),
|
|
252
|
+
dmCount: liveStat.dmCount.toLocaleString(),
|
|
253
|
+
avgDmPerUser: liveStat.avgDmPerUser,
|
|
254
|
+
medalCount: liveStat.medalCount.toLocaleString(),
|
|
255
|
+
fansChange: liveStat.fansChange > 0 ? `+${liveStat.fansChange}` : liveStat.fansChange.toString(),
|
|
256
|
+
endTime: formatTime(liveStat.endTime),
|
|
257
|
+
url: `https://live.bilibili.com/${state.roomId}`
|
|
258
|
+
};
|
|
259
|
+
const message = renderTemplate(finalConfig.templates.liveEnd, templateData);
|
|
260
|
+
for (const gid of groupIds) await sendGroupMessage(gid, message);
|
|
261
|
+
ctx.logger.info(`主播${mid}下播,已发送统计通知到指定群聊`);
|
|
262
|
+
} else if (state.isOnline && currentOnline) {
|
|
263
|
+
const currentStat = await getRoomStat(state.roomId);
|
|
264
|
+
state.lastStat = currentStat;
|
|
265
265
|
}
|
|
266
266
|
}
|
|
267
267
|
__name(checkAnchorState, "checkAnchorState");
|
|
268
268
|
ctx.on("ready", async () => {
|
|
269
269
|
if (!finalConfig.anchors || finalConfig.anchors.length === 0) {
|
|
270
|
-
ctx.logger.
|
|
270
|
+
ctx.logger.error("bilirice插件未配置任何主播,无法启动!");
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
if (!finalConfig.bilibiliCookie) {
|
|
274
|
+
ctx.logger.error("bilirice插件未配置B站Cookie,无法解决-352错误,请补充配置!");
|
|
271
275
|
return;
|
|
272
276
|
}
|
|
273
|
-
for (const [mid, _] of finalConfig.anchors)
|
|
277
|
+
for (const [mid, _] of finalConfig.anchors) {
|
|
278
|
+
await initAnchorState(mid).catch((err) => ctx.logger.error(`初始化主播${mid}失败:`, err.message));
|
|
279
|
+
}
|
|
274
280
|
ctx.setInterval(async () => {
|
|
275
281
|
for (const [mid, groupStr] of finalConfig.anchors) {
|
|
276
282
|
const groupIds = groupStr.split(",").filter((g) => g.trim());
|
|
277
|
-
await checkAnchorState(mid, groupIds);
|
|
283
|
+
await checkAnchorState(mid, groupIds).catch((err) => ctx.logger.error(`检查主播${mid}失败:`, err.message));
|
|
278
284
|
}
|
|
279
285
|
}, finalConfig.pollInterval * 1e3);
|
|
280
286
|
ctx.logger.info(`bilirice插件已启动,监听主播数:${finalConfig.anchors.length},轮询间隔:${finalConfig.pollInterval}秒`);
|
|
281
287
|
});
|
|
282
288
|
ctx.command("bilirice <mid>", "手动检查指定主播的直播间状态").action(async ({ session }, mid) => {
|
|
283
289
|
if (!mid) return "请输入主播UID";
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
290
|
+
if (!finalConfig.bilibiliCookie) return "插件未配置B站Cookie,无法执行操作!";
|
|
291
|
+
try {
|
|
292
|
+
const groupIds = session.guildId ? [session.guildId] : [];
|
|
293
|
+
await initAnchorState(mid);
|
|
294
|
+
await checkAnchorState(mid, groupIds);
|
|
295
|
+
return `已检查主播${mid}的直播间状态(含完整统计数据)`;
|
|
296
|
+
} catch (err) {
|
|
297
|
+
return `检查失败:${err.message}`;
|
|
298
|
+
}
|
|
288
299
|
});
|
|
289
300
|
}
|
|
290
301
|
__name(apply, "apply");
|