koishi-plugin-aka-60s-api 0.1.9 → 0.2.0
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 +1 -0
- package/lib/index.js +10 -7
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -31,6 +31,7 @@ var name = "aka-60s-api";
|
|
|
31
31
|
var inject = ["database"];
|
|
32
32
|
var Config = import_koishi.Schema.intersect([
|
|
33
33
|
import_koishi.Schema.object({
|
|
34
|
+
apiBaseUrl: import_koishi.Schema.string().default("http://172.0.0.1:4399").description("60s 服务 URL(不含 /v2 路径)"),
|
|
34
35
|
cooldownTime: import_koishi.Schema.number().default(30).min(5).max(300).description("冷却时间(秒)"),
|
|
35
36
|
enableLog: import_koishi.Schema.boolean().default(true).description("启用日志记录"),
|
|
36
37
|
scheduleWhitelist: import_koishi.Schema.array(String).default([]).description("定时发送群组白名单频道ID列表(为空=不发送)")
|
|
@@ -61,6 +62,8 @@ var Config = import_koishi.Schema.intersect([
|
|
|
61
62
|
]);
|
|
62
63
|
function apply(ctx, config) {
|
|
63
64
|
const logger = ctx.logger("aka-60s-api");
|
|
65
|
+
const normalizedApiBaseUrl = (config.apiBaseUrl || "http://172.0.0.1:4399").replace(/\/$/, "");
|
|
66
|
+
const buildApiUrl = /* @__PURE__ */ __name((path) => `${normalizedApiBaseUrl}${path}`, "buildApiUrl");
|
|
64
67
|
const cooldowns = /* @__PURE__ */ new Map();
|
|
65
68
|
let scheduleInterval = null;
|
|
66
69
|
let aiNewsScheduleInterval = null;
|
|
@@ -117,7 +120,7 @@ function apply(ctx, config) {
|
|
|
117
120
|
async function get60sNewsImage() {
|
|
118
121
|
try {
|
|
119
122
|
logInfo("60s API: 开始获取新闻图片");
|
|
120
|
-
const response = await ctx.http.get("
|
|
123
|
+
const response = await ctx.http.get(buildApiUrl("/v2/60s"), {
|
|
121
124
|
params: {
|
|
122
125
|
encoding: "image"
|
|
123
126
|
},
|
|
@@ -138,7 +141,7 @@ function apply(ctx, config) {
|
|
|
138
141
|
async function getTodayInHistory() {
|
|
139
142
|
try {
|
|
140
143
|
logInfo("60s API: 开始获取历史上的今天");
|
|
141
|
-
const response = await ctx.http.get("
|
|
144
|
+
const response = await ctx.http.get(buildApiUrl("/v2/today-in-history"), {
|
|
142
145
|
params: {
|
|
143
146
|
encoding: "json"
|
|
144
147
|
},
|
|
@@ -159,7 +162,7 @@ function apply(ctx, config) {
|
|
|
159
162
|
async function getZhihuTrends() {
|
|
160
163
|
try {
|
|
161
164
|
logInfo("60s API: 开始获取知乎话题榜");
|
|
162
|
-
const response = await ctx.http.get("
|
|
165
|
+
const response = await ctx.http.get(buildApiUrl("/v2/zhihu"), {
|
|
163
166
|
params: {
|
|
164
167
|
encoding: "json"
|
|
165
168
|
},
|
|
@@ -180,7 +183,7 @@ function apply(ctx, config) {
|
|
|
180
183
|
async function getAiNews(params) {
|
|
181
184
|
try {
|
|
182
185
|
logInfo("60s API: 开始获取AI快报", params);
|
|
183
|
-
const response = await ctx.http.get("
|
|
186
|
+
const response = await ctx.http.get(buildApiUrl("/v2/ai-news"), {
|
|
184
187
|
params: {
|
|
185
188
|
date: params.date,
|
|
186
189
|
all: params.all,
|
|
@@ -199,7 +202,7 @@ function apply(ctx, config) {
|
|
|
199
202
|
async function getMoyuDaily(encoding = "text") {
|
|
200
203
|
try {
|
|
201
204
|
logInfo("60s API: 开始获取摸鱼日报", { encoding });
|
|
202
|
-
const response = await ctx.http.get("
|
|
205
|
+
const response = await ctx.http.get(buildApiUrl("/v2/moyu"), {
|
|
203
206
|
params: {
|
|
204
207
|
encoding
|
|
205
208
|
},
|
|
@@ -216,7 +219,7 @@ function apply(ctx, config) {
|
|
|
216
219
|
async function getGoldPrice(encoding = "text") {
|
|
217
220
|
try {
|
|
218
221
|
logInfo("60s API: 开始获取今日金价", { encoding });
|
|
219
|
-
const response = await ctx.http.get("
|
|
222
|
+
const response = await ctx.http.get(buildApiUrl("/v2/gold-price"), {
|
|
220
223
|
params: {
|
|
221
224
|
encoding
|
|
222
225
|
},
|
|
@@ -233,7 +236,7 @@ function apply(ctx, config) {
|
|
|
233
236
|
async function getFuelPrice(params) {
|
|
234
237
|
try {
|
|
235
238
|
logInfo("60s API: 开始获取今日油价", params);
|
|
236
|
-
const response = await ctx.http.get("
|
|
239
|
+
const response = await ctx.http.get(buildApiUrl("/v2/fuel-price"), {
|
|
237
240
|
params: {
|
|
238
241
|
region: params.region,
|
|
239
242
|
encoding: params.encoding || "text"
|