koishi-plugin-smmcat-gptimage2 0.0.2 → 0.0.3

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
@@ -5,6 +5,8 @@ export interface Config {
5
5
  useMd: boolean;
6
6
  token: string;
7
7
  onlyUse: string[];
8
+ timeoutTime: number;
9
+ openNotice: boolean;
8
10
  }
9
11
  export declare const Config: Schema<Config>;
10
12
  export declare function apply(ctx: Context, config: Config): void;
package/lib/index.js CHANGED
@@ -31,7 +31,9 @@ var Config = import_koishi.Schema.object({
31
31
  deBug: import_koishi.Schema.boolean().default(false).description("日志查看更多信息"),
32
32
  useMd: import_koishi.Schema.boolean().default(false).description("使用qqbot的md发送(未实装)"),
33
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用户可用(为空则所有)")
34
+ onlyUse: import_koishi.Schema.array(String).role("table").default([]).description("仅指定userId用户可用(为空则所有)"),
35
+ timeoutTime: import_koishi.Schema.number().default(5).description("请求生图超时时间。(单位/分钟)"),
36
+ openNotice: import_koishi.Schema.boolean().default(true).description("开启进度播报(每隔一分钟,播报一次进度)")
35
37
  });
36
38
  function apply(ctx, config) {
37
39
  function sleep(ms = 1e3) {
@@ -45,7 +47,9 @@ function apply(ctx, config) {
45
47
  if (!ImgGpt.userCache[userId]) {
46
48
  ImgGpt.userCache[userId] = {
47
49
  progress: null,
48
- lastResult: null
50
+ lastResult: null,
51
+ status: "未启动",
52
+ prompt: ""
49
53
  };
50
54
  }
51
55
  try {
@@ -65,11 +69,13 @@ function apply(ctx, config) {
65
69
  let progress = 0;
66
70
  let url = null;
67
71
  let prompt = null;
68
- while (true) {
72
+ let status = null;
73
+ while (time < 60 * config.timeoutTime / 5) {
69
74
  const data = await ctx.http.post(`https://easy-tools.mgtv100.com/external/v1/pear/imageTaskShow`, { task_id: respose.id });
70
75
  config.deBug && console.log(data);
71
76
  progress = data.data?.progress || 0;
72
77
  prompt = data.data?.input?.prompt;
78
+ status = data.data?.status;
73
79
  if (data.data?.api_file_url) {
74
80
  if (Array.isArray(data.data?.api_file_url)) {
75
81
  url = data.data?.api_file_url[0];
@@ -80,15 +86,22 @@ function apply(ctx, config) {
80
86
  if (progress == 100) {
81
87
  ImgGpt.userCache[userId].progress = null;
82
88
  ImgGpt.userCache[userId].lastResult = url;
89
+ ImgGpt.userCache[userId].status = "已完成";
90
+ ImgGpt.userCache[userId].prompt = prompt;
83
91
  break;
92
+ } else {
93
+ ImgGpt.userCache[userId].progress = progress;
94
+ ImgGpt.userCache[userId].lastResult = null;
95
+ ImgGpt.userCache[userId].status = status;
96
+ ImgGpt.userCache[userId].prompt = prompt;
84
97
  }
85
- if (time % 6 == 0) {
86
- fn && await fn({ progress, url });
98
+ if (time % 12 == 0) {
99
+ fn && await fn({ progress, url, prompt, status });
87
100
  }
88
- await sleep(1e4);
101
+ await sleep(5e3);
89
102
  time++;
90
103
  }
91
- return { progress, url, prompt };
104
+ return { progress, url, prompt, status };
92
105
  } catch (error) {
93
106
  console.log(error.message);
94
107
  return null;
@@ -98,14 +111,51 @@ function apply(ctx, config) {
98
111
  ctx.command("获取标识").action(async ({ session }) => {
99
112
  return session.userId;
100
113
  });
114
+ ctx.command("当前进度").action(async ({ session }) => {
115
+ const temp = ImgGpt.userCache[session.userId] || null;
116
+ if (!temp) return `您暂未进行任何生图操作...`;
117
+ const max = temp?.progress && Math.floor(temp.progress / 10);
118
+ let i = 0;
119
+ await session.send(
120
+ `需求:${temp.prompt ? temp.prompt.length > 10 ? temp.prompt.slice(0, 10) + "..." : temp.prompt : "无"}
121
+ 状态:${temp.status || "未知"}
122
+ 当前进度:${temp.progress ? Array.from({ length: 10 }, () => {
123
+ i++;
124
+ if (i > max) {
125
+ return "□";
126
+ } else {
127
+ return "■";
128
+ }
129
+ }).join("") : "-"}`
130
+ );
131
+ });
101
132
  ctx.command("生图 <prompt:text>").action(async ({ session }, prompt) => {
102
133
  if (!config.onlyUse.includes(session.userId)) return `该功能暂不对外支持`;
103
134
  const text = import_koishi.h.select(prompt, "text")[0]?.attrs.content || null;
104
135
  const img = import_koishi.h.select(prompt, "img").map((item) => item.attrs.src) || null;
105
136
  if (!text) return `请携带需求发送,例如 /生图 生成一只猫娘`;
106
137
  await session.send("稍等,正在给你生...");
138
+ let messageId = null;
107
139
  const result = await ImgGpt.startGetImage(session, text, img, async (val) => {
108
- await session.send(`当前进度:${val.progress}%`);
140
+ if (config.openNotice) {
141
+ if (messageId) {
142
+ await session.bot.deleteMessage(session.channelId, messageId);
143
+ }
144
+ const max = Math.floor(val.progress / 10);
145
+ let i = 0;
146
+ messageId = await session.send(
147
+ `需求:${val.prompt.length > 10 ? val.prompt.slice(0, 10) + "..." : val.prompt}
148
+ 状态:${val.status}
149
+ 当前进度:${Array.from({ length: 10 }, () => {
150
+ i++;
151
+ if (i > max) {
152
+ return "□";
153
+ } else {
154
+ return "■";
155
+ }
156
+ }).join("")}`
157
+ );
158
+ }
109
159
  });
110
160
  console.log(result);
111
161
  if (!result) return `生成失败!`;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-smmcat-gptimage2",
3
3
  "description": "简单去使用云接口 GPT-Image2",
4
- "version": "0.0.2",
4
+ "version": "0.0.3",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [