koishi-plugin-aka-60s-api 0.2.14 → 0.2.15
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 +25 -0
- package/lib/index.js +40 -36
- package/package.json +1 -1
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Context, Schema } from 'koishi';
|
|
2
|
+
export declare const name = "aka-60s-api";
|
|
3
|
+
export declare const inject: string[];
|
|
4
|
+
export interface Config {
|
|
5
|
+
apiBaseUrl: string;
|
|
6
|
+
cooldownTime: number;
|
|
7
|
+
enableLog: boolean;
|
|
8
|
+
scheduleWhitelist: string[];
|
|
9
|
+
scheduleCooldown: number;
|
|
10
|
+
enableSchedule: boolean;
|
|
11
|
+
scheduleTime: string;
|
|
12
|
+
useForward: boolean;
|
|
13
|
+
enableAiNewsSchedule: boolean;
|
|
14
|
+
aiNewsScheduleTime: string;
|
|
15
|
+
aiUseForward: boolean;
|
|
16
|
+
enableMoyuSchedule: boolean;
|
|
17
|
+
moyuScheduleTime: string;
|
|
18
|
+
enableGoldSchedule: boolean;
|
|
19
|
+
goldScheduleTime: string;
|
|
20
|
+
enableFuelSchedule: boolean;
|
|
21
|
+
fuelScheduleTime: string;
|
|
22
|
+
fuelDefaultRegion: string;
|
|
23
|
+
}
|
|
24
|
+
export declare const Config: Schema<Config>;
|
|
25
|
+
export declare function apply(ctx: Context, config: Config): void;
|
package/lib/index.js
CHANGED
|
@@ -1,39 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Config = exports.inject = exports.name = void 0;
|
|
4
|
+
exports.apply = apply;
|
|
5
|
+
const koishi_1 = require("koishi");
|
|
6
|
+
exports.name = 'aka-60s-api';
|
|
7
|
+
exports.inject = ['database'];
|
|
8
|
+
exports.Config = koishi_1.Schema.intersect([
|
|
9
|
+
koishi_1.Schema.object({
|
|
10
|
+
apiBaseUrl: koishi_1.Schema.string().default('http://172.0.0.1:4399').description('60s 服务 URL(不含 /v2 路径)'),
|
|
11
|
+
cooldownTime: koishi_1.Schema.number().default(30).min(5).max(300).description('命令冷却时间(秒),用户手动触发命令的间隔限制'),
|
|
12
|
+
scheduleCooldown: koishi_1.Schema.number().default(86400).min(0).description('定时任务防重发冷却时间(秒),0表示不限制。默认86400秒=24小时'),
|
|
13
|
+
enableLog: koishi_1.Schema.boolean().default(true).description('启用日志记录'),
|
|
14
|
+
scheduleWhitelist: koishi_1.Schema.array(String).default([]).description('定时发送群组白名单频道ID列表(格式: platform:channelId,如 onebot:123456)')
|
|
11
15
|
}).description('基础设置'),
|
|
12
|
-
Schema.object({
|
|
13
|
-
enableSchedule: Schema.boolean().default(false).description('启用定时发送新闻'),
|
|
14
|
-
scheduleTime: Schema.string().default('08:00').description('定时发送时间 (格式: HH:MM 或 HH:MM / Nd,如 08:00 或 08:00 / 1d,表示每天或每N天的固定时间)'),
|
|
15
|
-
useForward: Schema.boolean().default(false).description('是否使用合并转发(仅QQ平台效果最佳)')
|
|
16
|
+
koishi_1.Schema.object({
|
|
17
|
+
enableSchedule: koishi_1.Schema.boolean().default(false).description('启用定时发送新闻'),
|
|
18
|
+
scheduleTime: koishi_1.Schema.string().default('08:00').description('定时发送时间 (格式: HH:MM 或 HH:MM / Nd,如 08:00 或 08:00 / 1d,表示每天或每N天的固定时间)'),
|
|
19
|
+
useForward: koishi_1.Schema.boolean().default(false).description('是否使用合并转发(仅QQ平台效果最佳)')
|
|
16
20
|
}).description('每日新闻'),
|
|
17
|
-
Schema.object({
|
|
18
|
-
enableAiNewsSchedule: Schema.boolean().default(false).description('启用AI快报定时发送(仅当天)'),
|
|
19
|
-
aiNewsScheduleTime: Schema.string().default('22:00').description('AI快报定时发送时间 (格式: HH:MM 或 HH:MM / Nd,如 22:00 或 22:00 / 1d)'),
|
|
20
|
-
aiUseForward: Schema.boolean().default(false).description('AI快报是否使用合并转发(仅QQ平台效果最佳)')
|
|
21
|
+
koishi_1.Schema.object({
|
|
22
|
+
enableAiNewsSchedule: koishi_1.Schema.boolean().default(false).description('启用AI快报定时发送(仅当天)'),
|
|
23
|
+
aiNewsScheduleTime: koishi_1.Schema.string().default('22:00').description('AI快报定时发送时间 (格式: HH:MM 或 HH:MM / Nd,如 22:00 或 22:00 / 1d)'),
|
|
24
|
+
aiUseForward: koishi_1.Schema.boolean().default(false).description('AI快报是否使用合并转发(仅QQ平台效果最佳)')
|
|
21
25
|
}).description('AI快报'),
|
|
22
|
-
Schema.object({
|
|
23
|
-
enableMoyuSchedule: Schema.boolean().default(false).description('启用摸鱼日报定时发送'),
|
|
24
|
-
moyuScheduleTime: Schema.string().default('10:00').description('摸鱼日报定时发送时间 (格式: HH:MM 或 HH:MM / Nd,如 10:00 或 10:00 / 1d)'),
|
|
26
|
+
koishi_1.Schema.object({
|
|
27
|
+
enableMoyuSchedule: koishi_1.Schema.boolean().default(false).description('启用摸鱼日报定时发送'),
|
|
28
|
+
moyuScheduleTime: koishi_1.Schema.string().default('10:00').description('摸鱼日报定时发送时间 (格式: HH:MM 或 HH:MM / Nd,如 10:00 或 10:00 / 1d)'),
|
|
25
29
|
}).description('摸鱼日报'),
|
|
26
|
-
Schema.object({
|
|
27
|
-
enableGoldSchedule: Schema.boolean().default(false).description('启用今日金价定时发送'),
|
|
28
|
-
goldScheduleTime: Schema.string().default('09:00').description('今日金价定时发送时间 (格式: HH:MM 或 HH:MM / Nd,如 09:00 或 09:00 / 1d)'),
|
|
30
|
+
koishi_1.Schema.object({
|
|
31
|
+
enableGoldSchedule: koishi_1.Schema.boolean().default(false).description('启用今日金价定时发送'),
|
|
32
|
+
goldScheduleTime: koishi_1.Schema.string().default('09:00').description('今日金价定时发送时间 (格式: HH:MM 或 HH:MM / Nd,如 09:00 或 09:00 / 1d)'),
|
|
29
33
|
}).description('今日金价'),
|
|
30
|
-
Schema.object({
|
|
31
|
-
enableFuelSchedule: Schema.boolean().default(false).description('启用今日油价定时发送'),
|
|
32
|
-
fuelScheduleTime: Schema.string().default('09:30').description('今日油价定时发送时间 (格式: HH:MM 或 HH:MM / Nd,如 09:30 或 09:30 / 1d)'),
|
|
33
|
-
fuelDefaultRegion: Schema.string().default('上海').description('今日油价默认地区')
|
|
34
|
+
koishi_1.Schema.object({
|
|
35
|
+
enableFuelSchedule: koishi_1.Schema.boolean().default(false).description('启用今日油价定时发送'),
|
|
36
|
+
fuelScheduleTime: koishi_1.Schema.string().default('09:30').description('今日油价定时发送时间 (格式: HH:MM 或 HH:MM / Nd,如 09:30 或 09:30 / 1d)'),
|
|
37
|
+
fuelDefaultRegion: koishi_1.Schema.string().default('上海').description('今日油价默认地区')
|
|
34
38
|
}).description('今日油价')
|
|
35
39
|
]);
|
|
36
|
-
|
|
40
|
+
function apply(ctx, config) {
|
|
37
41
|
const logger = ctx.logger('aka-60s-api');
|
|
38
42
|
const normalizedApiBaseUrl = (config.apiBaseUrl || 'http://172.0.0.1:4399').replace(/\/$/, '');
|
|
39
43
|
const buildApiUrl = (path) => `${normalizedApiBaseUrl}${path}`;
|
|
@@ -322,7 +326,7 @@ export function apply(ctx, config) {
|
|
|
322
326
|
}
|
|
323
327
|
try {
|
|
324
328
|
const imageBuffer = await get60sNewsImage();
|
|
325
|
-
const imageMessage = h.image(imageBuffer, 'image/png');
|
|
329
|
+
const imageMessage = koishi_1.h.image(imageBuffer, 'image/png');
|
|
326
330
|
for (const channelId of targetChannels) {
|
|
327
331
|
try {
|
|
328
332
|
await ctx.broadcast([channelId], imageMessage);
|
|
@@ -399,7 +403,7 @@ export function apply(ctx, config) {
|
|
|
399
403
|
const message = formatAiNewsText(response.data);
|
|
400
404
|
for (const channelId of targetChannels) {
|
|
401
405
|
try {
|
|
402
|
-
const output = config.aiUseForward ? h('figure', {}, [message]) : message;
|
|
406
|
+
const output = config.aiUseForward ? (0, koishi_1.h)('figure', {}, [message]) : message;
|
|
403
407
|
await ctx.broadcast([channelId], output);
|
|
404
408
|
logInfo('60s API: 定时发送AI快报成功', { channelId });
|
|
405
409
|
}
|
|
@@ -929,7 +933,7 @@ export function apply(ctx, config) {
|
|
|
929
933
|
// 获取新闻图片
|
|
930
934
|
const imageBuffer = await get60sNewsImage();
|
|
931
935
|
// 发送图片
|
|
932
|
-
const imageMessage = h.image(imageBuffer, 'image/png');
|
|
936
|
+
const imageMessage = koishi_1.h.image(imageBuffer, 'image/png');
|
|
933
937
|
await argv.session.send(imageMessage);
|
|
934
938
|
logInfo('60s API: 成功发送新闻图片', {
|
|
935
939
|
size: imageBuffer.length,
|
|
@@ -986,7 +990,7 @@ export function apply(ctx, config) {
|
|
|
986
990
|
return `${index + 1}. ${typeIcon} ${item.year}年 - ${item.title}\n${item.description}`;
|
|
987
991
|
})
|
|
988
992
|
];
|
|
989
|
-
const forwardMessage = h("figure", {}, forwardElements);
|
|
993
|
+
const forwardMessage = (0, koishi_1.h)("figure", {}, forwardElements);
|
|
990
994
|
await argv.session.send(forwardMessage);
|
|
991
995
|
}
|
|
992
996
|
else {
|
|
@@ -1053,7 +1057,7 @@ export function apply(ctx, config) {
|
|
|
1053
1057
|
return `${index + 1}. ${topic.title}\n${topic.detail}\n🔗 ${topic.link}`;
|
|
1054
1058
|
})
|
|
1055
1059
|
];
|
|
1056
|
-
const forwardMessage = h("figure", {}, forwardElements);
|
|
1060
|
+
const forwardMessage = (0, koishi_1.h)("figure", {}, forwardElements);
|
|
1057
1061
|
await argv.session.send(forwardMessage);
|
|
1058
1062
|
}
|
|
1059
1063
|
else {
|
|
@@ -1118,7 +1122,7 @@ export function apply(ctx, config) {
|
|
|
1118
1122
|
}
|
|
1119
1123
|
const message = formatAiNewsText(data);
|
|
1120
1124
|
if (config.aiUseForward && argv.session.platform === 'onebot') {
|
|
1121
|
-
await argv.session.send(h('figure', {}, [message]));
|
|
1125
|
+
await argv.session.send((0, koishi_1.h)('figure', {}, [message]));
|
|
1122
1126
|
return;
|
|
1123
1127
|
}
|
|
1124
1128
|
await argv.session.send(message);
|
|
@@ -1142,7 +1146,7 @@ export function apply(ctx, config) {
|
|
|
1142
1146
|
// 默认文本格式
|
|
1143
1147
|
const message = formatAiNewsText(response.data);
|
|
1144
1148
|
if (config.aiUseForward && argv.session.platform === 'onebot') {
|
|
1145
|
-
await argv.session.send(h('figure', {}, [message]));
|
|
1149
|
+
await argv.session.send((0, koishi_1.h)('figure', {}, [message]));
|
|
1146
1150
|
}
|
|
1147
1151
|
else {
|
|
1148
1152
|
await argv.session.send(message);
|