koishi-plugin-phimg2 1.0.2 → 1.0.4
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 +14 -10
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -65,7 +65,8 @@ var Config = import_koishi.Schema.object({
|
|
|
65
65
|
enabledByDefault: import_koishi.Schema.boolean().description("新群聊默认启用搜图功能").default(true),
|
|
66
66
|
useGlobalTagsByDefault: import_koishi.Schema.boolean().description("新群聊默认启用全局标签").default(true),
|
|
67
67
|
proxy: import_koishi.Schema.string().description("代理服务器 (例如 http://127.0.0.1:7890)").default(""),
|
|
68
|
-
timeout: import_koishi.Schema.number().description("请求超时时间 (秒)").default(30)
|
|
68
|
+
timeout: import_koishi.Schema.number().description("请求超时时间 (秒)").default(30),
|
|
69
|
+
filterId: import_koishi.Schema.number().description("搜索使用的 Filter ID (例如 56027 为 Everything)").default(100073)
|
|
69
70
|
});
|
|
70
71
|
function apply(ctx, config) {
|
|
71
72
|
ctx.model.extend("phimg_config", {
|
|
@@ -106,7 +107,11 @@ function apply(ctx, config) {
|
|
|
106
107
|
"Accept": "application/json",
|
|
107
108
|
"User-Agent": "Phimg for Koishi"
|
|
108
109
|
},
|
|
109
|
-
timeout: config.timeout * 1e3
|
|
110
|
+
timeout: config.timeout * 1e3,
|
|
111
|
+
params: {
|
|
112
|
+
...params,
|
|
113
|
+
filter_id: config.filterId
|
|
114
|
+
}
|
|
110
115
|
};
|
|
111
116
|
if (config.proxy) {
|
|
112
117
|
try {
|
|
@@ -123,7 +128,7 @@ function apply(ctx, config) {
|
|
|
123
128
|
try {
|
|
124
129
|
let response;
|
|
125
130
|
if (method === "images") {
|
|
126
|
-
response = await import_axios.default.get(url,
|
|
131
|
+
response = await import_axios.default.get(url, axiosConfig);
|
|
127
132
|
} else {
|
|
128
133
|
const formData = new URLSearchParams();
|
|
129
134
|
for (const key in params) {
|
|
@@ -131,7 +136,7 @@ function apply(ctx, config) {
|
|
|
131
136
|
}
|
|
132
137
|
response = await import_axios.default.post(url, formData, axiosConfig);
|
|
133
138
|
}
|
|
134
|
-
if (response.data.
|
|
139
|
+
if (!response.data.images || response.data.images.length === 0) {
|
|
135
140
|
throw new Error("未找到匹配的图片");
|
|
136
141
|
}
|
|
137
142
|
return response.data;
|
|
@@ -173,7 +178,7 @@ function apply(ctx, config) {
|
|
|
173
178
|
提示:
|
|
174
179
|
图搜图使用方式为引用图片,默认匹配距离为0.25
|
|
175
180
|
所有参数及变量全部遵循呆站(Philomena系图站)搜索API规范`;
|
|
176
|
-
const configHelp = `用法:
|
|
181
|
+
const configHelp = `用法: 搜图-c [选项]
|
|
177
182
|
|
|
178
183
|
可选项:
|
|
179
184
|
--add [tags] 添加标签,多个标签用逗号分隔
|
|
@@ -183,10 +188,10 @@ function apply(ctx, config) {
|
|
|
183
188
|
--onglobal 启用全局标签
|
|
184
189
|
--offglobal 关闭全局标签
|
|
185
190
|
`;
|
|
186
|
-
ctx.command("搜图 [params
|
|
191
|
+
ctx.command("搜图 [...params]", "从图站搜索图片").option("tags", "--tags 获取当前群聊内置标签列表").option("status", "--status 获取当前群聊的搜图功能状态").option("pp", "--pp <per_page:number> 每页结果数量,默认为50", { fallback: 50 }).option("p", "--p <page:number> 页码,默认为1", { fallback: 1 }).option("sf", "--sf <sf:string> 排序字段,默认为score", { fallback: "score" }).option("sd", "--sd <sd:string> 排序方向,默认为desc", { fallback: "desc" }).option("i", "--i <index:number> 选择结果索引,默认为-1(即随机)", { fallback: -1 }).action(async ({ session, options }, ...paramsArray) => {
|
|
187
192
|
if (!session?.guildId) return "搜图仅限群聊使用。";
|
|
188
|
-
|
|
189
|
-
if (!params &&
|
|
193
|
+
let params = paramsArray.join(" ");
|
|
194
|
+
if (!params && !session.quote && !options.tags && !options.status) {
|
|
190
195
|
return searchHelp;
|
|
191
196
|
}
|
|
192
197
|
const groupId = session.guildId;
|
|
@@ -286,8 +291,7 @@ tags: ${queryParams.q}`;
|
|
|
286
291
|
const confirmOffGlobal = /* @__PURE__ */ new Set();
|
|
287
292
|
ctx.command("搜图-c", "配置搜图功能", { authority: 3 }).option("on", "--on 开启当前群聊的搜图功能").option("off", "--off 关闭当前群聊的搜图功能").option("onglobal", "--onglobal 启用全局标签").option("offglobal", "--offglobal 关闭全局标签").option("add", "--add <tags:string> 添加标签,多个标签用逗号分隔").option("rm", "--rm <tags:string> 删除标签,多个标签用逗号分隔").action(async ({ session, options }) => {
|
|
288
293
|
if (!session?.guildId) return "搜图配置仅限群聊使用。";
|
|
289
|
-
|
|
290
|
-
if (tokens.length <= 1) {
|
|
294
|
+
if (Object.keys(options).length === 0) {
|
|
291
295
|
return configHelp;
|
|
292
296
|
}
|
|
293
297
|
const groupId = session.guildId;
|