koishi-plugin-aka-60s-api 0.1.8 → 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 CHANGED
@@ -2,6 +2,7 @@ import { Context, Schema } from 'koishi';
2
2
  export declare const name = "aka-60s-api";
3
3
  export declare const inject: string[];
4
4
  export interface Config {
5
+ apiBaseUrl: string;
5
6
  cooldownTime: number;
6
7
  enableLog: boolean;
7
8
  scheduleWhitelist: string[];
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("http://192.168.50.55:4399/v2/60s", {
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("http://192.168.50.55:4399/v2/today-in-history", {
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("http://192.168.50.55:4399/v2/zhihu", {
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("http://192.168.50.55:4399/v2/ai-news", {
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("http://192.168.50.55:4399/v2/moyu", {
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("http://192.168.50.55:4399/v2/gold-price", {
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("http://192.168.50.55:4399/v2/fuel-price", {
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"
@@ -268,42 +271,29 @@ function apply(ctx, config) {
268
271
  }
269
272
  __name(sendNewsToChannels, "sendNewsToChannels");
270
273
  function formatAiNewsText(data) {
271
- const formatOne = /* @__PURE__ */ __name((item) => {
272
- const header = `🤖 ${item.date} AI资讯快报`;
273
- const lines = item.news.map((newsItem, index) => {
274
- const source = newsItem.source ? `(${newsItem.source})` : "";
275
- return `${index + 1}. ${newsItem.title}${source}
276
- ${newsItem.detail}
277
- 🔗 ${newsItem.link}`;
278
- });
279
- return [header, ...lines].join("\n\n");
280
- }, "formatOne");
281
- if (Array.isArray(data)) {
282
- return data.map(formatOne).join("\n\n");
283
- }
284
- return formatOne(data);
274
+ const items = normalizeAiNewsData(data).flatMap((item) => item.news);
275
+ return items.map((newsItem, index) => `${index + 1}. ${newsItem.title}
276
+ ${newsItem.link}`).join("\n\n");
285
277
  }
286
278
  __name(formatAiNewsText, "formatAiNewsText");
287
- function formatAiNewsSummary(data) {
288
- const summaryLength = 80;
289
- const formatOne = /* @__PURE__ */ __name((item) => {
290
- const header = `🤖 ${item.date} AI资讯快报(摘要)`;
291
- const lines = item.news.map((newsItem, index) => {
292
- const source = newsItem.source ? `(${newsItem.source})` : "";
293
- const detail = (newsItem.detail || "").replace(/\s+/g, " ").trim();
294
- const shortDetail = detail.length > summaryLength ? `${detail.slice(0, summaryLength)}...` : detail;
295
- return `${index + 1}. ${newsItem.title}${source}
296
- ${shortDetail}
297
- 🔗 ${newsItem.link}`;
298
- });
299
- return [header, ...lines].join("\n\n");
300
- }, "formatOne");
301
- if (Array.isArray(data)) {
302
- return data.map(formatOne).join("\n\n");
303
- }
304
- return formatOne(data);
279
+ function formatAiNewsMarkdown(data) {
280
+ const items = normalizeAiNewsData(data).flatMap((item) => item.news);
281
+ return items.map((newsItem) => `- [${newsItem.title}](${newsItem.link})`).join("\n");
282
+ }
283
+ __name(formatAiNewsMarkdown, "formatAiNewsMarkdown");
284
+ function toTitleLinkData(data) {
285
+ return normalizeAiNewsData(data).map((item) => ({
286
+ date: item.date,
287
+ news: item.news.map((newsItem) => ({
288
+ title: newsItem.title,
289
+ detail: "",
290
+ link: newsItem.link,
291
+ source: "",
292
+ date: newsItem.date
293
+ }))
294
+ }));
305
295
  }
306
- __name(formatAiNewsSummary, "formatAiNewsSummary");
296
+ __name(toTitleLinkData, "toTitleLinkData");
307
297
  function formatDate(date) {
308
298
  const year = date.getFullYear();
309
299
  const month = `${date.getMonth() + 1}`.padStart(2, "0");
@@ -790,7 +780,7 @@ ${shortDetail}
790
780
  return "获取知乎话题榜失败,请稍后重试";
791
781
  }
792
782
  });
793
- ctx.command("AI快报 [date]", "获取AI资讯快报").option("date", "-d <date> 指定日期 (格式: YYYY-MM-DD)").option("all", "-a 获取所有日期").option("encoding", "-e <encoding> 编码方式 text/json/markdown/summary").action(async (argv, date) => {
783
+ ctx.command("AI快报 [date]", "获取AI资讯快报").option("date", "-d <date> 指定日期 (格式: YYYY-MM-DD)").option("all", "-a 获取所有日期").option("encoding", "-e <encoding> 编码方式 text/json/markdown").action(async (argv, date) => {
794
784
  const userId = argv.session.userId;
795
785
  if (!checkCooldown(userId)) {
796
786
  const now = Date.now();
@@ -807,27 +797,20 @@ ${shortDetail}
807
797
  const dates = getRecentAiNewsDates();
808
798
  const data = await fetchAiNewsByDates(dates);
809
799
  if (!data.length) return "未获取到近两天的AI快报数据";
810
- if (encoding === "summary") {
811
- return await argv.session.send(formatAiNewsSummary(data));
812
- }
813
800
  if (encoding === "json") {
814
- return await argv.session.send(JSON.stringify(data, null, 2));
801
+ await argv.session.send(JSON.stringify(toTitleLinkData(data), null, 2));
802
+ return;
815
803
  }
816
804
  if (encoding === "markdown") {
817
- const markdownResponses = await Promise.all(
818
- dates.map((item) => getAiNews({ date: item, encoding: "markdown" }))
819
- );
820
- return await argv.session.send(markdownResponses.filter(Boolean).join("\n\n"));
805
+ await argv.session.send(formatAiNewsMarkdown(data));
806
+ return;
821
807
  }
822
808
  const message2 = formatAiNewsText(data);
823
809
  if (config.aiUseForward && argv.session.platform === "onebot") {
824
- return await argv.session.send((0, import_koishi.h)("figure", {}, [message2]));
810
+ await argv.session.send((0, import_koishi.h)("figure", {}, [message2]));
811
+ return;
825
812
  }
826
- return await argv.session.send(message2);
827
- }
828
- if (encoding === "markdown") {
829
- const response2 = await getAiNews({ date: targetDate, all, encoding: "markdown" });
830
- await argv.session.send(response2);
813
+ await argv.session.send(message2);
831
814
  return;
832
815
  }
833
816
  if (encoding === "json") {
@@ -836,22 +819,16 @@ ${shortDetail}
836
819
  logError("60s API: AI快报返回错误", { code: response2.code, message: response2.message });
837
820
  return `获取AI快报失败: ${response2.message || "未知错误"}`;
838
821
  }
839
- await argv.session.send(JSON.stringify(response2.data, null, 2));
822
+ await argv.session.send(JSON.stringify(toTitleLinkData(response2.data), null, 2));
840
823
  return;
841
824
  }
842
- if (encoding === "summary") {
825
+ if (encoding === "markdown") {
843
826
  const response2 = await getAiNews({ date: targetDate, all, encoding: "json" });
844
827
  if (response2.code !== 200 || !response2.data) {
845
828
  logError("60s API: AI快报返回错误", { code: response2.code, message: response2.message });
846
829
  return `获取AI快报失败: ${response2.message || "未知错误"}`;
847
830
  }
848
- const message2 = formatAiNewsSummary(response2.data);
849
- if (config.aiUseForward && argv.session.platform === "onebot") {
850
- const forwardMessage = (0, import_koishi.h)("figure", {}, [message2]);
851
- await argv.session.send(forwardMessage);
852
- } else {
853
- await argv.session.send(message2);
854
- }
831
+ await argv.session.send(formatAiNewsMarkdown(response2.data));
855
832
  return;
856
833
  }
857
834
  const response = await getAiNews({ date: targetDate, all, encoding: "json" });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-aka-60s-api",
3
3
  "description": "调用60s API转发信息的工具 - 个人用",
4
- "version": "0.1.8",
4
+ "version": "0.2.0",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [