koishi-plugin-smmcat-gptimage2 0.0.1
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/chatActive.d.ts +10 -0
- package/lib/chatPassive.d.ts +17 -0
- package/lib/index.d.ts +10 -0
- package/lib/index.js +121 -0
- package/package.json +20 -0
- package/readme.md +5 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Context } from "koishi";
|
|
2
|
+
import { Config } from ".";
|
|
3
|
+
/** 内容发送模块 */
|
|
4
|
+
export declare const ChatOfActive: {
|
|
5
|
+
config: Config;
|
|
6
|
+
ctx: Context;
|
|
7
|
+
init(config: Config, ctx: Context): Promise<void>;
|
|
8
|
+
/** 发送消息 */
|
|
9
|
+
send(guildId: string, content: string): Promise<void>;
|
|
10
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Context, Session } from "koishi";
|
|
2
|
+
import { Config } from ".";
|
|
3
|
+
/** 内容发送模块 */
|
|
4
|
+
export declare const ChatOfPassive: {
|
|
5
|
+
config: Config;
|
|
6
|
+
ctx: Context;
|
|
7
|
+
chache: {};
|
|
8
|
+
messageIdTemp: {};
|
|
9
|
+
init(config: Config, ctx: Context): Promise<void>;
|
|
10
|
+
/** 发送消息 */
|
|
11
|
+
send(session: Session, content: string): Promise<void>;
|
|
12
|
+
isUseMd(session: Session): boolean;
|
|
13
|
+
/** 清除一条 msgid 记录 */
|
|
14
|
+
clearChache(): void;
|
|
15
|
+
/** 清除一条 messageId 缓存 */
|
|
16
|
+
clearMessageIdTemp(): void;
|
|
17
|
+
};
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Context, Schema } from 'koishi';
|
|
2
|
+
export declare const name = "smmcat-gptimage2";
|
|
3
|
+
export interface Config {
|
|
4
|
+
deBug: boolean;
|
|
5
|
+
useMd: boolean;
|
|
6
|
+
token: string;
|
|
7
|
+
onlyUse: string[];
|
|
8
|
+
}
|
|
9
|
+
export declare const Config: Schema<Config>;
|
|
10
|
+
export declare function apply(ctx: Context, config: Config): void;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name2 in all)
|
|
8
|
+
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
Config: () => Config,
|
|
24
|
+
apply: () => apply,
|
|
25
|
+
name: () => name
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(src_exports);
|
|
28
|
+
var import_koishi = require("koishi");
|
|
29
|
+
var name = "smmcat-gptimage2";
|
|
30
|
+
var Config = import_koishi.Schema.object({
|
|
31
|
+
deBug: import_koishi.Schema.boolean().default(false).description("日志查看更多信息"),
|
|
32
|
+
useMd: import_koishi.Schema.boolean().default(false).description("使用qqbot的md发送(未实装)"),
|
|
33
|
+
token: import_koishi.Schema.string().default("").description("[万象灵算](https://wxls.bbroot.com/sign-up?aff=8FJR) 提供的 API 密钥"),
|
|
34
|
+
onlyUse: import_koishi.Schema.array(String).role("table").default([]).description("仅指定userId用户可用(为空则所有)")
|
|
35
|
+
});
|
|
36
|
+
function apply(ctx, config) {
|
|
37
|
+
function sleep(ms = 1e3) {
|
|
38
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
39
|
+
}
|
|
40
|
+
__name(sleep, "sleep");
|
|
41
|
+
const ImgGpt = {
|
|
42
|
+
userCache: {},
|
|
43
|
+
async startGetImage(session, content, img = null, fn) {
|
|
44
|
+
const { userId } = session;
|
|
45
|
+
if (!ImgGpt.userCache[userId]) {
|
|
46
|
+
ImgGpt.userCache[userId] = {
|
|
47
|
+
progress: null,
|
|
48
|
+
lastResult: null
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
const body = {
|
|
53
|
+
model: "gpt-image-2",
|
|
54
|
+
prompt: content,
|
|
55
|
+
aspect_ratio: "16:9",
|
|
56
|
+
response_format: "url",
|
|
57
|
+
n: 1,
|
|
58
|
+
images: img || void 0
|
|
59
|
+
};
|
|
60
|
+
config.deBug && console.log(body);
|
|
61
|
+
const respose = await ctx.http.post("https://wxls.bbroot.com/v1/images/generations", body, {
|
|
62
|
+
headers: { "Authorization": config.token }
|
|
63
|
+
});
|
|
64
|
+
let time = 0;
|
|
65
|
+
let progress = 0;
|
|
66
|
+
let url = null;
|
|
67
|
+
let prompt = null;
|
|
68
|
+
while (true) {
|
|
69
|
+
const data = await ctx.http.post(`https://tools.mgtv100.com/external/v1/pear/imageTaskShow`, { task_id: respose.id });
|
|
70
|
+
config.deBug && console.log(data);
|
|
71
|
+
progress = data.data?.progress || 0;
|
|
72
|
+
prompt = data.data?.input?.prompt;
|
|
73
|
+
if (data.data?.api_file_url) {
|
|
74
|
+
if (Array.isArray(data.data?.api_file_url)) {
|
|
75
|
+
url = data.data?.api_file_url[0];
|
|
76
|
+
} else {
|
|
77
|
+
url = data.data?.api_file_url;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (progress == 100) {
|
|
81
|
+
ImgGpt.userCache[userId].progress = null;
|
|
82
|
+
ImgGpt.userCache[userId].lastResult = url;
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
if (time % 6 == 0) {
|
|
86
|
+
fn && await fn({ progress, url });
|
|
87
|
+
}
|
|
88
|
+
await sleep(1e4);
|
|
89
|
+
time++;
|
|
90
|
+
}
|
|
91
|
+
return { progress, url, prompt };
|
|
92
|
+
} catch (error) {
|
|
93
|
+
console.log(error.message);
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
ctx.command("获取标识").action(async ({ session }) => {
|
|
99
|
+
return session.userId;
|
|
100
|
+
});
|
|
101
|
+
ctx.command("生图 <prompt:text>").action(async ({ session }, prompt) => {
|
|
102
|
+
if (!config.onlyUse.includes(session.userId)) return `该功能暂不对外支持`;
|
|
103
|
+
const text = import_koishi.h.select(prompt, "text")[0]?.attrs.content || null;
|
|
104
|
+
const img = import_koishi.h.select(prompt, "img").map((item) => item.attrs.src) || null;
|
|
105
|
+
if (!text) return `请携带需求发送,例如 /生图 生成一只猫娘`;
|
|
106
|
+
await session.send("稍等,正在给你生...");
|
|
107
|
+
const result = await ImgGpt.startGetImage(session, text, img, async (val) => {
|
|
108
|
+
await session.send(`当前进度:${val.progress}%`);
|
|
109
|
+
});
|
|
110
|
+
console.log(result);
|
|
111
|
+
if (!result) return `生成失败!`;
|
|
112
|
+
await session.send(import_koishi.h.image(result.url) + result.prompt);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
__name(apply, "apply");
|
|
116
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
117
|
+
0 && (module.exports = {
|
|
118
|
+
Config,
|
|
119
|
+
apply,
|
|
120
|
+
name
|
|
121
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "koishi-plugin-smmcat-gptimage2",
|
|
3
|
+
"description": "简单去使用云接口 GPT-Image2",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"typings": "lib/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"lib",
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"keywords": [
|
|
13
|
+
"chatbot",
|
|
14
|
+
"koishi",
|
|
15
|
+
"plugin"
|
|
16
|
+
],
|
|
17
|
+
"peerDependencies": {
|
|
18
|
+
"koishi": "^4.18.7"
|
|
19
|
+
}
|
|
20
|
+
}
|