koishi-plugin-phimg2 1.0.5 → 1.0.6

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
@@ -1,5 +1,5 @@
1
1
  import { Context, Schema } from 'koishi';
2
- export declare const name = "phimg2";
2
+ export declare const name = "phimg";
3
3
  export declare const inject: string[];
4
4
  declare module 'koishi' {
5
5
  interface Tables {
package/lib/index.js CHANGED
@@ -27,7 +27,7 @@ __export(src_exports, {
27
27
  });
28
28
  module.exports = __toCommonJS(src_exports);
29
29
  var import_koishi = require("koishi");
30
- var name = "phimg2";
30
+ var name = "phimg";
31
31
  var inject = ["database", "http"];
32
32
  var translationTable = {
33
33
  ";": ";",
@@ -122,7 +122,7 @@ function apply(ctx, config) {
122
122
  } catch (error) {
123
123
  if (error.response?.status === 404) throw new Error("未找到匹配的图片");
124
124
  ctx.logger("phimg").warn(error);
125
- throw new Error(`${error.message}`);
125
+ throw new Error(`API 请求失败: ${error.message}`);
126
126
  }
127
127
  }, "makeRequest");
128
128
  const VIDEO_TYPES = ["webm", "mp4"];
@@ -179,19 +179,21 @@ function apply(ctx, config) {
179
179
  return '搜图未在本群开启,管理员请用 "搜图-c --on" 启动';
180
180
  }
181
181
  params = translateText(params || "");
182
+ const cleanParams = params.replace(/<[^>]+>/g, "").trim();
182
183
  let imageUrl;
183
- const quote = session.quote;
184
- if (quote) {
185
- const imgElement = import_koishi.h.select(quote.content, "image")[0] || import_koishi.h.select(quote.content, "img")[0];
186
- if (imgElement) {
187
- imageUrl = imgElement.attrs.url || imgElement.attrs.src;
188
- }
184
+ if (session.quote) {
185
+ const img = import_koishi.h.select(session.quote.content, "image")[0] || import_koishi.h.select(session.quote.content, "img")[0];
186
+ if (img) imageUrl = img.attrs.url || img.attrs.src;
187
+ }
188
+ if (!imageUrl) {
189
+ const img = import_koishi.h.select(session.content, "image")[0] || import_koishi.h.select(session.content, "img")[0];
190
+ if (img) imageUrl = img.attrs.url || img.attrs.src;
189
191
  }
190
192
  try {
191
193
  if (imageUrl) {
192
194
  let distance = 0.25;
193
- if (params) {
194
- const parsed = Number(params);
195
+ if (cleanParams) {
196
+ const parsed = Number(cleanParams);
195
197
  if (!isNaN(parsed)) {
196
198
  distance = parsed;
197
199
  } else {
@@ -220,11 +222,11 @@ id: ${img.id} | score: ${img.score}
220
222
  }
221
223
  return result;
222
224
  } else {
223
- const userTags = params ? params.split(",").map((t) => t.trim()).filter((t) => t) : [];
225
+ const userTags = cleanParams ? cleanParams.split(",").map((t) => t.trim()).filter((t) => t) : [];
224
226
  const globalTags = groupConfig.useGlobalTags ? config.defaultTags : [];
225
227
  const groupTags = groupConfig.customTags;
226
228
  const allTags = Array.from(/* @__PURE__ */ new Set([...groupTags, ...globalTags, ...userTags]));
227
- if (allTags.length === 0 && !params) return "请输入搜索标签。";
229
+ if (allTags.length === 0 && !cleanParams) return "请输入搜索标签。";
228
230
  const queryParams = {
229
231
  q: allTags.join(", "),
230
232
  key: config.apiKey,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-phimg2",
3
3
  "description": "Koishi 插件,让机器人通过Philomena API在使用Philomena搭建的图站上使用标签(tags)搜图或图搜图",
4
- "version": "1.0.5",
4
+ "version": "1.0.6",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [