koishi-plugin-aka-60s-api 0.0.4 → 0.0.5

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.
Files changed (2) hide show
  1. package/lib/index.js +50 -1
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -78,6 +78,27 @@ function apply(ctx, config) {
78
78
  }
79
79
  }
80
80
  __name(get60sNews, "get60sNews");
81
+ async function get60sNewsImage() {
82
+ try {
83
+ logInfo("60s API: 开始获取新闻图片");
84
+ const response = await ctx.http.get("https://192.168.50.55:4399/v2/60s", {
85
+ params: {
86
+ encoding: "image"
87
+ },
88
+ timeout: 3e4,
89
+ responseType: "arraybuffer"
90
+ });
91
+ const buffer = Buffer.from(response);
92
+ logInfo("60s API: 获取新闻图片成功", {
93
+ size: buffer.length
94
+ });
95
+ return buffer;
96
+ } catch (error) {
97
+ logError("60s API: 获取新闻图片失败", error);
98
+ throw error;
99
+ }
100
+ }
101
+ __name(get60sNewsImage, "get60sNewsImage");
81
102
  ctx.command("60s", "获取60秒新闻").action(async (argv) => {
82
103
  const userId = argv.session.userId;
83
104
  if (!checkCooldown(userId)) {
@@ -128,12 +149,40 @@ function apply(ctx, config) {
128
149
  return "获取新闻失败,请稍后重试";
129
150
  }
130
151
  });
152
+ ctx.command("新闻", "获取60秒新闻图片").action(async (argv) => {
153
+ const userId = argv.session.userId;
154
+ if (!checkCooldown(userId)) {
155
+ const now = Date.now();
156
+ const lastTime = cooldowns.get(userId) || 0;
157
+ const timeLeft = Math.ceil((lastTime + config.cooldownTime * 1e3 - now) / 1e3);
158
+ return `请等待 ${timeLeft} 秒后再试`;
159
+ }
160
+ try {
161
+ logInfo("60s API: 用户请求新闻图片", { userId });
162
+ await argv.session.send("正在获取60秒新闻图片,请稍候...");
163
+ const imageBuffer = await get60sNewsImage();
164
+ const imageMessage = import_koishi.h.image(imageBuffer, "image/png");
165
+ await argv.session.send(imageMessage);
166
+ logInfo("60s API: 成功发送新闻图片", {
167
+ size: imageBuffer.length,
168
+ userId
169
+ });
170
+ return "📰 60秒读懂世界新闻图片已发送";
171
+ } catch (error) {
172
+ logError("60s API: 处理新闻图片请求失败", {
173
+ error,
174
+ errorMessage: error?.message || "未知错误",
175
+ userId
176
+ });
177
+ return "获取新闻图片失败,请稍后重试";
178
+ }
179
+ });
131
180
  ctx.command("60s重置", "重置60秒新闻冷却时间").action(async (argv) => {
132
181
  const userId = argv.session.userId;
133
182
  const hadCooldown = cooldowns.has(userId);
134
183
  cooldowns.delete(userId);
135
184
  logInfo("60s API: 手动重置冷却时间", { userId, hadCooldown });
136
- return hadCooldown ? "已重置冷却时间,可以重新使用60s指令" : "当前没有冷却时间";
185
+ return hadCooldown ? "已重置冷却时间,可以重新使用新闻相关指令" : "当前没有冷却时间";
137
186
  });
138
187
  ctx.on("dispose", () => {
139
188
  cooldowns.clear();
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.0.4",
4
+ "version": "0.0.5",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [