koishi-plugin-starfx-bot 0.3.5 → 0.4.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/index.d.ts CHANGED
@@ -7,6 +7,8 @@ export interface Config {
7
7
  openSold: boolean;
8
8
  atNotSay: boolean;
9
9
  atNotSayOther: boolean;
10
+ atNotSayProperty: number;
11
+ atNotSayOtherProperty: number;
10
12
  replyBot: string;
11
13
  iLoveYou: boolean;
12
14
  }
@@ -14,19 +16,28 @@ export declare const Config: Schema<Schemastery.ObjectS<{
14
16
  openLock: Schema<boolean, boolean>;
15
17
  openSold: Schema<boolean, boolean>;
16
18
  atNotSay: Schema<boolean, boolean>;
19
+ atNotSayProperty: Schema<number, number>;
17
20
  atNotSayOther: Schema<boolean, boolean>;
21
+ atNotSayOtherProperty: Schema<number, number>;
18
22
  iLoveYou: Schema<boolean, boolean>;
19
23
  replyBot: Schema<"关闭" | "无需at" | "必须at", "关闭" | "无需at" | "必须at">;
20
24
  }>, {
21
25
  openLock: boolean;
22
26
  openSold: boolean;
23
27
  atNotSay: boolean;
28
+ atNotSayProperty: number;
24
29
  atNotSayOther: boolean;
30
+ atNotSayOtherProperty: number;
25
31
  iLoveYou: boolean;
26
32
  replyBot: "关闭" | "无需at" | "必须at";
27
33
  } & import("cosmokit").Dict>;
28
34
  export declare const usage = "<h5>StarFreedomX\u7684\u81EA\u7528\u63D2\u4EF6 \u653E\u4E86\u4E00\u4E9B\u5C0F\u529F\u80FD</h5>\n ";
29
35
  export declare function apply(ctx: Context, cfg: Config): void;
30
36
  export declare function getImageSrc(session: Session, param: string): Promise<any>;
31
- export declare function drawLock(baseImage: string): Promise<h | "输入无效。" | "发生错误。">;
32
- export declare function drawSold(baseImage: string): Promise<h | "输入无效。" | "发生错误。">;
37
+ export declare function drawLock(ctx: Context, baseImage: string): Promise<h | "发生错误" | "输入无效">;
38
+ /**
39
+ * "卖掉了"绘图函数
40
+ * @param ctx
41
+ * @param baseImage
42
+ */
43
+ export declare function drawSold(ctx: Context, baseImage: string): Promise<h | "发生错误" | "输入无效">;
package/lib/index.js CHANGED
@@ -5,6 +5,9 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __getProtoOf = Object.getPrototypeOf;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
7
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
+ var __commonJS = (cb, mod) => function __require() {
9
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
+ };
8
11
  var __export = (target, all) => {
9
12
  for (var name2 in all)
10
13
  __defProp(target, name2, { get: all[name2], enumerable: true });
@@ -27,6 +30,13 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
30
  ));
28
31
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
32
 
33
+ // src/locales/zh-CN.yml
34
+ var require_zh_CN = __commonJS({
35
+ "src/locales/zh-CN.yml"(exports2, module2) {
36
+ module2.exports = { commands: null, middleware: { messages: { atNotReply: "艾特我又不说话", atNotReplyOther: "艾特他又不说话", notBot: "我才不是机器人!", loveMessage: "我喜欢你", iLoveU: "我也喜欢你" } } };
37
+ }
38
+ });
39
+
30
40
  // src/index.ts
31
41
  var src_exports = {};
