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 +1 -1
- package/lib/index.js +14 -12
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
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 = "
|
|
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(
|
|
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
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
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 (
|
|
194
|
-
const parsed = Number(
|
|
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 =
|
|
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 && !
|
|
229
|
+
if (allTags.length === 0 && !cleanParams) return "请输入搜索标签。";
|
|
228
230
|
const queryParams = {
|
|
229
231
|
q: allTags.join(", "),
|
|
230
232
|
key: config.apiKey,
|