apexify.js 3.1.8 → 3.2.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.
@@ -5,437 +5,440 @@ const utils_1 = require("../../utils");
5
5
  const apexPainter = new utils_1.ApexPainter();
6
6
  async function filters(Apex) {
7
7
  Apex.on("interactionCreate", async (a) => {
8
- if (!a.isModalSubmit())
9
- return;
10
- const submitId = a.customId;
11
- if (submitId === "resizing_image_zenithmodal") {
12
- await a.deferReply({ ephemeral: true });
13
- const imagePosition = parseInt(a.fields.getTextInputValue("Image_Postion"), 10);
14
- const interactionMessage = await a.message.fetch();
15
- const attachmentsArray = Array.from(interactionMessage.attachments.values());
16
- const totalAttachments = attachmentsArray.length;
17
- if (imagePosition >= 1 && imagePosition <= totalAttachments) {
18
- const selectedAttachment = attachmentsArray[imagePosition - 1];
19
- const imageURL = selectedAttachment.url;
20
- const width = a.fields.getTextInputValue("modal_resizingImage_width");
21
- const height = a.fields.getTextInputValue("modal_resizingImage_height");
22
- try {
23
- const resizedBuffer = await apexPainter.resize({
24
- imagePath: imageURL,
25
- size: { width: parseInt(width, 10), height: parseInt(height, 10) },
26
- });
27
- await a.editReply({
28
- content: "Resized Image:",
29
- files: [resizedBuffer],
30
- ephemeral: true,
31
- });
8
+ try {
9
+ if (!a.isModalSubmit())
10
+ return;
11
+ const submitId = a.customId;
12
+ if (submitId === "resizing_image_zenithmodal") {
13
+ await a.deferReply({ ephemeral: true });
14
+ const imagePosition = parseInt(a.fields.getTextInputValue("Image_Postion"), 10);
15
+ const interactionMessage = await a.message.fetch();
16
+ const attachmentsArray = Array.from(interactionMessage.attachments.values());
17
+ const totalAttachments = attachmentsArray.length;
18
+ if (imagePosition >= 1 && imagePosition <= totalAttachments) {
19
+ const selectedAttachment = attachmentsArray[imagePosition - 1];
20
+ const imageURL = selectedAttachment.url;
21
+ const width = a.fields.getTextInputValue("modal_resizingImage_width");
22
+ const height = a.fields.getTextInputValue("modal_resizingImage_height");
23
+ try {
24
+ const resizedBuffer = await apexPainter.resize({
25
+ imagePath: imageURL,
26
+ size: { width: parseInt(width, 10), height: parseInt(height, 10) },
27
+ });
28
+ await a.editReply({
29
+ content: "Resized Image:",
30
+ files: [resizedBuffer],
31
+ ephemeral: true,
32
+ });
33
+ }
34
+ catch (error) {
35
+ console.error("Error resizing image:", error);
36
+ await a.editReply({
37
+ content: "Failed to resize image",
38
+ ephemeral: true,
39
+ });
40
+ }
32
41
  }
33
- catch (error) {
34
- console.error("Error resizing image:", error);
42
+ else {
35
43
  await a.editReply({
36
- content: "Failed to resize image",
44
+ content: `Invalid image position. Please select a position between 1 and ${totalAttachments}.`,
37
45
  ephemeral: true,
38
46
  });
39
47
  }
40
48
  }
41
- else {
42
- await a.editReply({
43
- content: `Invalid image position. Please select a position between 1 and ${totalAttachments}.`,
44
- ephemeral: true,
45
- });
46
- }
47
- }
48
- else if (submitId === "Color_Filters") {
49
- await a.deferReply({ ephemeral: true });
50
- const imagePosition = parseInt(a.fields.getTextInputValue("Image_Postion"), 10);
51
- const interactionMessage = await a.message.fetch();
52
- const attachmentsArray = Array.from(interactionMessage.attachments.values());
53
- const totalAttachments = attachmentsArray.length;
54
- if (imagePosition >= 1 && imagePosition <= totalAttachments) {
55
- const selectedAttachment = attachmentsArray[imagePosition - 1];
56
- const imageURL = selectedAttachment.url;
57
- const hexColor = a.fields.getTextInputValue("color_filter_image");
58
- apexPainter.validHex(hexColor);
59
- try {
60
- const filteredBuffer = await apexPainter.colorsFilter(imageURL, hexColor);
61
- await a.editReply({
62
- content: "Filtered Image:",
63
- files: [filteredBuffer],
64
- ephemeral: true,
65
- });
49
+ else if (submitId === "Color_Filters") {
50
+ await a.deferReply({ ephemeral: true });
51
+ const imagePosition = parseInt(a.fields.getTextInputValue("Image_Postion"), 10);
52
+ const interactionMessage = await a.message.fetch();
53
+ const attachmentsArray = Array.from(interactionMessage.attachments.values());
54
+ const totalAttachments = attachmentsArray.length;
55
+ if (imagePosition >= 1 && imagePosition <= totalAttachments) {
56
+ const selectedAttachment = attachmentsArray[imagePosition - 1];
57
+ const imageURL = selectedAttachment.url;
58
+ const hexColor = a.fields.getTextInputValue("color_filter_image");
59
+ apexPainter.validHex(hexColor);
60
+ try {
61
+ const filteredBuffer = await apexPainter.colorsFilter(imageURL, hexColor);
62
+ await a.editReply({
63
+ content: "Filtered Image:",
64
+ files: [filteredBuffer],
65
+ ephemeral: true,
66
+ });
67
+ }
68
+ catch (error) {
69
+ console.error("Error applying color filter:", error);
70
+ await a.editReply({
71
+ content: "Failed to apply color filter. Note: colors need to be in hex code format.",
72
+ ephemeral: true,
73
+ });
74
+ }
66
75
  }
67
- catch (error) {
68
- console.error("Error applying color filter:", error);
76
+ else {
69
77
  await a.editReply({
70
- content: "Failed to apply color filter. Note: colors need to be in hex code format.",
78
+ content: `Invalid image position. Please select a position between 1 and ${totalAttachments}.`,
71
79
  ephemeral: true,
72
80
  });
73
81
  }
74
82
  }
75
- else {
76
- await a.editReply({
77
- content: `Invalid image position. Please select a position between 1 and ${totalAttachments}.`,
78
- ephemeral: true,
79
- });
80
- }
81
- }
82
- else if (submitId === "Convert_Image_Extension") {
83
- await a.deferReply({ ephemeral: true });
84
- const imagePosition = parseInt(a.fields.getTextInputValue("Image_Postion"), 10);
85
- const interactionMessage = await a.message.fetch();
86
- const attachmentsArray = Array.from(interactionMessage.attachments.values());
87
- const totalAttachments = attachmentsArray.length;
88
- if (imagePosition >= 1 && imagePosition <= totalAttachments) {
89
- const selectedAttachment = attachmentsArray[imagePosition - 1];
90
- const imageURL = selectedAttachment.url;
91
- const imageType = a.fields.getTextInputValue("image_type");
92
- try {
93
- const convertedBuffer = await apexPainter.imgconverter(imageURL, imageType, __dirname);
94
- await a.editReply({
95
- content: "Converted Image:",
96
- files: [convertedBuffer],
97
- ephemeral: true,
98
- });
83
+ else if (submitId === "Convert_Image_Extension") {
84
+ await a.deferReply({ ephemeral: true });
85
+ const imagePosition = parseInt(a.fields.getTextInputValue("Image_Postion"), 10);
86
+ const interactionMessage = await a.message.fetch();
87
+ const attachmentsArray = Array.from(interactionMessage.attachments.values());
88
+ const totalAttachments = attachmentsArray.length;
89
+ if (imagePosition >= 1 && imagePosition <= totalAttachments) {
90
+ const selectedAttachment = attachmentsArray[imagePosition - 1];
91
+ const imageURL = selectedAttachment.url;
92
+ const imageType = a.fields.getTextInputValue("image_type");
93
+ try {
94
+ const convertedBuffer = await apexPainter.imgconverter(imageURL, imageType, __dirname);
95
+ await a.editReply({
96
+ content: "Converted Image:",
97
+ files: [convertedBuffer],
98
+ ephemeral: true,
99
+ });
100
+ }
101
+ catch (error) {
102
+ console.error("Error converting image extension:", error);
103
+ await a.editReply({
104
+ content: "Failed to convert image extension",
105
+ ephemeral: true,
106
+ });
107
+ }
99
108
  }
100
- catch (error) {
101
- console.error("Error converting image extension:", error);
109
+ else {
102
110
  await a.editReply({
103
- content: "Failed to convert image extension",
111
+ content: `Invalid image position. Please select a position between 1 and ${totalAttachments}.`,
104
112
  ephemeral: true,
105
113
  });
106
114
  }
107
115
  }
108
- else {
109
- await a.editReply({
110
- content: `Invalid image position. Please select a position between 1 and ${totalAttachments}.`,
111
- ephemeral: true,
112
- });
113
- }
114
- }
115
- else if (submitId === "Image_Brightness") {
116
- await a.deferReply({ ephemeral: true });
117
- const imagePosition = parseInt(a.fields.getTextInputValue("Image_Postion"), 10);
118
- const interactionMessage = await a.message.fetch();
119
- const attachmentsArray = Array.from(interactionMessage.attachments.values());
120
- const totalAttachments = attachmentsArray.length;
121
- if (imagePosition >= 1 && imagePosition <= totalAttachments) {
122
- const selectedAttachment = attachmentsArray[imagePosition - 1];
123
- const imageURL = selectedAttachment.url;
124
- const brightnessDegree = a.fields.getTextInputValue("brightness_degree");
125
- if (brightnessDegree < 0 || brightnessDegree > 1) {
126
- return await a.editReply({
127
- content: "Value must be between 0-1",
128
- ephemeral: true,
129
- });
130
- }
131
- try {
132
- const processedBuffer = await apexPainter.processImage(imageURL, [
133
- { type: "brightness", value: parseFloat(brightnessDegree) },
134
- ]);
135
- await a.editReply({
136
- content: "Brightness Adjusted Image:",
137
- files: [processedBuffer],
138
- ephemeral: true,
139
- });
116
+ else if (submitId === "Image_Brightness") {
117
+ await a.deferReply({ ephemeral: true });
118
+ const imagePosition = parseInt(a.fields.getTextInputValue("Image_Postion"), 10);
119
+ const interactionMessage = await a.message.fetch();
120
+ const attachmentsArray = Array.from(interactionMessage.attachments.values());
121
+ const totalAttachments = attachmentsArray.length;
122
+ if (imagePosition >= 1 && imagePosition <= totalAttachments) {
123
+ const selectedAttachment = attachmentsArray[imagePosition - 1];
124
+ const imageURL = selectedAttachment.url;
125
+ const brightnessDegree = a.fields.getTextInputValue("brightness_degree");
126
+ if (brightnessDegree < 0 || brightnessDegree > 1) {
127
+ return await a.editReply({
128
+ content: "Value must be between 0-1",
129
+ ephemeral: true,
130
+ });
131
+ }
132
+ try {
133
+ const processedBuffer = await apexPainter.processImage(imageURL, [
134
+ { type: "brightness", value: parseFloat(brightnessDegree) },
135
+ ]);
136
+ await a.editReply({
137
+ content: "Brightness Adjusted Image:",
138
+ files: [processedBuffer],
139
+ ephemeral: true,
140
+ });
141
+ }
142
+ catch (error) {
143
+ console.error("Error adjusting image brightness:", error);
144
+ await a.editReply({
145
+ content: "Failed to adjust image brightness",
146
+ ephemeral: true,
147
+ });
148
+ }
140
149
  }
141
- catch (error) {
142
- console.error("Error adjusting image brightness:", error);
150
+ else {
143
151
  await a.editReply({
144
- content: "Failed to adjust image brightness",
152
+ content: `Invalid image position. Please select a position between 1 and ${totalAttachments}.`,
145
153
  ephemeral: true,
146
154
  });
147
155
  }
148
156
  }
149
- else {
150
- await a.editReply({
151
- content: `Invalid image position. Please select a position between 1 and ${totalAttachments}.`,
152
- ephemeral: true,
153
- });
154
- }
155
- }
156
- else if (submitId === "Sepia_Filter") {
157
- await a.deferReply({ ephemeral: true });
158
- const imagePosition = parseInt(a.fields.getTextInputValue("Image_Postion"), 10);
159
- const interactionMessage = await a.message.fetch();
160
- const attachmentsArray = Array.from(interactionMessage.attachments.values());
161
- const totalAttachments = attachmentsArray.length;
162
- if (imagePosition >= 1 && imagePosition <= totalAttachments) {
163
- const selectedAttachment = attachmentsArray[imagePosition - 1];
164
- const imageURL = selectedAttachment.url;
165
- try {
166
- const processedBuffer = await apexPainter.processImage(imageURL, [
167
- { type: "sepia" },
168
- ]);
169
- await a.editReply({
170
- content: "Applied Sepia Image:",
171
- files: [processedBuffer],
172
- ephemeral: true,
173
- });
157
+ else if (submitId === "Sepia_Filter") {
158
+ await a.deferReply({ ephemeral: true });
159
+ const imagePosition = parseInt(a.fields.getTextInputValue("Image_Postion"), 10);
160
+ const interactionMessage = await a.message.fetch();
161
+ const attachmentsArray = Array.from(interactionMessage.attachments.values());
162
+ const totalAttachments = attachmentsArray.length;
163
+ if (imagePosition >= 1 && imagePosition <= totalAttachments) {
164
+ const selectedAttachment = attachmentsArray[imagePosition - 1];
165
+ const imageURL = selectedAttachment.url;
166
+ try {
167
+ const processedBuffer = await apexPainter.processImage(imageURL, [
168
+ { type: "sepia" },
169
+ ]);
170
+ await a.editReply({
171
+ content: "Applied Sepia Image:",
172
+ files: [processedBuffer],
173
+ ephemeral: true,
174
+ });
175
+ }
176
+ catch (error) {
177
+ console.error("Error applying sepia:", error);
178
+ await a.editReply({
179
+ content: "Failed to apply sepia filter",
180
+ ephemeral: true,
181
+ });
182
+ }
174
183
  }
175
- catch (error) {
176
- console.error("Error applying sepia:", error);
184
+ else {
177
185
  await a.editReply({
178
- content: "Failed to apply sepia filter",
186
+ content: `Invalid image position. Please select a position between 1 and ${totalAttachments}.`,
179
187
  ephemeral: true,
180
188
  });
181
189
  }
182
190
  }
183
- else {
184
- await a.editReply({
185
- content: `Invalid image position. Please select a position between 1 and ${totalAttachments}.`,
186
- ephemeral: true,
187
- });
188
- }
189
- }
190
- else if (submitId === "Pixelate_Filter") {
191
- await a.deferReply({ ephemeral: true });
192
- const imagePosition = parseInt(a.fields.getTextInputValue("Image_Postion"), 10);
193
- const interactionMessage = await a.message.fetch();
194
- const attachmentsArray = Array.from(interactionMessage.attachments.values());
195
- const totalAttachments = attachmentsArray.length;
196
- if (imagePosition >= 1 && imagePosition <= totalAttachments) {
197
- const selectedAttachment = attachmentsArray[imagePosition - 1];
198
- const imageURL = selectedAttachment.url;
199
- const xy = a.fields.getTextInputValue("Pixelate_XY");
200
- const wh = a.fields.getTextInputValue("Pixelate_WH");
201
- const size = a.fields.getTextInputValue("Pixelate_Size");
202
- try {
203
- const xyArray = xy
204
- .split(",")
205
- .map((coord) => parseInt(coord.trim(), 10));
206
- const whArray = wh
207
- .split(",")
208
- .map((coord) => parseInt(coord.trim(), 10));
209
- if (xyArray.length !== 2 ||
210
- whArray.length !== 2 ||
211
- xyArray.some(isNaN) ||
212
- whArray.some(isNaN)) {
213
- throw new Error('Invalid format for xy or wh. Use the format "x, y" and "width, height" with valid integer values.');
191
+ else if (submitId === "Pixelate_Filter") {
192
+ await a.deferReply({ ephemeral: true });
193
+ const imagePosition = parseInt(a.fields.getTextInputValue("Image_Postion"), 10);
194
+ const interactionMessage = await a.message.fetch();
195
+ const attachmentsArray = Array.from(interactionMessage.attachments.values());
196
+ const totalAttachments = attachmentsArray.length;
197
+ if (imagePosition >= 1 && imagePosition <= totalAttachments) {
198
+ const selectedAttachment = attachmentsArray[imagePosition - 1];
199
+ const imageURL = selectedAttachment.url;
200
+ const xy = a.fields.getTextInputValue("Pixelate_XY");
201
+ const wh = a.fields.getTextInputValue("Pixelate_WH");
202
+ const size = a.fields.getTextInputValue("Pixelate_Size");
203
+ try {
204
+ const xyArray = xy
205
+ .split(",")
206
+ .map((coord) => parseInt(coord.trim(), 10));
207
+ const whArray = wh
208
+ .split(",")
209
+ .map((coord) => parseInt(coord.trim(), 10));
210
+ if (xyArray.length !== 2 ||
211
+ whArray.length !== 2 ||
212
+ xyArray.some(isNaN) ||
213
+ whArray.some(isNaN)) {
214
+ throw new Error('Invalid format for xy or wh. Use the format "x, y" and "width, height" with valid integer values.');
215
+ }
216
+ const [x, y] = xyArray;
217
+ const [width, height] = whArray;
218
+ const processedBuffer = await apexPainter.processImage(imageURL, [
219
+ {
220
+ type: "pixelate",
221
+ size: parseInt(size, 10),
222
+ x,
223
+ y,
224
+ w: width,
225
+ h: height,
226
+ },
227
+ ]);
228
+ await a.editReply({
229
+ content: "Pixelated Image:",
230
+ files: [processedBuffer],
231
+ ephemeral: true,
232
+ });
233
+ }
234
+ catch (error) {
235
+ console.error("Error applying pixelate filter:", error);
236
+ await a.editReply({
237
+ content: "Failed to apply pixelate filter: " + error.message,
238
+ ephemeral: true,
239
+ });
214
240
  }
215
- const [x, y] = xyArray;
216
- const [width, height] = whArray;
217
- const processedBuffer = await apexPainter.processImage(imageURL, [
218
- {
219
- type: "pixelate",
220
- size: parseInt(size, 10),
221
- x,
222
- y,
223
- w: width,
224
- h: height,
225
- },
226
- ]);
227
- await a.editReply({
228
- content: "Pixelated Image:",
229
- files: [processedBuffer],
230
- ephemeral: true,
231
- });
232
241
  }
233
- catch (error) {
234
- console.error("Error applying pixelate filter:", error);
242
+ else {
235
243
  await a.editReply({
236
- content: "Failed to apply pixelate filter: " + error.message,
244
+ content: `Invalid image position. Please select a position between 1 and ${totalAttachments}.`,
237
245
  ephemeral: true,
238
246
  });
239
247
  }
240
248
  }
241
- else {
242
- await a.editReply({
243
- content: `Invalid image position. Please select a position between 1 and ${totalAttachments}.`,
244
- ephemeral: true,
245
- });
246
- }
247
- }
248
- else if (submitId === "Image_Blur") {
249
- await a.deferReply({ ephemeral: true });
250
- const imagePosition = parseInt(a.fields.getTextInputValue("Image_Postion"), 10);
251
- const interactionMessage = await a.message.fetch();
252
- const attachmentsArray = Array.from(interactionMessage.attachments.values());
253
- const totalAttachments = attachmentsArray.length;
254
- if (imagePosition >= 1 && imagePosition <= totalAttachments) {
255
- const selectedAttachment = attachmentsArray[imagePosition - 1];
256
- const imageURL = selectedAttachment.url;
257
- const blurRadius = a.fields.getTextInputValue("blur_radius");
258
- if (blurRadius < 0 || blurRadius > 100) {
259
- return await a.editReply({
260
- content: "Value must be between 0-100",
261
- ephemeral: true,
262
- });
263
- }
264
- try {
265
- const processedBuffer = await apexPainter.processImage(imageURL, [
266
- { type: "blur", radius: parseFloat(blurRadius) },
267
- ]);
268
- await a.editReply({
269
- content: "Blurred Image:",
270
- files: [processedBuffer],
271
- ephemeral: true,
272
- });
249
+ else if (submitId === "Image_Blur") {
250
+ await a.deferReply({ ephemeral: true });
251
+ const imagePosition = parseInt(a.fields.getTextInputValue("Image_Postion"), 10);
252
+ const interactionMessage = await a.message.fetch();
253
+ const attachmentsArray = Array.from(interactionMessage.attachments.values());
254
+ const totalAttachments = attachmentsArray.length;
255
+ if (imagePosition >= 1 && imagePosition <= totalAttachments) {
256
+ const selectedAttachment = attachmentsArray[imagePosition - 1];
257
+ const imageURL = selectedAttachment.url;
258
+ const blurRadius = a.fields.getTextInputValue("blur_radius");
259
+ if (blurRadius < 0 || blurRadius > 100) {
260
+ return await a.editReply({
261
+ content: "Value must be between 0-100",
262
+ ephemeral: true,
263
+ });
264
+ }
265
+ try {
266
+ const processedBuffer = await apexPainter.processImage(imageURL, [
267
+ { type: "blur", radius: parseFloat(blurRadius) },
268
+ ]);
269
+ await a.editReply({
270
+ content: "Blurred Image:",
271
+ files: [processedBuffer],
272
+ ephemeral: true,
273
+ });
274
+ }
275
+ catch (error) {
276
+ console.error("Error applying blur filter:", error);
277
+ await a.editReply({
278
+ content: "Failed to apply blur filter: " + error.message,
279
+ ephemeral: true,
280
+ });
281
+ }
273
282
  }
274
- catch (error) {
275
- console.error("Error applying blur filter:", error);
283
+ else {
276
284
  await a.editReply({
277
- content: "Failed to apply blur filter: " + error.message,
285
+ content: `Invalid image position. Please select a position between 1 and ${totalAttachments}.`,
278
286
  ephemeral: true,
279
287
  });
280
288
  }
281
289
  }
282
- else {
283
- await a.editReply({
284
- content: `Invalid image position. Please select a position between 1 and ${totalAttachments}.`,
285
- ephemeral: true,
286
- });
287
- }
288
- }
289
- else if (submitId === "Image_Fade") {
290
- await a.deferReply({ ephemeral: true });
291
- const imagePosition = parseInt(a.fields.getTextInputValue("Image_Postion"), 10);
292
- const interactionMessage = await a.message.fetch();
293
- const attachmentsArray = Array.from(interactionMessage.attachments.values());
294
- const totalAttachments = attachmentsArray.length;
295
- if (imagePosition >= 1 && imagePosition <= totalAttachments) {
296
- const selectedAttachment = attachmentsArray[imagePosition - 1];
297
- const imageURL = selectedAttachment.url;
298
- const fadeFactor = a.fields.getTextInputValue("fade_factor");
299
- if (fadeFactor < 0 || fadeFactor > 1) {
300
- return await a.editReply({
301
- content: "Value must be between 0-1",
302
- ephemeral: true,
303
- });
304
- }
305
- try {
306
- const processedBuffer = await apexPainter.processImage(imageURL, [
307
- { type: "fade", factor: parseFloat(fadeFactor) },
308
- ]);
309
- await a.editReply({
310
- content: "Faded Image:",
311
- files: [processedBuffer],
312
- ephemeral: true,
313
- });
290
+ else if (submitId === "Image_Fade") {
291
+ await a.deferReply({ ephemeral: true });
292
+ const imagePosition = parseInt(a.fields.getTextInputValue("Image_Postion"), 10);
293
+ const interactionMessage = await a.message.fetch();
294
+ const attachmentsArray = Array.from(interactionMessage.attachments.values());
295
+ const totalAttachments = attachmentsArray.length;
296
+ if (imagePosition >= 1 && imagePosition <= totalAttachments) {
297
+ const selectedAttachment = attachmentsArray[imagePosition - 1];
298
+ const imageURL = selectedAttachment.url;
299
+ const fadeFactor = a.fields.getTextInputValue("fade_factor");
300
+ if (fadeFactor < 0 || fadeFactor > 1) {
301
+ return await a.editReply({
302
+ content: "Value must be between 0-1",
303
+ ephemeral: true,
304
+ });
305
+ }
306
+ try {
307
+ const processedBuffer = await apexPainter.processImage(imageURL, [
308
+ { type: "fade", factor: parseFloat(fadeFactor) },
309
+ ]);
310
+ await a.editReply({
311
+ content: "Faded Image:",
312
+ files: [processedBuffer],
313
+ ephemeral: true,
314
+ });
315
+ }
316
+ catch (error) {
317
+ console.error("Error applying fade filter:", error);
318
+ await a.editReply({
319
+ content: "Failed to apply fade filter: " + error.message,
320
+ ephemeral: true,
321
+ });
322
+ }
314
323
  }
315
- catch (error) {
316
- console.error("Error applying fade filter:", error);
324
+ else {
317
325
  await a.editReply({
318
- content: "Failed to apply fade filter: " + error.message,
326
+ content: `Invalid image position. Please select a position between 1 and ${totalAttachments}.`,
319
327
  ephemeral: true,
320
328
  });
321
329
  }
322
330
  }
323
- else {
324
- await a.editReply({
325
- content: `Invalid image position. Please select a position between 1 and ${totalAttachments}.`,
326
- ephemeral: true,
327
- });
328
- }
329
- }
330
- else if (submitId === "Image_Opaque") {
331
- await a.deferReply({ ephemeral: true });
332
- const imagePosition = parseInt(a.fields.getTextInputValue("Image_Postion"), 10);
333
- const interactionMessage = await a.message.fetch();
334
- const attachmentsArray = Array.from(interactionMessage.attachments.values());
335
- const totalAttachments = attachmentsArray.length;
336
- if (imagePosition >= 1 && imagePosition <= totalAttachments) {
337
- const selectedAttachment = attachmentsArray[imagePosition - 1];
338
- const imageURL = selectedAttachment.url;
339
- try {
340
- const processedBuffer = await apexPainter.processImage(imageURL, [
341
- { type: "opaque" },
342
- ]);
343
- await a.editReply({
344
- content: "Opaque Image:",
345
- files: [processedBuffer],
346
- ephemeral: true,
347
- });
331
+ else if (submitId === "Image_Opaque") {
332
+ await a.deferReply({ ephemeral: true });
333
+ const imagePosition = parseInt(a.fields.getTextInputValue("Image_Postion"), 10);
334
+ const interactionMessage = await a.message.fetch();
335
+ const attachmentsArray = Array.from(interactionMessage.attachments.values());
336
+ const totalAttachments = attachmentsArray.length;
337
+ if (imagePosition >= 1 && imagePosition <= totalAttachments) {
338
+ const selectedAttachment = attachmentsArray[imagePosition - 1];
339
+ const imageURL = selectedAttachment.url;
340
+ try {
341
+ const processedBuffer = await apexPainter.processImage(imageURL, [
342
+ { type: "opaque" },
343
+ ]);
344
+ await a.editReply({
345
+ content: "Opaque Image:",
346
+ files: [processedBuffer],
347
+ ephemeral: true,
348
+ });
349
+ }
350
+ catch (error) {
351
+ console.error("Error applying opaque filter:", error);
352
+ await a.editReply({
353
+ content: "Failed to apply opaque filter: " + error.message,
354
+ ephemeral: true,
355
+ });
356
+ }
348
357
  }
349
- catch (error) {
350
- console.error("Error applying opaque filter:", error);
358
+ else {
351
359
  await a.editReply({
352
- content: "Failed to apply opaque filter: " + error.message,
360
+ content: `Invalid image position. Please select a position between 1 and ${totalAttachments}.`,
353
361
  ephemeral: true,
354
362
  });
355
363
  }
356
364
  }
357
- else {
358
- await a.editReply({
359
- content: `Invalid image position. Please select a position between 1 and ${totalAttachments}.`,
360
- ephemeral: true,
361
- });
362
- }
363
- }
364
- else if (submitId === "Image_GrayScale") {
365
- await a.deferReply({ ephemeral: true });
366
- const imagePosition = parseInt(a.fields.getTextInputValue("Image_Postion"), 10);
367
- const interactionMessage = await a.message.fetch();
368
- const attachmentsArray = Array.from(interactionMessage.attachments.values());
369
- const totalAttachments = attachmentsArray.length;
370
- if (imagePosition >= 1 && imagePosition <= totalAttachments) {
371
- const selectedAttachment = attachmentsArray[imagePosition - 1];
372
- const imageURL = selectedAttachment.url;
373
- try {
374
- const processedBuffer = await apexPainter.processImage(imageURL, [
375
- { type: "greyscale" },
376
- ]);
377
- await a.editReply({
378
- content: "Grayscale Image:",
379
- files: [processedBuffer],
380
- ephemeral: true,
381
- });
365
+ else if (submitId === "Image_GrayScale") {
366
+ await a.deferReply({ ephemeral: true });
367
+ const imagePosition = parseInt(a.fields.getTextInputValue("Image_Postion"), 10);
368
+ const interactionMessage = await a.message.fetch();
369
+ const attachmentsArray = Array.from(interactionMessage.attachments.values());
370
+ const totalAttachments = attachmentsArray.length;
371
+ if (imagePosition >= 1 && imagePosition <= totalAttachments) {
372
+ const selectedAttachment = attachmentsArray[imagePosition - 1];
373
+ const imageURL = selectedAttachment.url;
374
+ try {
375
+ const processedBuffer = await apexPainter.processImage(imageURL, [
376
+ { type: "greyscale" },
377
+ ]);
378
+ await a.editReply({
379
+ content: "Grayscale Image:",
380
+ files: [processedBuffer],
381
+ ephemeral: true,
382
+ });
383
+ }
384
+ catch (error) {
385
+ console.error("Error applying grayscale filter:", error);
386
+ await a.editReply({
387
+ content: "Failed to apply grayscale filter: " + error.message,
388
+ ephemeral: true,
389
+ });
390
+ }
382
391
  }
383
- catch (error) {
384
- console.error("Error applying grayscale filter:", error);
392
+ else {
385
393
  await a.editReply({
386
- content: "Failed to apply grayscale filter: " + error.message,
394
+ content: `Invalid image position. Please select a position between 1 and ${totalAttachments}.`,
387
395
  ephemeral: true,
388
396
  });
389
397
  }
390
398
  }
391
- else {
392
- await a.editReply({
393
- content: `Invalid image position. Please select a position between 1 and ${totalAttachments}.`,
394
- ephemeral: true,
395
- });
396
- }
397
- }
398
- else if (submitId === "Image_Contrast") {
399
- await a.deferReply({ ephemeral: true });
400
- const imagePosition = parseInt(a.fields.getTextInputValue("Image_Postion"), 10);
401
- const interactionMessage = await a.message.fetch();
402
- const attachmentsArray = Array.from(interactionMessage.attachments.values());
403
- const totalAttachments = attachmentsArray.length;
404
- if (imagePosition >= 1 && imagePosition <= totalAttachments) {
405
- const selectedAttachment = attachmentsArray[imagePosition - 1];
406
- const imageURL = selectedAttachment.url;
407
- const contrastValue = a.fields.getTextInputValue("Contrast_Value");
408
- if (contrastValue < 0 || contrastValue > 2) {
409
- return await a.editReply({
410
- content: "Value must be between 0-2",
411
- ephemeral: true,
412
- });
413
- }
414
- try {
415
- const processedBuffer = await apexPainter.processImage(imageURL, [
416
- { type: "contrast", value: parseFloat(contrastValue) },
417
- ]);
418
- await a.editReply({
419
- content: "Contrasted Image:",
420
- files: [processedBuffer],
421
- ephemeral: true,
422
- });
399
+ else if (submitId === "Image_Contrast") {
400
+ await a.deferReply({ ephemeral: true });
401
+ const imagePosition = parseInt(a.fields.getTextInputValue("Image_Postion"), 10);
402
+ const interactionMessage = await a.message.fetch();
403
+ const attachmentsArray = Array.from(interactionMessage.attachments.values());
404
+ const totalAttachments = attachmentsArray.length;
405
+ if (imagePosition >= 1 && imagePosition <= totalAttachments) {
406
+ const selectedAttachment = attachmentsArray[imagePosition - 1];
407
+ const imageURL = selectedAttachment.url;
408
+ const contrastValue = a.fields.getTextInputValue("Contrast_Value");
409
+ if (contrastValue < 0 || contrastValue > 2) {
410
+ return await a.editReply({
411
+ content: "Value must be between 0-2",
412
+ ephemeral: true,
413
+ });
414
+ }
415
+ try {
416
+ const processedBuffer = await apexPainter.processImage(imageURL, [
417
+ { type: "contrast", value: parseFloat(contrastValue) },
418
+ ]);
419
+ await a.editReply({
420
+ content: "Contrasted Image:",
421
+ files: [processedBuffer],
422
+ ephemeral: true,
423
+ });
424
+ }
425
+ catch (error) {
426
+ console.error("Error applying contrast filter:", error);
427
+ await a.editReply({
428
+ content: "Failed to apply contrast filter: " + error.message,
429
+ ephemeral: true,
430
+ });
431
+ }
423
432
  }
424
- catch (error) {
425
- console.error("Error applying contrast filter:", error);
433
+ else {
426
434
  await a.editReply({
427
- content: "Failed to apply contrast filter: " + error.message,
435
+ content: `Invalid image position. Please select a position between 1 and ${totalAttachments}.`,
428
436
  ephemeral: true,
429
437
  });
430
438
  }
431
439
  }
432
- else {
433
- await a.editReply({
434
- content: `Invalid image position. Please select a position between 1 and ${totalAttachments}.`,
435
- ephemeral: true,
436
- });
437
- }
438
440
  }
441
+ catch (error) { }
439
442
  });
440
443
  }
441
444
  exports.filters = filters;