32
42
  __export(src_exports, {
@@ -42,7 +52,7 @@ __export(src_exports, {
42
52
  });
43
53
  module.exports = __toCommonJS(src_exports);
44
54
  var import_koishi = require("koishi");
45
- var import_jimp = require("jimp");
55
+ var import_sharp = __toESM(require("sharp"));
46
56
  var fs = __toESM(require("fs"));
47
57
  var name = "starfx-bot";
48
58
  var baseDir;
@@ -52,21 +62,30 @@ var Config = import_koishi.Schema.intersect([
52
62
  openLock: import_koishi.Schema.boolean().default(true).description("开启明日方舟封印功能"),
53
63
  openSold: import_koishi.Schema.boolean().default(true).description('开启闲鱼"卖掉了"功能'),
54
64
  atNotSay: import_koishi.Schema.boolean().default(true).description("开启‘艾特我又不说话’功能"),
65
+ atNotSayProperty: import_koishi.Schema.number().role("slider").min(0).max(1).step(0.01).default(0.5).description("'艾特我又不说话'回复概率"),
55
66
  atNotSayOther: import_koishi.Schema.boolean().default(true).description("开启‘艾特他又不说话’功能"),
67
+ atNotSayOtherProperty: import_koishi.Schema.number().role("slider").min(0).max(1).step(0.01).default(0.5).description("'艾特他又不说话'回复概率"),
56
68
  iLoveYou: import_koishi.Schema.boolean().default(true).description("开启‘我喜欢你’功能"),
57
- replyBot: import_koishi.Schema.union(["关闭", "无需at", "必须at"]).default("无需at").description("回复‘我才是不是机器人!’功能")
69
+ replyBot: import_koishi.Schema.union(["关闭", "无需at", "必须at"]).default("无需at").description("回复‘我才不是机器人!’功能")
58
70
  })
59
71
  ]);
60
72
  var usage = `<h5>StarFreedomX的自用插件 放了一些小功能</h5>
61
73
  `;
62
74
  function apply(ctx, cfg) {
75
+ ctx.i18n.define("zh-CN", require_zh_CN());
63
76
  baseDir = ctx.baseDir;
64
77
  assetsDir = `${ctx.baseDir}/data/starfx-bot/assets`;
65
78
  initAssets("lock.png");
66
79
  initAssets("sold.png");
67
80
  if (cfg.openLock) {
68
81
  ctx.command("封印 [param]").action(async ({ session }, param) => {
69
- return await drawLock(await getImageSrc(session, param));
82
+ console.log("elements");
83
+ console.log(session.elements);
84
+ console.log("quote");
85
+ console.log(session.quote);
86
+ console.log("param");
87
+ console.log(param);
88
+ return await drawLock(ctx, await getImageSrc(session, param));
70
89
  });
71
90
  }
72
91
  if (cfg.openSold) {
@@ -77,7 +96,7 @@ function apply(ctx, cfg) {
77
96
  console.log(session.quote);
78
97
  console.log("param");
79
98
  console.log(param);
80
- return await drawSold(await getImageSrc(session, param));
99
+ return await drawSold(ctx, await getImageSrc(session, param));
81
100
  });
82
101
  }
83
102
  ctx.middleware(async (session, next) => {
@@ -86,27 +105,36 @@ function apply(ctx, cfg) {
86
105
  if (cfg.atNotSay || cfg.atNotSayOther) {
87
106
  if (elements.length === 1 && elements[0].type === "at") {
88
107
  if (elements[0].attrs.id === session.selfId) {
89
- if (cfg.atNotSay)
90
- await session.send("艾特我又不说话");
108
+ if (cfg.atNotSay) {
109
+ if (import_koishi.Random.bool(cfg.atNotSayProperty)) {
110
+ await session.send(session.text("middleware.messages.atNotReply"));
111
+ }
112
+ }
91
113
  } else {
92
- if (cfg.atNotSayOther)
93
- await session.send("艾特他又不说话");
114
+ if (cfg.atNotSayOther) {
115
+ if (import_koishi.Random.bool(cfg.atNotSayOtherProperty)) {
116
+ await session.send(session.text("middleware.messages.atNotReplyOther"));
117
+ }
118
+ }
94
119
  }
95
120
  }
96
121
  }
97
122
  if (cfg.replyBot !== "关闭") {
98
- const bots = ["bot", "机器人", "Bot", "BOT", "机器人!", "机器人!"];
123
+ const bots = ["bot", "机器人", "Bot", "BOT", "机器人!", "机器人!", "人机"];
99
124
  const texts = elements?.filter((e) => e.type === "text").map((e) => e?.attrs?.content?.trim());
100
125
  const ats = elements?.filter((e) => e.type === "at").map((e) => e?.attrs?.id);
101
126
  const mentionedBot = texts?.some((t) => bots.includes(t));
102
127
  const atMe = ats?.includes(session.selfId);
103
128
  if (elements?.length === 1 && mentionedBot && cfg.replyBot === "无需at" || elements?.length === 2 && mentionedBot && atMe) {
104
- await session.send("我才不是机器人!");
129
+ await session.send(session.text("middleware.messages.notBot"));
105
130
  }
106
131
  }
107
132
  if (cfg.iLoveYou) {
108
- if (elements?.length === 2 && elements.some((e) => e.type === "at" && e?.attrs?.id === session.selfId) && elements.some((e) => e.type === "text" && e?.attrs?.content?.trim() === "我喜欢你")) {
109
- await session.send(`${import_koishi.h.quote(session.messageId)}${import_koishi.h.at(session.userId)} 我也喜欢你`);
133
+ if (elements?.length === 2 && elements.some((e) => e.type === "at" && e?.attrs?.id === session.selfId) && elements.some((e) => e.type === "text" && e?.attrs?.content?.trim() === session.text("middleware.messages.loveMessage"))) {
134
+ await session.send(session.text("middleware.messages.iLoveU", {
135
+ at: import_koishi.h.at(session.userId),
136
+ quote: import_koishi.h.quote(session.messageId)
137
+ }));
110
138
  }
111
139
  }
112
140
  return next();
@@ -123,7 +151,7 @@ async function getImageSrc(session, param) {
123
151
  for (const element of elementArray) {
124
152
  if (element?.type === "img") {
125
153
  return element?.attrs?.src;
126
- } else if (element?.type === "at" && element?.attrs?.id && element.attrs.id !== session.selfId) {
154
+ } else if (element?.type === "at" && element?.attrs?.id) {
127
155
  return `https://q1.qlogo.cn/g?b=qq&nk=${element.attrs.id}&s=640`;
128
156
  }
129
157
  }
@@ -148,49 +176,75 @@ function initAssets(fileName) {
148
176
  }
149
177
  }
150
178
  __name(initAssets, "initAssets");
151
- async function drawLock(baseImage) {
152
- if (!baseImage) {
153
- return "输入无效。";
179
+ async function drawLock(ctx, baseImage) {
180
+ const image = await getImageFromUrl(ctx, baseImage);
181
+ if (image === -1) {
182
+ return "发生错误";
183
+ } else if (image === -2) {
184
+ return "输入无效";
154
185
  }
186
+ const imageMetadata = await image.metadata();
155
187
  const lockUrl = `${baseDir}/data/starfx-bot/assets/lock.png`;
156
- let image;
157
- try {
158
- image = await import_jimp.Jimp.read(baseImage);
159
- } catch (err) {
160
- console.error(err);
161
- return "发生错误。";
162
- }
163
- const size1 = image.width > image.height ? image.height : image.width;
164
- image.cover({ w: size1, h: size1 });
165
- const overlay = await import_jimp.Jimp.read(lockUrl);
166
- overlay.resize({ w: image.width });
167
- image.composite(overlay);
168
- return import_koishi.h.image(await image.getBuffer("image/jpeg"), "image/jpeg");
188
+ const size1 = Math.min(imageMetadata.width, imageMetadata.height);
189
+ image.resize({ width: size1, height: size1, fit: "cover" });
190
+ const overlay = (0, import_sharp.default)(lockUrl).png();
191
+ overlay.resize({ width: size1 });
192
+ image.composite([{ input: await overlay.toBuffer() }]);
193
+ return import_koishi.h.image(await image.png().toBuffer(), "image/png");
169
194
  }
170
195
  __name(drawLock, "drawLock");
171
- async function drawSold(baseImage) {
172
- if (!baseImage) {
173
- return "输入无效。";
196
+ async function drawSold(ctx, baseImage) {
197
+ const image = await getImageFromUrl(ctx, baseImage);
198
+ if (image === -1) {
199
+ return "发生错误";
200
+ } else if (image === -2) {
201
+ return "输入无效";
174
202
  }
203
+ const imageMetadata = await image.metadata();
204
+ const size1 = Math.min(imageMetadata.width, imageMetadata.height);
205
+ image.resize({ width: size1, height: size1, fit: "cover" });
206
+ const middle = (0, import_sharp.default)({
207
+ create: {
208
+ width: size1,
209
+ height: size1,
210
+ channels: 4,
211
+ background: { r: 255, g: 255, b: 255, alpha: 0.4 }
212
+ }
213
+ }).png();
175
214
  const soldUrl = `${assetsDir}/sold.png`;
215
+ const overlay = (0, import_sharp.default)(soldUrl).png();
216
+ const overlaySize = Math.round(size1 * 182 / 240);
217
+ overlay.resize({
218
+ width: overlaySize,
219
+ height: overlaySize
220
+ });
221
+ const topLeft = Math.round(overlaySize * 29 / 182);
222
+ image.composite([
223
+ { input: await middle.toBuffer() },
224
+ {
225
+ input: await overlay.toBuffer(),
226
+ top: topLeft,
227
+ left: topLeft
228
+ }
229
+ ]);
230
+ return import_koishi.h.image(await image.png().toBuffer(), "image/png");
231
+ }
232
+ __name(drawSold, "drawSold");
233
+ async function getImageFromUrl(ctx, url) {
234
+ if (!url) return -2;
176
235
  let image;
236
+ const config = {
237
+ responseType: "arraybuffer"
238
+ };
177
239
  try {
178
- image = await import_jimp.Jimp.read(baseImage);
240
+ image = (0, import_sharp.default)(await ctx.http.get(url, config)).png();
179
241
  } catch (err) {
180
242
  console.error(err);
181
- return "发生错误。";
243
+ return -1;
182
244
  }
183
- const size1 = Math.min(image.width, image.height);
184
- image.cover({ w: size1, h: size1 });
185
- const middle = new import_jimp.Jimp({ width: image.width, height: image.height, color: 4294967295 });
186
- const overlay = await import_jimp.Jimp.read(soldUrl);
187
- overlay.resize({ w: image.width * 182 / 240 });
188
- middle.opacity(0.4);
189
- image.composite(middle);
190
- image.composite(overlay, image.width * 29 / 240, image.width * 29 / 240);
191
- return import_koishi.h.image(await image.getBuffer("image/jpeg"), "image/jpeg");
245
+ return image;
192
246
  }
193
- __name(drawSold, "drawSold");
247
+ __name(getImageFromUrl, "getImageFromUrl");
194
248
  // Annotate the CommonJS export names for ESM import in node:
195
249
  0 && (module.exports = {
196
250
  Config,
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "contributors": [
5
5
  "StarFreedomX <starfreedomx@outlook.com>"
6
6
  ],
7
- "version": "0.3.5",
7
+ "version": "0.4.1",
8
8
  "main": "lib/index.js",
9
9
  "typings": "lib/index.d.ts",
10
10
  "files": [
@@ -36,6 +36,6 @@
36
36
  "koishi": "^4.18.7"
37
37
  },
38
38
  "dependencies": {
39
- "jimp": "^1.6.0"
39
+ "sharp": "^0.34.1"
40
40
  }
41
41
  }
package/readme.md CHANGED
@@ -22,3 +22,6 @@ StarFreedomX机器人的小功能,自用
22
22
  | `0.3.3` | 修订添加"我才不是机器人"是否需要at |
23
23
  | `0.3.4` | 分离"艾特我/他又不说话"的两个选项为单独的开关 |
24
24
  | `0.3.5` | 修复丢失的assets |
25
+ | `0.3.6` | 添加"艾特我/他又不说话"的概率配置 |
26
+ | `0.4.0` | 更改处理库为sharp |
27
+ | `0.4.1` | 修复sharp处理w>h的图报错的bug |
package/assets/lock.png DELETED
Binary file
package/assets/sold.png DELETED
Binary file