@spatulox/simplediscordbot 2.2.1 → 3.0.0
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/CHANGELOG.md +9 -2
- package/dist/index.d.mts +2 -326
- package/dist/index.d.ts +2 -326
- package/dist/index.js +165 -789
- package/dist/index.mjs +144 -758
- package/package.json +3 -2
package/dist/index.mjs
CHANGED
|
@@ -1,293 +1,8 @@
|
|
|
1
1
|
// src/core/Bot.ts
|
|
2
2
|
import { Events, version } from "discord.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
constructor(val) {
|
|
7
|
-
this.val = val;
|
|
8
|
-
}
|
|
9
|
-
val;
|
|
10
|
-
toMilliseconds() {
|
|
11
|
-
return this.val;
|
|
12
|
-
}
|
|
13
|
-
toSeconds() {
|
|
14
|
-
return this.val / 1e3;
|
|
15
|
-
}
|
|
16
|
-
toMinutes() {
|
|
17
|
-
return this.val / (60 * 1e3);
|
|
18
|
-
}
|
|
19
|
-
toHours() {
|
|
20
|
-
return this.val / (60 * 60 * 1e3);
|
|
21
|
-
}
|
|
22
|
-
toDays() {
|
|
23
|
-
return this.val / (24 * 60 * 60 * 1e3);
|
|
24
|
-
}
|
|
25
|
-
toString() {
|
|
26
|
-
return this.val.toString();
|
|
27
|
-
}
|
|
28
|
-
valueOf() {
|
|
29
|
-
return this.val;
|
|
30
|
-
}
|
|
31
|
-
value() {
|
|
32
|
-
return this.val;
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
var Milliseconds = {
|
|
36
|
-
MS_100: new UnitTime(100),
|
|
37
|
-
MS_200: new UnitTime(200),
|
|
38
|
-
MS_500: new UnitTime(500),
|
|
39
|
-
MS_800: new UnitTime(800),
|
|
40
|
-
MS_1000: new UnitTime(1e3)
|
|
41
|
-
};
|
|
42
|
-
var Seconds = {
|
|
43
|
-
SEC_01: new UnitTime(1e3),
|
|
44
|
-
SEC_02: new UnitTime(2e3),
|
|
45
|
-
SEC_03: new UnitTime(3e3),
|
|
46
|
-
SEC_04: new UnitTime(4e3),
|
|
47
|
-
SEC_05: new UnitTime(5e3),
|
|
48
|
-
SEC_06: new UnitTime(6e3),
|
|
49
|
-
SEC_07: new UnitTime(7e3),
|
|
50
|
-
SEC_08: new UnitTime(8e3),
|
|
51
|
-
SEC_09: new UnitTime(9e3),
|
|
52
|
-
SEC_10: new UnitTime(1e4),
|
|
53
|
-
SEC_11: new UnitTime(11e3),
|
|
54
|
-
SEC_12: new UnitTime(12e3),
|
|
55
|
-
SEC_13: new UnitTime(13e3),
|
|
56
|
-
SEC_14: new UnitTime(14e3),
|
|
57
|
-
SEC_15: new UnitTime(15e3),
|
|
58
|
-
SEC_16: new UnitTime(16e3),
|
|
59
|
-
SEC_17: new UnitTime(17e3),
|
|
60
|
-
SEC_18: new UnitTime(18e3),
|
|
61
|
-
SEC_19: new UnitTime(19e3),
|
|
62
|
-
SEC_20: new UnitTime(2e4),
|
|
63
|
-
SEC_21: new UnitTime(21e3),
|
|
64
|
-
SEC_22: new UnitTime(22e3),
|
|
65
|
-
SEC_23: new UnitTime(23e3),
|
|
66
|
-
SEC_24: new UnitTime(24e3),
|
|
67
|
-
SEC_25: new UnitTime(25e3),
|
|
68
|
-
SEC_26: new UnitTime(26e3),
|
|
69
|
-
SEC_27: new UnitTime(27e3),
|
|
70
|
-
SEC_28: new UnitTime(28e3),
|
|
71
|
-
SEC_29: new UnitTime(29e3),
|
|
72
|
-
SEC_30: new UnitTime(3e4),
|
|
73
|
-
SEC_31: new UnitTime(31e3),
|
|
74
|
-
SEC_32: new UnitTime(32e3),
|
|
75
|
-
SEC_33: new UnitTime(33e3),
|
|
76
|
-
SEC_34: new UnitTime(34e3),
|
|
77
|
-
SEC_35: new UnitTime(35e3),
|
|
78
|
-
SEC_36: new UnitTime(36e3),
|
|
79
|
-
SEC_37: new UnitTime(37e3),
|
|
80
|
-
SEC_38: new UnitTime(38e3),
|
|
81
|
-
SEC_39: new UnitTime(39e3),
|
|
82
|
-
SEC_40: new UnitTime(4e4),
|
|
83
|
-
SEC_41: new UnitTime(41e3),
|
|
84
|
-
SEC_42: new UnitTime(42e3),
|
|
85
|
-
SEC_43: new UnitTime(43e3),
|
|
86
|
-
SEC_44: new UnitTime(44e3),
|
|
87
|
-
SEC_45: new UnitTime(45e3),
|
|
88
|
-
SEC_46: new UnitTime(46e3),
|
|
89
|
-
SEC_47: new UnitTime(47e3),
|
|
90
|
-
SEC_48: new UnitTime(48e3),
|
|
91
|
-
SEC_49: new UnitTime(49e3),
|
|
92
|
-
SEC_50: new UnitTime(5e4),
|
|
93
|
-
SEC_51: new UnitTime(51e3),
|
|
94
|
-
SEC_52: new UnitTime(52e3),
|
|
95
|
-
SEC_53: new UnitTime(53e3),
|
|
96
|
-
SEC_54: new UnitTime(54e3),
|
|
97
|
-
SEC_55: new UnitTime(55e3),
|
|
98
|
-
SEC_56: new UnitTime(56e3),
|
|
99
|
-
SEC_57: new UnitTime(57e3),
|
|
100
|
-
SEC_58: new UnitTime(58e3),
|
|
101
|
-
SEC_59: new UnitTime(59e3),
|
|
102
|
-
SEC_60: new UnitTime(6e4)
|
|
103
|
-
};
|
|
104
|
-
var Minutes = {
|
|
105
|
-
MIN_01: new UnitTime(6e4),
|
|
106
|
-
MIN_02: new UnitTime(12e4),
|
|
107
|
-
MIN_03: new UnitTime(18e4),
|
|
108
|
-
MIN_04: new UnitTime(24e4),
|
|
109
|
-
MIN_05: new UnitTime(3e5),
|
|
110
|
-
MIN_06: new UnitTime(36e4),
|
|
111
|
-
MIN_07: new UnitTime(42e4),
|
|
112
|
-
MIN_08: new UnitTime(48e4),
|
|
113
|
-
MIN_09: new UnitTime(54e4),
|
|
114
|
-
MIN_10: new UnitTime(6e5),
|
|
115
|
-
MIN_11: new UnitTime(66e4),
|
|
116
|
-
MIN_12: new UnitTime(72e4),
|
|
117
|
-
MIN_13: new UnitTime(78e4),
|
|
118
|
-
MIN_14: new UnitTime(84e4),
|
|
119
|
-
MIN_15: new UnitTime(9e5),
|
|
120
|
-
MIN_16: new UnitTime(96e4),
|
|
121
|
-
MIN_17: new UnitTime(102e4),
|
|
122
|
-
MIN_18: new UnitTime(108e4),
|
|
123
|
-
MIN_19: new UnitTime(114e4),
|
|
124
|
-
MIN_20: new UnitTime(12e5),
|
|
125
|
-
MIN_21: new UnitTime(126e4),
|
|
126
|
-
MIN_22: new UnitTime(132e4),
|
|
127
|
-
MIN_23: new UnitTime(138e4),
|
|
128
|
-
MIN_24: new UnitTime(144e4),
|
|
129
|
-
MIN_25: new UnitTime(15e5),
|
|
130
|
-
MIN_26: new UnitTime(156e4),
|
|
131
|
-
MIN_27: new UnitTime(162e4),
|
|
132
|
-
MIN_28: new UnitTime(168e4),
|
|
133
|
-
MIN_29: new UnitTime(174e4),
|
|
134
|
-
MIN_30: new UnitTime(18e5),
|
|
135
|
-
MIN_31: new UnitTime(186e4),
|
|
136
|
-
MIN_32: new UnitTime(192e4),
|
|
137
|
-
MIN_33: new UnitTime(198e4),
|
|
138
|
-
MIN_34: new UnitTime(204e4),
|
|
139
|
-
MIN_35: new UnitTime(21e5),
|
|
140
|
-
MIN_36: new UnitTime(216e4),
|
|
141
|
-
MIN_37: new UnitTime(222e4),
|
|
142
|
-
MIN_38: new UnitTime(228e4),
|
|
143
|
-
MIN_39: new UnitTime(234e4),
|
|
144
|
-
MIN_40: new UnitTime(24e5),
|
|
145
|
-
MIN_41: new UnitTime(246e4),
|
|
146
|
-
MIN_42: new UnitTime(252e4),
|
|
147
|
-
MIN_43: new UnitTime(258e4),
|
|
148
|
-
MIN_44: new UnitTime(264e4),
|
|
149
|
-
MIN_45: new UnitTime(27e5),
|
|
150
|
-
MIN_46: new UnitTime(276e4),
|
|
151
|
-
MIN_47: new UnitTime(282e4),
|
|
152
|
-
MIN_48: new UnitTime(288e4),
|
|
153
|
-
MIN_49: new UnitTime(294e4),
|
|
154
|
-
MIN_50: new UnitTime(3e6),
|
|
155
|
-
MIN_51: new UnitTime(306e4),
|
|
156
|
-
MIN_52: new UnitTime(312e4),
|
|
157
|
-
MIN_53: new UnitTime(318e4),
|
|
158
|
-
MIN_54: new UnitTime(324e4),
|
|
159
|
-
MIN_55: new UnitTime(33e5),
|
|
160
|
-
MIN_56: new UnitTime(336e4),
|
|
161
|
-
MIN_57: new UnitTime(342e4),
|
|
162
|
-
MIN_58: new UnitTime(348e4),
|
|
163
|
-
MIN_59: new UnitTime(354e4),
|
|
164
|
-
MIN_60: new UnitTime(36e5)
|
|
165
|
-
};
|
|
166
|
-
var Hours = {
|
|
167
|
-
HOUR_01: new UnitTime(36e5),
|
|
168
|
-
HOUR_02: new UnitTime(72e5),
|
|
169
|
-
HOUR_03: new UnitTime(108e5),
|
|
170
|
-
HOUR_04: new UnitTime(144e5),
|
|
171
|
-
HOUR_05: new UnitTime(18e6),
|
|
172
|
-
HOUR_06: new UnitTime(216e5),
|
|
173
|
-
HOUR_07: new UnitTime(252e5),
|
|
174
|
-
HOUR_08: new UnitTime(288e5),
|
|
175
|
-
HOUR_09: new UnitTime(324e5),
|
|
176
|
-
HOUR_10: new UnitTime(36e6),
|
|
177
|
-
HOUR_11: new UnitTime(396e5),
|
|
178
|
-
HOUR_12: new UnitTime(432e5),
|
|
179
|
-
HOUR_13: new UnitTime(468e5),
|
|
180
|
-
HOUR_14: new UnitTime(504e5),
|
|
181
|
-
HOUR_15: new UnitTime(54e6),
|
|
182
|
-
HOUR_16: new UnitTime(576e5),
|
|
183
|
-
HOUR_17: new UnitTime(612e5),
|
|
184
|
-
HOUR_18: new UnitTime(648e5),
|
|
185
|
-
HOUR_19: new UnitTime(684e5),
|
|
186
|
-
HOUR_20: new UnitTime(72e6),
|
|
187
|
-
HOUR_21: new UnitTime(756e5),
|
|
188
|
-
HOUR_22: new UnitTime(792e5),
|
|
189
|
-
HOUR_23: new UnitTime(828e5),
|
|
190
|
-
HOUR_24: new UnitTime(864e5)
|
|
191
|
-
};
|
|
192
|
-
var Days = {
|
|
193
|
-
DAY_01: new UnitTime(864e5),
|
|
194
|
-
DAY_02: new UnitTime(1728e5),
|
|
195
|
-
DAY_03: new UnitTime(2592e5),
|
|
196
|
-
DAY_04: new UnitTime(3456e5),
|
|
197
|
-
DAY_05: new UnitTime(432e6),
|
|
198
|
-
DAY_06: new UnitTime(5184e5),
|
|
199
|
-
DAY_07: new UnitTime(6048e5),
|
|
200
|
-
DAY_08: new UnitTime(6912e5),
|
|
201
|
-
DAY_09: new UnitTime(7776e5),
|
|
202
|
-
DAY_10: new UnitTime(864e6)
|
|
203
|
-
};
|
|
204
|
-
var Time = {
|
|
205
|
-
milisecond: Milliseconds,
|
|
206
|
-
second: Seconds,
|
|
207
|
-
minute: Minutes,
|
|
208
|
-
hour: Hours,
|
|
209
|
-
day: Days,
|
|
210
|
-
get DAY() {
|
|
211
|
-
const h = (/* @__PURE__ */ new Date()).getHours();
|
|
212
|
-
return h >= 7 && h < 23;
|
|
213
|
-
},
|
|
214
|
-
get NIGHT() {
|
|
215
|
-
return !this.DAY;
|
|
216
|
-
}
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
// src/utils/Log.ts
|
|
220
|
-
var Log = class {
|
|
221
|
-
static getPrefix(level) {
|
|
222
|
-
const now = /* @__PURE__ */ new Date();
|
|
223
|
-
const timestamp = `[${now.toLocaleDateString()} - ${now.toLocaleTimeString()}]`;
|
|
224
|
-
return `${timestamp} [${level.toUpperCase()}]`;
|
|
225
|
-
}
|
|
226
|
-
static info(message) {
|
|
227
|
-
console.info(`${this.getPrefix("info")} ${message}`);
|
|
228
|
-
}
|
|
229
|
-
static warn(message) {
|
|
230
|
-
console.warn(`${this.getPrefix("warn")} ${message}`);
|
|
231
|
-
}
|
|
232
|
-
static error(message) {
|
|
233
|
-
console.error(`${this.getPrefix("error")} ${message}`);
|
|
234
|
-
}
|
|
235
|
-
static debug(message) {
|
|
236
|
-
console.debug(`${this.getPrefix("debug")} ${message}`);
|
|
237
|
-
}
|
|
238
|
-
static table(data) {
|
|
239
|
-
const prefix = this.getPrefix("table");
|
|
240
|
-
console.info(`${prefix} Table output:`);
|
|
241
|
-
console.table(data);
|
|
242
|
-
}
|
|
243
|
-
};
|
|
244
|
-
|
|
245
|
-
// src/utils/InternetChecker.ts
|
|
246
|
-
var InternetChecker = class {
|
|
247
|
-
static TARGET = "https://one.one.one.one/";
|
|
248
|
-
// Cloudflare DNS HTTPS
|
|
249
|
-
static RETRY_TIME = Time.second.SEC_30;
|
|
250
|
-
/**
|
|
251
|
-
* Check internet connection towards 1.1.1.1 (Cloudflare DNS)
|
|
252
|
-
* @param tries Number of attempts (0 = infini)
|
|
253
|
-
*/
|
|
254
|
-
static async checkConnection(tries = 0) {
|
|
255
|
-
let attempt = 0;
|
|
256
|
-
Log.info(
|
|
257
|
-
tries > 0 ? `HTTP ping ${this.TARGET} (max ${tries} attempts)...` : `HTTP ping ${this.TARGET} (infinite attempts)...`
|
|
258
|
-
);
|
|
259
|
-
while (tries === 0 || attempt < tries) {
|
|
260
|
-
try {
|
|
261
|
-
const controller = new AbortController();
|
|
262
|
-
const timeoutId = setTimeout(() => controller.abort(), 5e3);
|
|
263
|
-
const response = await fetch(this.TARGET, {
|
|
264
|
-
method: "HEAD",
|
|
265
|
-
signal: controller.signal,
|
|
266
|
-
cache: "no-store"
|
|
267
|
-
});
|
|
268
|
-
clearTimeout(timeoutId);
|
|
269
|
-
if (response.ok) {
|
|
270
|
-
const latency = response.headers.get("x-response-time") || "<1ms";
|
|
271
|
-
Log.info(`Internet connection OK (${latency})`);
|
|
272
|
-
return true;
|
|
273
|
-
}
|
|
274
|
-
} catch (error) {
|
|
275
|
-
attempt++;
|
|
276
|
-
const errorMsg = error.name === "AbortError" ? "Timeout (5s)" : error.message || "Unknown";
|
|
277
|
-
Log.warn(
|
|
278
|
-
tries > 0 ? `Ping failed (${errorMsg}) - Attempt ${attempt}/${tries}` : `Ping failed (${errorMsg}) - Retrying in ${this.RETRY_TIME.toSeconds()} seconds...`
|
|
279
|
-
);
|
|
280
|
-
try {
|
|
281
|
-
await new Promise((resolve2) => setTimeout(resolve2, this.RETRY_TIME.toMilliseconds()));
|
|
282
|
-
} catch {
|
|
283
|
-
Log.error("Retry delay failed.");
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
Log.error(`No response from ${this.TARGET} after all attempts.`);
|
|
288
|
-
return false;
|
|
289
|
-
}
|
|
290
|
-
};
|
|
3
|
+
import { Time } from "@spatulox/utils";
|
|
4
|
+
import { Log as Log3 } from "@spatulox/utils";
|
|
5
|
+
import { InternetChecker } from "@spatulox/utils";
|
|
291
6
|
|
|
292
7
|
// src/core/BotLog.ts
|
|
293
8
|
import {
|
|
@@ -296,6 +11,7 @@ import {
|
|
|
296
11
|
ContainerBuilder,
|
|
297
12
|
MessageFlags as MessageFlags2
|
|
298
13
|
} from "discord.js";
|
|
14
|
+
import { Log } from "@spatulox/utils";
|
|
299
15
|
|
|
300
16
|
// src/manager/interactible/SelectMenuManager.ts
|
|
301
17
|
import {
|
|
@@ -783,6 +499,7 @@ import {
|
|
|
783
499
|
User,
|
|
784
500
|
GuildMember
|
|
785
501
|
} from "discord.js";
|
|
502
|
+
import { Log as Log2 } from "@spatulox/utils";
|
|
786
503
|
|
|
787
504
|
// src/manager/builder/SendableComponentBuilder.ts
|
|
788
505
|
import {
|
|
@@ -853,13 +570,13 @@ var BotMessage = class {
|
|
|
853
570
|
static async send(channel, content, component) {
|
|
854
571
|
try {
|
|
855
572
|
if (!channel) {
|
|
856
|
-
|
|
573
|
+
Log2.warn("Cannot send message: Invalid channel ID");
|
|
857
574
|
return null;
|
|
858
575
|
}
|
|
859
576
|
if (typeof channel === "string") {
|
|
860
577
|
const fetchedChannel = Bot.client.channels.cache.get(channel);
|
|
861
578
|
if (!fetchedChannel?.isTextBased()) {
|
|
862
|
-
|
|
579
|
+
Log2.warn(`Cannot send message : Invalid channel ID: ${channel}`);
|
|
863
580
|
return null;
|
|
864
581
|
}
|
|
865
582
|
channel = fetchedChannel;
|
|
@@ -889,14 +606,14 @@ var BotMessage = class {
|
|
|
889
606
|
throw e;
|
|
890
607
|
}
|
|
891
608
|
} catch (e) {
|
|
892
|
-
|
|
609
|
+
Log2.error(`Cannot send message : ${e}`);
|
|
893
610
|
return null;
|
|
894
611
|
}
|
|
895
612
|
}
|
|
896
613
|
static async sendDM(userOrId, content, component) {
|
|
897
614
|
try {
|
|
898
615
|
if (!userOrId) {
|
|
899
|
-
|
|
616
|
+
Log2.warn("Cannot send DM: Invalid user / ID");
|
|
900
617
|
return null;
|
|
901
618
|
}
|
|
902
619
|
let targetUser;
|
|
@@ -905,7 +622,7 @@ var BotMessage = class {
|
|
|
905
622
|
} else {
|
|
906
623
|
const fetchedUser = await Bot.client.users.fetch(userOrId);
|
|
907
624
|
if (!fetchedUser) {
|
|
908
|
-
|
|
625
|
+
Log2.warn(`Cannot send DM: User not found for ID: ${userOrId}`);
|
|
909
626
|
return null;
|
|
910
627
|
}
|
|
911
628
|
targetUser = fetchedUser;
|
|
@@ -922,7 +639,7 @@ var BotMessage = class {
|
|
|
922
639
|
}
|
|
923
640
|
return await targetUser.send(messageCreate);
|
|
924
641
|
} catch (error) {
|
|
925
|
-
|
|
642
|
+
Log2.error(`Cannot send DM to ${userOrId}: ${error}`);
|
|
926
643
|
return null;
|
|
927
644
|
}
|
|
928
645
|
}
|
|
@@ -1026,7 +743,7 @@ var BotInteraction = class {
|
|
|
1026
743
|
// package.json
|
|
1027
744
|
var package_default = {
|
|
1028
745
|
name: "@spatulox/simplediscordbot",
|
|
1029
|
-
version: "2.2.
|
|
746
|
+
version: "2.2.2",
|
|
1030
747
|
author: "Spatulox",
|
|
1031
748
|
description: "Simple discord bot framework to set up a bot under 30 secondes",
|
|
1032
749
|
exports: {
|
|
@@ -1048,7 +765,8 @@ var package_default = {
|
|
|
1048
765
|
},
|
|
1049
766
|
license: "MIT",
|
|
1050
767
|
dependencies: {
|
|
1051
|
-
"@spatulox/discord-interaction-manager": "^2.0.6"
|
|
768
|
+
"@spatulox/discord-interaction-manager": "^2.0.6",
|
|
769
|
+
"@spatulox/utils": "^0.1.1"
|
|
1052
770
|
},
|
|
1053
771
|
peerDependencies: {
|
|
1054
772
|
"discord.js": "^14.26.0"
|
|
@@ -1108,15 +826,15 @@ var Bot = class _Bot {
|
|
|
1108
826
|
return _Bot._config;
|
|
1109
827
|
}
|
|
1110
828
|
constructor(client, config = {}) {
|
|
1111
|
-
|
|
1112
|
-
|
|
829
|
+
Log3.info("----------------------------------------------------");
|
|
830
|
+
Log3.info("Starting Bot");
|
|
1113
831
|
_Bot.criticConfig = { dev: BotEnv.dev, token: BotEnv.token };
|
|
1114
832
|
_Bot._config = config;
|
|
1115
833
|
_Bot._client = client;
|
|
1116
834
|
(async () => {
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
835
|
+
Log3.info(`Using discord.js version: ${version}`);
|
|
836
|
+
Log3.info(`Using simplediscordbot version: ${SimpleDiscordBotInfo.version}`);
|
|
837
|
+
Log3.info("Trying to connect to Discord Servers");
|
|
1120
838
|
await InternetChecker.checkConnection(3);
|
|
1121
839
|
await this.login();
|
|
1122
840
|
})();
|
|
@@ -1131,12 +849,12 @@ var Bot = class _Bot {
|
|
|
1131
849
|
_Bot._client.on(Events.ClientReady, async () => {
|
|
1132
850
|
if (_Bot._client.user) {
|
|
1133
851
|
await _Bot.log.initDiscordLogging();
|
|
1134
|
-
|
|
852
|
+
Log3.info(`Connected on ${_Bot._client.guilds.cache.size} servers as ${_Bot._client.user.tag}`);
|
|
1135
853
|
_Bot.log.info(EmbedManager.description("Bot Started"));
|
|
1136
854
|
}
|
|
1137
855
|
});
|
|
1138
856
|
} catch (error) {
|
|
1139
|
-
|
|
857
|
+
Log3.error(`Connection error : ${error}. Trying again...`);
|
|
1140
858
|
tries++;
|
|
1141
859
|
await new Promise(
|
|
1142
860
|
(resolve2) => setTimeout(resolve2, Time.second.SEC_03.toMilliseconds())
|
|
@@ -1144,7 +862,7 @@ var Bot = class _Bot {
|
|
|
1144
862
|
}
|
|
1145
863
|
}
|
|
1146
864
|
if (!success) {
|
|
1147
|
-
|
|
865
|
+
Log3.error("Impossible to connect the bot after 3 attempts");
|
|
1148
866
|
return false;
|
|
1149
867
|
}
|
|
1150
868
|
return true;
|
|
@@ -1152,12 +870,12 @@ var Bot = class _Bot {
|
|
|
1152
870
|
static setActivity(message, type) {
|
|
1153
871
|
if (_Bot._client.user) {
|
|
1154
872
|
_Bot._client.user.setActivity({ name: message, type });
|
|
1155
|
-
|
|
873
|
+
Log3.info(`Activity defined : ${message}`);
|
|
1156
874
|
}
|
|
1157
875
|
}
|
|
1158
876
|
static setRandomActivity(randomActivity, intervalMs = null) {
|
|
1159
877
|
if (randomActivity.length == 0) {
|
|
1160
|
-
|
|
878
|
+
Log3.error("Bot.randomActivity = [{}] is empty");
|
|
1161
879
|
return;
|
|
1162
880
|
}
|
|
1163
881
|
const pickRandom = () => {
|
|
@@ -1167,335 +885,21 @@ var Bot = class _Bot {
|
|
|
1167
885
|
};
|
|
1168
886
|
if (intervalMs === null) {
|
|
1169
887
|
pickRandom();
|
|
1170
|
-
|
|
888
|
+
Log3.info(`Activity set ONCE`);
|
|
1171
889
|
return;
|
|
1172
890
|
}
|
|
1173
891
|
pickRandom();
|
|
1174
892
|
setInterval(async () => {
|
|
1175
893
|
pickRandom();
|
|
1176
894
|
}, intervalMs);
|
|
1177
|
-
|
|
895
|
+
Log3.info(`Random activity started (every ${Math.round(intervalMs / 6e4)}min)`);
|
|
1178
896
|
return;
|
|
1179
897
|
}
|
|
1180
898
|
};
|
|
1181
899
|
|
|
1182
|
-
// src/
|
|
1183
|
-
import
|
|
1184
|
-
import
|
|
1185
|
-
var FileManager = class {
|
|
1186
|
-
/**
|
|
1187
|
-
* Check if a file exist
|
|
1188
|
-
* @param filePath File path with file name
|
|
1189
|
-
* @returns true si le fichier existe, false sinon
|
|
1190
|
-
*/
|
|
1191
|
-
static async fileExists(filePath) {
|
|
1192
|
-
try {
|
|
1193
|
-
await fs.access(filePath);
|
|
1194
|
-
return true;
|
|
1195
|
-
} catch {
|
|
1196
|
-
return false;
|
|
1197
|
-
}
|
|
1198
|
-
}
|
|
1199
|
-
/**
|
|
1200
|
-
* Reads a JSON file synchronously.
|
|
1201
|
-
* @param filePath Full path to the JSON file
|
|
1202
|
-
* @returns Parsed JSON object or 'Error' string on failure
|
|
1203
|
-
*/
|
|
1204
|
-
static async readJsonFile(filePath) {
|
|
1205
|
-
try {
|
|
1206
|
-
const data = await fs.readFile(filePath, "utf8");
|
|
1207
|
-
return JSON.parse(data);
|
|
1208
|
-
} catch (error) {
|
|
1209
|
-
Log.error(`Failed to read JSON file ${filePath}: ${error}`);
|
|
1210
|
-
return false;
|
|
1211
|
-
}
|
|
1212
|
-
}
|
|
1213
|
-
/**
|
|
1214
|
-
* Lists all directories in a given path.
|
|
1215
|
-
* @param directoryPath Path to scan for directories
|
|
1216
|
-
* @returns Array of directory names or false on error
|
|
1217
|
-
*/
|
|
1218
|
-
static async listDirectories(directoryPath) {
|
|
1219
|
-
try {
|
|
1220
|
-
const files = await fs.readdir(directoryPath, { withFileTypes: true });
|
|
1221
|
-
return files.filter((file) => file.isDirectory()).map((dir) => dir.name);
|
|
1222
|
-
} catch (error) {
|
|
1223
|
-
Log.error(`Failed to read directory ${directoryPath}: ${error}`);
|
|
1224
|
-
return false;
|
|
1225
|
-
}
|
|
1226
|
-
}
|
|
1227
|
-
/**
|
|
1228
|
-
* Lists all JSON files in a directory.
|
|
1229
|
-
* @param directoryPath Path to scan for JSON files
|
|
1230
|
-
* @returns Array of JSON filenames or false on error
|
|
1231
|
-
*/
|
|
1232
|
-
static async listJsonFiles(directoryPath) {
|
|
1233
|
-
try {
|
|
1234
|
-
const files = await fs.readdir(directoryPath);
|
|
1235
|
-
return files.filter((file) => path.extname(file) === ".json");
|
|
1236
|
-
} catch (error) {
|
|
1237
|
-
Log.error(`Failed to read directory ${directoryPath}: ${error}`);
|
|
1238
|
-
return false;
|
|
1239
|
-
}
|
|
1240
|
-
}
|
|
1241
|
-
/**
|
|
1242
|
-
* Lists files with specific extension in a directory.
|
|
1243
|
-
* @param directoryPath Path to scan
|
|
1244
|
-
* @param extension File extension (with or without dot)
|
|
1245
|
-
* @returns Array of matching filenames or 'Error' string on failure
|
|
1246
|
-
*/
|
|
1247
|
-
static async listFiles(directoryPath, extension) {
|
|
1248
|
-
if (typeof directoryPath !== "string" || typeof extension !== "string") {
|
|
1249
|
-
Log.error("Directory path and extension must be strings");
|
|
1250
|
-
return false;
|
|
1251
|
-
}
|
|
1252
|
-
try {
|
|
1253
|
-
let ext = extension;
|
|
1254
|
-
if (ext.startsWith(".")) {
|
|
1255
|
-
ext = ext.slice(1);
|
|
1256
|
-
}
|
|
1257
|
-
const files = await fs.readdir(directoryPath);
|
|
1258
|
-
return files.filter((file) => path.extname(file) === `.${ext}`);
|
|
1259
|
-
} catch (error) {
|
|
1260
|
-
Log.error(`Failed to read directory ${directoryPath}: ${error}`);
|
|
1261
|
-
return false;
|
|
1262
|
-
}
|
|
1263
|
-
}
|
|
1264
|
-
/**
|
|
1265
|
-
* Creates directory structure and writes JSON data to file.
|
|
1266
|
-
* @param directoryPath Full directory path (creates if missing)
|
|
1267
|
-
* @param filename Filename without extension
|
|
1268
|
-
* @param data Data to write (JSON serializable)
|
|
1269
|
-
* @param sendErrorToErrorChannel Send error to the error channel
|
|
1270
|
-
* @returns true on success, false on failure
|
|
1271
|
-
*/
|
|
1272
|
-
static async writeJsonFile(directoryPath, filename, data, sendErrorToErrorChannel = true) {
|
|
1273
|
-
if (Array.isArray(data) && data.length === 1 && data[0] === "Error") {
|
|
1274
|
-
Log.error(`Cannot save data for ${filename}: data contains 'Error'`);
|
|
1275
|
-
return false;
|
|
1276
|
-
}
|
|
1277
|
-
try {
|
|
1278
|
-
await fs.mkdir(directoryPath, { recursive: true });
|
|
1279
|
-
if (!filename || filename.trim() === "") {
|
|
1280
|
-
Log.error("Cannot write JSON file: empty filename");
|
|
1281
|
-
return false;
|
|
1282
|
-
}
|
|
1283
|
-
const cleanFilename = filename.replace(/\.json$/i, "");
|
|
1284
|
-
const filePath = path.join(directoryPath, `${cleanFilename}.json`);
|
|
1285
|
-
const jsonContent = JSON.stringify(data, null, 2);
|
|
1286
|
-
await fs.writeFile(filePath, jsonContent);
|
|
1287
|
-
Log.info(`Successfully wrote data to ${filePath}`);
|
|
1288
|
-
return true;
|
|
1289
|
-
} catch (error) {
|
|
1290
|
-
const cleanFilename = filename.replace(/\.json$/i, "") || "unknown";
|
|
1291
|
-
if (sendErrorToErrorChannel) {
|
|
1292
|
-
await Bot.log.info(EmbedManager.error(`Failed to write file ${directoryPath}/${cleanFilename}.json: ${error}`));
|
|
1293
|
-
} else {
|
|
1294
|
-
Log.error(`Failed to write file ${directoryPath}/${cleanFilename}.json: ${error}`);
|
|
1295
|
-
}
|
|
1296
|
-
return false;
|
|
1297
|
-
}
|
|
1298
|
-
}
|
|
1299
|
-
/**
|
|
1300
|
-
* Delete a file
|
|
1301
|
-
* @param filePath Full file path
|
|
1302
|
-
* @returns true si supprimé avec succès, false sinon
|
|
1303
|
-
*/
|
|
1304
|
-
static async deleteFile(filePath) {
|
|
1305
|
-
try {
|
|
1306
|
-
if (!await this.fileExists(filePath)) {
|
|
1307
|
-
Log.warn(`File does not exist: ${filePath}`);
|
|
1308
|
-
return false;
|
|
1309
|
-
}
|
|
1310
|
-
await fs.unlink(filePath);
|
|
1311
|
-
Log.info(`Successfully deleted file: ${filePath}`);
|
|
1312
|
-
return true;
|
|
1313
|
-
} catch (error) {
|
|
1314
|
-
Log.error(`Failed to delete file ${filePath}: ${error}`);
|
|
1315
|
-
return false;
|
|
1316
|
-
}
|
|
1317
|
-
}
|
|
1318
|
-
};
|
|
1319
|
-
|
|
1320
|
-
// src/manager/CacheManager.ts
|
|
1321
|
-
import path2 from "path";
|
|
1322
|
-
var CacheManager = class {
|
|
1323
|
-
static get cacheDir() {
|
|
1324
|
-
let folderPath = "simplediscordbot";
|
|
1325
|
-
if (Bot.config?.botName) {
|
|
1326
|
-
folderPath = this.cleanCacheId(Bot.config?.botName?.toLowerCase()).replace(" ", "_");
|
|
1327
|
-
}
|
|
1328
|
-
return path2.join(process.cwd(), `.${folderPath}cache`);
|
|
1329
|
-
}
|
|
1330
|
-
static cleanCacheId(key) {
|
|
1331
|
-
return key.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
1332
|
-
}
|
|
1333
|
-
static createFilePath(filename) {
|
|
1334
|
-
return path2.join(this.cacheDir, `${filename}.json`);
|
|
1335
|
-
}
|
|
1336
|
-
/**
|
|
1337
|
-
* New file with cache_id as name
|
|
1338
|
-
* @param cache_id - id which become the cache file name
|
|
1339
|
-
* @param initialData - optional initial data
|
|
1340
|
-
* @returns true if success, false otherwise
|
|
1341
|
-
*/
|
|
1342
|
-
static async createCache(cache_id, initialData = {}) {
|
|
1343
|
-
if (!cache_id || typeof cache_id !== "string" || cache_id.trim() === "") {
|
|
1344
|
-
Bot.log.error('"Key" to create a cache must be a non-empty string');
|
|
1345
|
-
return false;
|
|
1346
|
-
}
|
|
1347
|
-
const cleanCacheId = cache_id.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
1348
|
-
Bot.log.info(`Creating cache file: ${cleanCacheId}.json`);
|
|
1349
|
-
return await FileManager.writeJsonFile(
|
|
1350
|
-
this.cacheDir,
|
|
1351
|
-
this.cleanCacheId(cache_id),
|
|
1352
|
-
initialData,
|
|
1353
|
-
true
|
|
1354
|
-
);
|
|
1355
|
-
}
|
|
1356
|
-
/**
|
|
1357
|
-
* Read cache data or create empty one
|
|
1358
|
-
* @param cache_id
|
|
1359
|
-
* @param default_data default data with default key/value This will be send back if the cache doesn't exist and need to be created
|
|
1360
|
-
* @returns true if success, false otherwise
|
|
1361
|
-
*/
|
|
1362
|
-
static async getOrCreateCache(cache_id, default_data) {
|
|
1363
|
-
if (!cache_id || typeof cache_id !== "string" || cache_id.trim() === "") {
|
|
1364
|
-
Log.error('"cache_id" to get or create a cache must be a non-empty string');
|
|
1365
|
-
return false;
|
|
1366
|
-
}
|
|
1367
|
-
const cleanCacheId = this.cleanCacheId(cache_id);
|
|
1368
|
-
const filePath = this.createFilePath(cleanCacheId);
|
|
1369
|
-
if (await FileManager.fileExists(filePath)) {
|
|
1370
|
-
Log.info(`Cache already exists: ${cleanCacheId}.json`);
|
|
1371
|
-
return FileManager.readJsonFile(filePath);
|
|
1372
|
-
}
|
|
1373
|
-
Log.info(`Creating new cache file: ${this.cacheDir}/${cleanCacheId}.json`);
|
|
1374
|
-
const res = await FileManager.writeJsonFile(
|
|
1375
|
-
this.cacheDir,
|
|
1376
|
-
cleanCacheId,
|
|
1377
|
-
default_data,
|
|
1378
|
-
false
|
|
1379
|
-
);
|
|
1380
|
-
return res ? default_data : false;
|
|
1381
|
-
}
|
|
1382
|
-
/**
|
|
1383
|
-
* Read cache data
|
|
1384
|
-
* @param cache_id - cache_id to read
|
|
1385
|
-
* @returns Json data, false otherwise
|
|
1386
|
-
*/
|
|
1387
|
-
static async readCache(cache_id) {
|
|
1388
|
-
if (!cache_id || typeof cache_id !== "string") {
|
|
1389
|
-
Bot.log.error('"Key" must be a string');
|
|
1390
|
-
return false;
|
|
1391
|
-
}
|
|
1392
|
-
const cleanCacheId = this.cleanCacheId(cache_id);
|
|
1393
|
-
const filePath = this.createFilePath(cleanCacheId);
|
|
1394
|
-
if (!await FileManager.fileExists(filePath)) {
|
|
1395
|
-
Log.debug(`Cache not found: ${cleanCacheId}.json`);
|
|
1396
|
-
return false;
|
|
1397
|
-
}
|
|
1398
|
-
return await FileManager.readJsonFile(filePath);
|
|
1399
|
-
}
|
|
1400
|
-
/**
|
|
1401
|
-
* Overwrite cache data with the new data
|
|
1402
|
-
* @param cache_id - ID of the cache
|
|
1403
|
-
* @param data - new data
|
|
1404
|
-
* @returns true if success, false otherwise
|
|
1405
|
-
*/
|
|
1406
|
-
static async writeCache(cache_id, data) {
|
|
1407
|
-
if (!cache_id || typeof cache_id !== "string") {
|
|
1408
|
-
Log.error("Cache ID must be a string");
|
|
1409
|
-
return false;
|
|
1410
|
-
}
|
|
1411
|
-
const cleanCacheId = this.cleanCacheId(cache_id);
|
|
1412
|
-
Bot.log.info(`Writing to cache: ${cleanCacheId}.json`);
|
|
1413
|
-
return await FileManager.writeJsonFile(
|
|
1414
|
-
this.cacheDir,
|
|
1415
|
-
cleanCacheId,
|
|
1416
|
-
data,
|
|
1417
|
-
true
|
|
1418
|
-
);
|
|
1419
|
-
}
|
|
1420
|
-
/**
|
|
1421
|
-
* Update specific property of the cache
|
|
1422
|
-
* @param cache_id - ID of the cache
|
|
1423
|
-
* @param property - property to update, with key and value
|
|
1424
|
-
* @returns true if success, false otherwise
|
|
1425
|
-
*/
|
|
1426
|
-
static async updateCacheProperty(cache_id, property) {
|
|
1427
|
-
const cacheData = await this.readCache(cache_id);
|
|
1428
|
-
if (cacheData === false) {
|
|
1429
|
-
Log.error(`Cache ${cache_id} not found`);
|
|
1430
|
-
return false;
|
|
1431
|
-
}
|
|
1432
|
-
cacheData[property.key] = property.value;
|
|
1433
|
-
return await this.writeCache(cache_id, cacheData);
|
|
1434
|
-
}
|
|
1435
|
-
/**
|
|
1436
|
-
* Reset an entire cache
|
|
1437
|
-
* @param cache_id - cache ID to reset
|
|
1438
|
-
* @returns true if success, false otherwise
|
|
1439
|
-
*/
|
|
1440
|
-
static async resetCache(cache_id) {
|
|
1441
|
-
try {
|
|
1442
|
-
const cleanCacheId = cache_id.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
1443
|
-
await this.writeCache(cache_id, {});
|
|
1444
|
-
Log.info(`Reset cache: ${cleanCacheId}.json`);
|
|
1445
|
-
return true;
|
|
1446
|
-
} catch (error) {
|
|
1447
|
-
Log.error(`Failed to reset cache ${cache_id}: ${error}`);
|
|
1448
|
-
return false;
|
|
1449
|
-
}
|
|
1450
|
-
}
|
|
1451
|
-
/**
|
|
1452
|
-
* Delete an entire cache
|
|
1453
|
-
* @param cache_id - cache ID to delete
|
|
1454
|
-
* @returns true if success, false otherwise
|
|
1455
|
-
*/
|
|
1456
|
-
static async deleteCache(cache_id) {
|
|
1457
|
-
try {
|
|
1458
|
-
const cleanCacheId = cache_id.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
1459
|
-
const filePath = this.createFilePath(cleanCacheId);
|
|
1460
|
-
if (await FileManager.deleteFile(filePath)) {
|
|
1461
|
-
Log.info(`Deleted cache: ${cleanCacheId}.json`);
|
|
1462
|
-
return true;
|
|
1463
|
-
}
|
|
1464
|
-
return false;
|
|
1465
|
-
} catch (error) {
|
|
1466
|
-
Log.error(`Failed to delete cache ${cache_id}: ${error}`);
|
|
1467
|
-
return false;
|
|
1468
|
-
}
|
|
1469
|
-
}
|
|
1470
|
-
/**
|
|
1471
|
-
* List every existing cache
|
|
1472
|
-
* @returns Array of cache_id, false otherwise
|
|
1473
|
-
*/
|
|
1474
|
-
static async listCaches() {
|
|
1475
|
-
return await FileManager.listJsonFiles(this.cacheDir);
|
|
1476
|
-
}
|
|
1477
|
-
/**
|
|
1478
|
-
* Clean cache data
|
|
1479
|
-
* @returns true if success, false otherwise
|
|
1480
|
-
*/
|
|
1481
|
-
static async clearAllCaches() {
|
|
1482
|
-
try {
|
|
1483
|
-
const caches = await this.listCaches();
|
|
1484
|
-
if (caches === false || caches.length === 0) {
|
|
1485
|
-
return true;
|
|
1486
|
-
}
|
|
1487
|
-
let success = true;
|
|
1488
|
-
for (const cache of caches) {
|
|
1489
|
-
const result = await this.deleteCache(cache.replace(".json", ""));
|
|
1490
|
-
if (!result) success = false;
|
|
1491
|
-
}
|
|
1492
|
-
return success;
|
|
1493
|
-
} catch (error) {
|
|
1494
|
-
Log.error(`Failed to clear caches: ${error}`);
|
|
1495
|
-
return false;
|
|
1496
|
-
}
|
|
1497
|
-
}
|
|
1498
|
-
};
|
|
900
|
+
// src/index.ts
|
|
901
|
+
import { FileManager } from "@spatulox/utils";
|
|
902
|
+
import { CacheManager } from "@spatulox/utils";
|
|
1499
903
|
|
|
1500
904
|
// src/manager/messages/WebhookManager.ts
|
|
1501
905
|
import {
|
|
@@ -1512,9 +916,6 @@ var WebhookManager = class {
|
|
|
1512
916
|
this.name = name;
|
|
1513
917
|
this.avatarPathOrUrl = avatarPathOrUrl;
|
|
1514
918
|
}
|
|
1515
|
-
client;
|
|
1516
|
-
name;
|
|
1517
|
-
avatarPathOrUrl;
|
|
1518
919
|
webhook = null;
|
|
1519
920
|
async getAvatar() {
|
|
1520
921
|
if (!this.avatarPathOrUrl) return null;
|
|
@@ -1630,10 +1031,17 @@ var WebhookManager = class {
|
|
|
1630
1031
|
}
|
|
1631
1032
|
};
|
|
1632
1033
|
|
|
1034
|
+
// src/manager/messages/ReactionManager.ts
|
|
1035
|
+
import { Log as Log7 } from "@spatulox/utils";
|
|
1036
|
+
|
|
1633
1037
|
// src/manager/guild/ChannelManager/GuildTextChannelManager.ts
|
|
1634
1038
|
import { TextChannel as TextChannel4, ChannelType as ChannelType2 } from "discord.js";
|
|
1635
1039
|
|
|
1040
|
+
// src/manager/guild/ChannelManager/GuildChannelManager.ts
|
|
1041
|
+
import { Log as Log5 } from "@spatulox/utils";
|
|
1042
|
+
|
|
1636
1043
|
// src/manager/guild/ChannelManager/GuildMessageManager.ts
|
|
1044
|
+
import { Log as Log4 } from "@spatulox/utils";
|
|
1637
1045
|
var GuildMessageManager = class {
|
|
1638
1046
|
/**
|
|
1639
1047
|
* Impl
|
|
@@ -1642,7 +1050,7 @@ var GuildMessageManager = class {
|
|
|
1642
1050
|
try {
|
|
1643
1051
|
const channel = await GuildTextChannelManager.find(channelId);
|
|
1644
1052
|
if (!channel) {
|
|
1645
|
-
|
|
1053
|
+
Log4.error(`Channel ${channelId} not found in guild`);
|
|
1646
1054
|
return null;
|
|
1647
1055
|
}
|
|
1648
1056
|
let payload;
|
|
@@ -1655,7 +1063,7 @@ var GuildMessageManager = class {
|
|
|
1655
1063
|
}
|
|
1656
1064
|
return await channel.send(payload);
|
|
1657
1065
|
} catch (error) {
|
|
1658
|
-
|
|
1066
|
+
Log4.error(`Failed to send message to ${channelId}: ${error}`);
|
|
1659
1067
|
throw error;
|
|
1660
1068
|
}
|
|
1661
1069
|
}
|
|
@@ -1666,15 +1074,15 @@ var GuildMessageManager = class {
|
|
|
1666
1074
|
try {
|
|
1667
1075
|
const channel = await GuildTextChannelManager.find(channelId);
|
|
1668
1076
|
if (!channel) {
|
|
1669
|
-
|
|
1077
|
+
Log4.error(`Channel ${channelId} not found`);
|
|
1670
1078
|
return false;
|
|
1671
1079
|
}
|
|
1672
1080
|
const message = await channel.messages.fetch(messageId);
|
|
1673
1081
|
await message.delete();
|
|
1674
|
-
|
|
1082
|
+
Log4.info(`Deleted message ${messageId} from ${channelId}`);
|
|
1675
1083
|
return true;
|
|
1676
1084
|
} catch (error) {
|
|
1677
|
-
|
|
1085
|
+
Log4.error(`Failed to delete message ${messageId} from ${channelId}: ${error}`);
|
|
1678
1086
|
return false;
|
|
1679
1087
|
}
|
|
1680
1088
|
}
|
|
@@ -1685,14 +1093,14 @@ var GuildMessageManager = class {
|
|
|
1685
1093
|
try {
|
|
1686
1094
|
const channel = await GuildTextChannelManager.find(channelId);
|
|
1687
1095
|
if (!channel) {
|
|
1688
|
-
|
|
1096
|
+
Log4.error(`Channel ${channelId} not found`);
|
|
1689
1097
|
return [];
|
|
1690
1098
|
}
|
|
1691
1099
|
const messages = await channel.messages.fetch({ limit });
|
|
1692
|
-
|
|
1100
|
+
Log4.info(`Fetched ${messages.size} messages from ${channelId}`);
|
|
1693
1101
|
return Array.from(messages.values());
|
|
1694
1102
|
} catch (error) {
|
|
1695
|
-
|
|
1103
|
+
Log4.error(`Failed to fetch messages from ${channelId}: ${error}`);
|
|
1696
1104
|
return [];
|
|
1697
1105
|
}
|
|
1698
1106
|
}
|
|
@@ -1703,13 +1111,13 @@ var GuildMessageManager = class {
|
|
|
1703
1111
|
try {
|
|
1704
1112
|
const channel = await GuildTextChannelManager.find(channelId);
|
|
1705
1113
|
if (!channel) {
|
|
1706
|
-
|
|
1114
|
+
Log4.error(`Channel ${channelId} not found`);
|
|
1707
1115
|
return null;
|
|
1708
1116
|
}
|
|
1709
1117
|
const message = await channel.messages.fetch(messageId);
|
|
1710
1118
|
return message;
|
|
1711
1119
|
} catch (error) {
|
|
1712
|
-
|
|
1120
|
+
Log4.error(`Failed to fetch message ${messageId} from ${channelId}: ${error}`);
|
|
1713
1121
|
return null;
|
|
1714
1122
|
}
|
|
1715
1123
|
}
|
|
@@ -1725,13 +1133,13 @@ var GuildChannelManager = class _GuildChannelManager {
|
|
|
1725
1133
|
try {
|
|
1726
1134
|
const guild = Bot.client.guilds.cache.get(guildId);
|
|
1727
1135
|
if (!guild) {
|
|
1728
|
-
|
|
1136
|
+
Log5.warn(`Guild ${guildId} not found`);
|
|
1729
1137
|
return null;
|
|
1730
1138
|
}
|
|
1731
1139
|
const channel = await guild.channels.fetch(channelId);
|
|
1732
1140
|
return channel ?? null;
|
|
1733
1141
|
} catch (error) {
|
|
1734
|
-
|
|
1142
|
+
Log5.error(`Failed to find channel ${channelId} in guild ${guildId}: ${error}`);
|
|
1735
1143
|
return null;
|
|
1736
1144
|
}
|
|
1737
1145
|
}
|
|
@@ -1741,10 +1149,10 @@ var GuildChannelManager = class _GuildChannelManager {
|
|
|
1741
1149
|
if (cached && !cached.isDMBased()) return cached;
|
|
1742
1150
|
const channel = await Bot.client.channels.fetch(channelId);
|
|
1743
1151
|
if (channel && !channel.isDMBased()) return channel;
|
|
1744
|
-
|
|
1152
|
+
Log5.warn(`Channel ${channelId} not found in any guild`);
|
|
1745
1153
|
return null;
|
|
1746
1154
|
} catch (error) {
|
|
1747
|
-
|
|
1155
|
+
Log5.error(`Failed to find channel ${channelId}: ${error}`);
|
|
1748
1156
|
return null;
|
|
1749
1157
|
}
|
|
1750
1158
|
}
|
|
@@ -1752,12 +1160,12 @@ var GuildChannelManager = class _GuildChannelManager {
|
|
|
1752
1160
|
try {
|
|
1753
1161
|
const guild = Bot.client.guilds.cache.get(guildId);
|
|
1754
1162
|
if (!guild) {
|
|
1755
|
-
|
|
1163
|
+
Log5.warn(`Guild ${guildId} not found`);
|
|
1756
1164
|
return [];
|
|
1757
1165
|
}
|
|
1758
1166
|
return Array.from(guild.channels.cache.values());
|
|
1759
1167
|
} catch (error) {
|
|
1760
|
-
|
|
1168
|
+
Log5.error(`Failed to find channel ${guildId}: ${error}`);
|
|
1761
1169
|
return [];
|
|
1762
1170
|
}
|
|
1763
1171
|
}
|
|
@@ -1768,14 +1176,14 @@ var GuildChannelManager = class _GuildChannelManager {
|
|
|
1768
1176
|
try {
|
|
1769
1177
|
const guild = Bot.client.guilds.cache.get(guildId);
|
|
1770
1178
|
if (!guild) {
|
|
1771
|
-
|
|
1179
|
+
Log5.warn(`Guild ${guildId} not found`);
|
|
1772
1180
|
return [];
|
|
1773
1181
|
}
|
|
1774
1182
|
return Array.from(guild.channels.cache.values()).filter(
|
|
1775
1183
|
(channel) => channel.name.toLowerCase().includes(name.toLowerCase())
|
|
1776
1184
|
);
|
|
1777
1185
|
} catch (error) {
|
|
1778
|
-
|
|
1186
|
+
Log5.error(`Failed to find channel ${guildId}: ${error}`);
|
|
1779
1187
|
return [];
|
|
1780
1188
|
}
|
|
1781
1189
|
}
|
|
@@ -1786,10 +1194,10 @@ var GuildChannelManager = class _GuildChannelManager {
|
|
|
1786
1194
|
throw new Error(`Guild ${guildId} not found`);
|
|
1787
1195
|
}
|
|
1788
1196
|
const channel = await guild.channels.create(options);
|
|
1789
|
-
|
|
1197
|
+
Log5.info(`Created channel ${channel.name} (${channel.id}) in guild ${guildId}`);
|
|
1790
1198
|
return channel;
|
|
1791
1199
|
} catch (error) {
|
|
1792
|
-
|
|
1200
|
+
Log5.error(`Failed to create channel in guild ${guildId}: ${error}`);
|
|
1793
1201
|
throw error;
|
|
1794
1202
|
}
|
|
1795
1203
|
}
|
|
@@ -1800,16 +1208,17 @@ var GuildChannelManager = class _GuildChannelManager {
|
|
|
1800
1208
|
throw new Error(`Channel ${channelId} not found`);
|
|
1801
1209
|
}
|
|
1802
1210
|
await channel.delete();
|
|
1803
|
-
|
|
1211
|
+
Log5.info(`Deleted channel ${channelId}`);
|
|
1804
1212
|
return true;
|
|
1805
1213
|
} catch (error) {
|
|
1806
|
-
|
|
1214
|
+
Log5.error(`Failed to delete channel ${channelId}: ${error}`);
|
|
1807
1215
|
throw error;
|
|
1808
1216
|
}
|
|
1809
1217
|
}
|
|
1810
1218
|
};
|
|
1811
1219
|
|
|
1812
1220
|
// src/manager/guild/ChannelManager/GuildTextChannelManager.ts
|
|
1221
|
+
import { Log as Log6 } from "@spatulox/utils";
|
|
1813
1222
|
var GuildTextChannelManager = class extends GuildChannelManager {
|
|
1814
1223
|
static async findInGuild(guildId, channelId) {
|
|
1815
1224
|
const channel = await super.findInGuild(guildId, channelId);
|
|
@@ -1822,7 +1231,7 @@ var GuildTextChannelManager = class extends GuildChannelManager {
|
|
|
1822
1231
|
static findAll(guildId) {
|
|
1823
1232
|
const guild = Bot.client.guilds.cache.get(guildId);
|
|
1824
1233
|
if (!guild) {
|
|
1825
|
-
|
|
1234
|
+
Log6.warn(`Guild ${guildId} not found`);
|
|
1826
1235
|
return [];
|
|
1827
1236
|
}
|
|
1828
1237
|
return Array.from(guild.channels.cache.values()).filter((c) => c instanceof TextChannel4);
|
|
@@ -1852,9 +1261,9 @@ var ReactionManager = class {
|
|
|
1852
1261
|
}
|
|
1853
1262
|
const message = await channel.messages.fetch(messageId);
|
|
1854
1263
|
await message.react(emoji);
|
|
1855
|
-
|
|
1264
|
+
Log7.info(`Added reaction ${emoji} to message ${messageId}`);
|
|
1856
1265
|
} catch (error) {
|
|
1857
|
-
|
|
1266
|
+
Log7.error(`Failed to add reaction to ${messageId}: ${error}`);
|
|
1858
1267
|
throw error;
|
|
1859
1268
|
}
|
|
1860
1269
|
}
|
|
@@ -1874,9 +1283,9 @@ var ReactionManager = class {
|
|
|
1874
1283
|
}
|
|
1875
1284
|
const user = await Bot.client.users.fetch(userId);
|
|
1876
1285
|
await reaction.users.remove(user);
|
|
1877
|
-
|
|
1286
|
+
Log7.info(`Removed reaction ${emoji} from user ${userId} on message ${messageId}`);
|
|
1878
1287
|
} catch (error) {
|
|
1879
|
-
|
|
1288
|
+
Log7.error(`Failed to remove reaction from ${messageId}: ${error}`);
|
|
1880
1289
|
throw error;
|
|
1881
1290
|
}
|
|
1882
1291
|
}
|
|
@@ -1900,10 +1309,10 @@ var ReactionManager = class {
|
|
|
1900
1309
|
users: Array.from(users.values())
|
|
1901
1310
|
});
|
|
1902
1311
|
}
|
|
1903
|
-
|
|
1312
|
+
Log7.info(`Fetched ${reactionList.length} reactions for message ${messageId}`);
|
|
1904
1313
|
return reactionList;
|
|
1905
1314
|
} catch (error) {
|
|
1906
|
-
|
|
1315
|
+
Log7.error(`Failed to fetch reactions for ${messageId}: ${error}`);
|
|
1907
1316
|
throw error;
|
|
1908
1317
|
}
|
|
1909
1318
|
}
|
|
@@ -1918,9 +1327,9 @@ var ReactionManager = class {
|
|
|
1918
1327
|
}
|
|
1919
1328
|
const message = await channel.messages.fetch(messageId);
|
|
1920
1329
|
await message.reactions.removeAll();
|
|
1921
|
-
|
|
1330
|
+
Log7.info(`Cleared all reactions from message ${messageId}`);
|
|
1922
1331
|
} catch (error) {
|
|
1923
|
-
|
|
1332
|
+
Log7.error(`Failed to clear reactions from ${messageId}: ${error}`);
|
|
1924
1333
|
throw error;
|
|
1925
1334
|
}
|
|
1926
1335
|
}
|
|
@@ -1928,9 +1337,15 @@ var ReactionManager = class {
|
|
|
1928
1337
|
|
|
1929
1338
|
// src/manager/guild/GuildManager.ts
|
|
1930
1339
|
import { Guild as Guild2, StageChannel as StageChannel2, VoiceChannel as VoiceChannel2 } from "discord.js";
|
|
1340
|
+
import { Log as Log16 } from "@spatulox/utils";
|
|
1341
|
+
import { Time as Time2 } from "@spatulox/utils";
|
|
1342
|
+
|
|
1343
|
+
// src/manager/guild/GuildUserManager.ts
|
|
1344
|
+
import { Log as Log9 } from "@spatulox/utils";
|
|
1931
1345
|
|
|
1932
1346
|
// src/manager/direct/BasicUserManager.ts
|
|
1933
1347
|
import { GuildMember as GuildMember2 } from "discord.js";
|
|
1348
|
+
import { Log as Log8 } from "@spatulox/utils";
|
|
1934
1349
|
var BasicUserManager = class {
|
|
1935
1350
|
/**
|
|
1936
1351
|
* Find member in specific guild
|
|
@@ -1946,7 +1361,7 @@ var BasicUserManager = class {
|
|
|
1946
1361
|
const cached = targetGuild.members.cache.get(memberId);
|
|
1947
1362
|
if (cached) return cached;
|
|
1948
1363
|
const member = await targetGuild.members.fetch(memberId).catch(() => null);
|
|
1949
|
-
if (!member)
|
|
1364
|
+
if (!member) Log8.error(`UserManager: Member ${memberId} not found in guild ${targetGuild.id}`);
|
|
1950
1365
|
return member;
|
|
1951
1366
|
}
|
|
1952
1367
|
/**
|
|
@@ -1989,13 +1404,13 @@ var BasicUserManager = class {
|
|
|
1989
1404
|
}
|
|
1990
1405
|
const message = await dmChannel.send(payload);
|
|
1991
1406
|
if (user instanceof GuildMember2) {
|
|
1992
|
-
|
|
1407
|
+
Log8.info(`Sent DM to ${user.id} (${user.user.username}): "${(payload.content || "Embed/Component").substring(0, 50)}..."`);
|
|
1993
1408
|
} else {
|
|
1994
|
-
|
|
1409
|
+
Log8.info(`Sent DM to ${user.id} (${user.username}): "${(payload.content || "Embed/Component").substring(0, 50)}..."`);
|
|
1995
1410
|
}
|
|
1996
1411
|
return message;
|
|
1997
1412
|
} catch (error) {
|
|
1998
|
-
|
|
1413
|
+
Log8.error(`Failed to send DM to ${user_id_or_user}: ${error}`);
|
|
1999
1414
|
throw new Error(`Cannot send DM to ${user_id_or_user}`);
|
|
2000
1415
|
}
|
|
2001
1416
|
}
|
|
@@ -2013,7 +1428,7 @@ var GuildUserManager = class extends BasicUserManager {
|
|
|
2013
1428
|
try {
|
|
2014
1429
|
const oldName = member.displayName;
|
|
2015
1430
|
await member.setNickname(nickname.trim());
|
|
2016
|
-
|
|
1431
|
+
Log9.info(`Renaming user: ${oldName} \u2192 ${nickname.trim()}`);
|
|
2017
1432
|
await setTimeout2(1500);
|
|
2018
1433
|
return true;
|
|
2019
1434
|
} catch (error) {
|
|
@@ -2031,13 +1446,13 @@ var GuildUserManager = class extends BasicUserManager {
|
|
|
2031
1446
|
try {
|
|
2032
1447
|
const guild = await GuildManager.find(guildId);
|
|
2033
1448
|
if (!guild) {
|
|
2034
|
-
|
|
1449
|
+
Log9.warn(`Guild ${guildId} not found`);
|
|
2035
1450
|
return false;
|
|
2036
1451
|
}
|
|
2037
1452
|
const ban = await guild.bans.fetch(userId);
|
|
2038
1453
|
return !!ban;
|
|
2039
1454
|
} catch (error) {
|
|
2040
|
-
|
|
1455
|
+
Log9.debug(`User ${userId} is not banned from guild ${guildId}`);
|
|
2041
1456
|
return false;
|
|
2042
1457
|
}
|
|
2043
1458
|
}
|
|
@@ -2051,9 +1466,9 @@ var GuildUserManager = class extends BasicUserManager {
|
|
|
2051
1466
|
throw new Error(`Member ${memberId} not found or not in a voice channel`);
|
|
2052
1467
|
}
|
|
2053
1468
|
await member.voice.disconnect();
|
|
2054
|
-
|
|
1469
|
+
Log9.info(`Disconnected member ${memberId} from voice in guild ${guildId}`);
|
|
2055
1470
|
} catch (error) {
|
|
2056
|
-
|
|
1471
|
+
Log9.error(`Failed to disconnect member ${memberId} from voice in ${guildId}: ${error}`);
|
|
2057
1472
|
throw error;
|
|
2058
1473
|
}
|
|
2059
1474
|
}
|
|
@@ -2068,7 +1483,7 @@ var GuildUserManager = class extends BasicUserManager {
|
|
|
2068
1483
|
}
|
|
2069
1484
|
return member.voice.channelId !== null;
|
|
2070
1485
|
} catch (error) {
|
|
2071
|
-
|
|
1486
|
+
Log9.debug(`Member ${memberId} not found or not in voice in guild ${guildId}`);
|
|
2072
1487
|
return false;
|
|
2073
1488
|
}
|
|
2074
1489
|
}
|
|
@@ -2082,9 +1497,9 @@ var GuildUserManager = class extends BasicUserManager {
|
|
|
2082
1497
|
throw new Error(`User ${guildId} not found`);
|
|
2083
1498
|
}
|
|
2084
1499
|
await member.voice.setMute(true, reason);
|
|
2085
|
-
|
|
1500
|
+
Log9.info(`Server muted ${memberId} in guild ${guildId}: ${reason || "No reason"}`);
|
|
2086
1501
|
} catch (error) {
|
|
2087
|
-
|
|
1502
|
+
Log9.error(`Failed to server mute ${memberId} in ${guildId}:, error`);
|
|
2088
1503
|
throw error;
|
|
2089
1504
|
}
|
|
2090
1505
|
}
|
|
@@ -2098,9 +1513,9 @@ var GuildUserManager = class extends BasicUserManager {
|
|
|
2098
1513
|
throw new Error(`User ${guildId} not found`);
|
|
2099
1514
|
}
|
|
2100
1515
|
await member.voice.setMute(false, reason);
|
|
2101
|
-
|
|
1516
|
+
Log9.info(`Server unmuted ${memberId} in guild ${guildId}: ${reason || "No reason"}`);
|
|
2102
1517
|
} catch (error) {
|
|
2103
|
-
|
|
1518
|
+
Log9.error(`Failed to server unmute ${memberId} in ${guildId}: ${error}`);
|
|
2104
1519
|
throw error;
|
|
2105
1520
|
}
|
|
2106
1521
|
}
|
|
@@ -2114,9 +1529,9 @@ var GuildUserManager = class extends BasicUserManager {
|
|
|
2114
1529
|
throw new Error(`User ${guildId} not found`);
|
|
2115
1530
|
}
|
|
2116
1531
|
await member.voice.setDeaf(true, reason);
|
|
2117
|
-
|
|
1532
|
+
Log9.info(`Server deafened ${memberId} in guild ${guildId}: ${reason || "No reason"}`);
|
|
2118
1533
|
} catch (error) {
|
|
2119
|
-
|
|
1534
|
+
Log9.error(`Failed to server deafen ${memberId} in ${guildId}: ${error}`);
|
|
2120
1535
|
throw error;
|
|
2121
1536
|
}
|
|
2122
1537
|
}
|
|
@@ -2130,9 +1545,9 @@ var GuildUserManager = class extends BasicUserManager {
|
|
|
2130
1545
|
throw new Error(`User ${guildId} not found`);
|
|
2131
1546
|
}
|
|
2132
1547
|
await member.voice.setDeaf(false, reason);
|
|
2133
|
-
|
|
1548
|
+
Log9.info(`Server undeafened ${memberId} in guild ${guildId}: ${reason || "No reason"}`);
|
|
2134
1549
|
} catch (error) {
|
|
2135
|
-
|
|
1550
|
+
Log9.error(`Failed to server undeafen ${memberId} in ${guildId}: ${error}`);
|
|
2136
1551
|
throw error;
|
|
2137
1552
|
}
|
|
2138
1553
|
}
|
|
@@ -2147,9 +1562,9 @@ var GuildUserManager = class extends BasicUserManager {
|
|
|
2147
1562
|
}
|
|
2148
1563
|
const expires = Date.now() + duration;
|
|
2149
1564
|
await member.timeout(expires, reason);
|
|
2150
|
-
|
|
1565
|
+
Log9.info(`Timed out ${memberId} for ${duration}ms in guild ${guildId}: ${reason || "No reason"}`);
|
|
2151
1566
|
} catch (error) {
|
|
2152
|
-
|
|
1567
|
+
Log9.error(`Failed to timeout ${memberId} in ${guildId}: ${error}`);
|
|
2153
1568
|
throw error;
|
|
2154
1569
|
}
|
|
2155
1570
|
}
|
|
@@ -2163,9 +1578,9 @@ var GuildUserManager = class extends BasicUserManager {
|
|
|
2163
1578
|
throw new Error(`User ${guildId} not found`);
|
|
2164
1579
|
}
|
|
2165
1580
|
await member.timeout(null, reason);
|
|
2166
|
-
|
|
1581
|
+
Log9.info(`Untimed out ${memberId} in guild ${guildId}: ${reason || "No reason"}`);
|
|
2167
1582
|
} catch (error) {
|
|
2168
|
-
|
|
1583
|
+
Log9.error(`Failed to untimeout ${memberId} in ${guildId}: ${error}`);
|
|
2169
1584
|
throw error;
|
|
2170
1585
|
}
|
|
2171
1586
|
}
|
|
@@ -2179,9 +1594,9 @@ var GuildUserManager = class extends BasicUserManager {
|
|
|
2179
1594
|
throw new Error(`User ${guildId} not found`);
|
|
2180
1595
|
}
|
|
2181
1596
|
await member.kick(reason);
|
|
2182
|
-
|
|
1597
|
+
Log9.info(`Kicked ${memberId} from guild ${guildId}: ${reason || "No reason"}`);
|
|
2183
1598
|
} catch (error) {
|
|
2184
|
-
|
|
1599
|
+
Log9.error(`Failed to kick ${memberId} from ${guildId}: ${error}`);
|
|
2185
1600
|
throw error;
|
|
2186
1601
|
}
|
|
2187
1602
|
}
|
|
@@ -2192,9 +1607,9 @@ var GuildUserManager = class extends BasicUserManager {
|
|
|
2192
1607
|
}
|
|
2193
1608
|
try {
|
|
2194
1609
|
await guild.members.ban(userId, banOption);
|
|
2195
|
-
|
|
1610
|
+
Log9.info(`Banned user ${userId} from guild ${guildId}`);
|
|
2196
1611
|
} catch (error) {
|
|
2197
|
-
|
|
1612
|
+
Log9.error(`Failed to ban user ${userId} from guild ${guildId}: ${error}`);
|
|
2198
1613
|
throw error;
|
|
2199
1614
|
}
|
|
2200
1615
|
}
|
|
@@ -2205,15 +1620,16 @@ var GuildUserManager = class extends BasicUserManager {
|
|
|
2205
1620
|
}
|
|
2206
1621
|
try {
|
|
2207
1622
|
await guild.members.unban(userId, reason);
|
|
2208
|
-
|
|
1623
|
+
Log9.info(`Unbanned user ${userId} from guild ${guildId}`);
|
|
2209
1624
|
} catch (error) {
|
|
2210
|
-
|
|
1625
|
+
Log9.error(`Failed to unban user ${userId} from guild ${guildId}: ${error}`);
|
|
2211
1626
|
throw error;
|
|
2212
1627
|
}
|
|
2213
1628
|
}
|
|
2214
1629
|
};
|
|
2215
1630
|
|
|
2216
1631
|
// src/manager/guild/RoleManager.ts
|
|
1632
|
+
import { Log as Log10 } from "@spatulox/utils";
|
|
2217
1633
|
var RoleManager = class {
|
|
2218
1634
|
/**
|
|
2219
1635
|
* Add role - CACHE ONLY
|
|
@@ -2224,14 +1640,14 @@ var RoleManager = class {
|
|
|
2224
1640
|
try {
|
|
2225
1641
|
const role = member.guild.roles.cache.get(roleId);
|
|
2226
1642
|
if (!role) {
|
|
2227
|
-
|
|
1643
|
+
Log10.warn(`Role ${roleId} not found in cache`);
|
|
2228
1644
|
return false;
|
|
2229
1645
|
}
|
|
2230
1646
|
await member.roles.add(role);
|
|
2231
|
-
|
|
1647
|
+
Log10.info(`\u2705 Added ${role.name} to ${member.displayName}`);
|
|
2232
1648
|
return true;
|
|
2233
1649
|
} catch (error) {
|
|
2234
|
-
|
|
1650
|
+
Log10.error(`Failed to add role ${roleId}: ${error}`);
|
|
2235
1651
|
return false;
|
|
2236
1652
|
}
|
|
2237
1653
|
}
|
|
@@ -2251,14 +1667,14 @@ var RoleManager = class {
|
|
|
2251
1667
|
);
|
|
2252
1668
|
}
|
|
2253
1669
|
if (!role) {
|
|
2254
|
-
|
|
1670
|
+
Log10.warn(`Role ${roleIdOrName} not found for ${member.displayName}`);
|
|
2255
1671
|
return false;
|
|
2256
1672
|
}
|
|
2257
1673
|
await member.roles.remove(role);
|
|
2258
|
-
|
|
1674
|
+
Log10.info(`\u2705 Removed ${role.name} from ${member.displayName}`);
|
|
2259
1675
|
return true;
|
|
2260
1676
|
} catch (error) {
|
|
2261
|
-
|
|
1677
|
+
Log10.error(`Failed to remove role ${roleIdOrName}: ${error}`);
|
|
2262
1678
|
return false;
|
|
2263
1679
|
}
|
|
2264
1680
|
}
|
|
@@ -2268,7 +1684,7 @@ var RoleManager = class {
|
|
|
2268
1684
|
static async toggle(member, roleIdOrName) {
|
|
2269
1685
|
const role = member.roles.cache.get(roleIdOrName) || member.roles.cache.find((r) => r.name.toLowerCase() === roleIdOrName.toString().toLowerCase());
|
|
2270
1686
|
if (!role) {
|
|
2271
|
-
|
|
1687
|
+
Log10.warn(`Role ${roleIdOrName} not found`);
|
|
2272
1688
|
throw new Error(`Role not found`);
|
|
2273
1689
|
}
|
|
2274
1690
|
if (member.roles.cache.has(role.id)) {
|
|
@@ -2294,6 +1710,7 @@ var RoleManager = class {
|
|
|
2294
1710
|
|
|
2295
1711
|
// src/manager/guild/ChannelManager/ForumChannelManager.ts
|
|
2296
1712
|
import { ChannelType as ChannelType3, ForumChannel } from "discord.js";
|
|
1713
|
+
import { Log as Log11 } from "@spatulox/utils";
|
|
2297
1714
|
var ForumChannelManager = class extends GuildChannelManager {
|
|
2298
1715
|
static async findInGuild(guildId, channelId) {
|
|
2299
1716
|
const channel = await super.findInGuild(guildId, channelId);
|
|
@@ -2306,7 +1723,7 @@ var ForumChannelManager = class extends GuildChannelManager {
|
|
|
2306
1723
|
static findAll(guildId) {
|
|
2307
1724
|
const guild = Bot.client.guilds.cache.get(guildId);
|
|
2308
1725
|
if (!guild) {
|
|
2309
|
-
|
|
1726
|
+
Log11.warn(`Guild ${guildId} not found`);
|
|
2310
1727
|
return [];
|
|
2311
1728
|
}
|
|
2312
1729
|
return Array.from(guild.channels.cache.values()).filter((c) => c instanceof ForumChannel);
|
|
@@ -2322,6 +1739,7 @@ var ForumChannelManager = class extends GuildChannelManager {
|
|
|
2322
1739
|
|
|
2323
1740
|
// src/manager/guild/ChannelManager/NewsChannelManager.ts
|
|
2324
1741
|
import { ChannelType as ChannelType4, NewsChannel } from "discord.js";
|
|
1742
|
+
import { Log as Log12 } from "@spatulox/utils";
|
|
2325
1743
|
var NewsChannelManager = class extends GuildChannelManager {
|
|
2326
1744
|
static async findInGuild(guildId, channelId) {
|
|
2327
1745
|
const channel = await super.findInGuild(guildId, channelId);
|
|
@@ -2334,7 +1752,7 @@ var NewsChannelManager = class extends GuildChannelManager {
|
|
|
2334
1752
|
static findAll(guildId) {
|
|
2335
1753
|
const guild = Bot.client.guilds.cache.get(guildId);
|
|
2336
1754
|
if (!guild) {
|
|
2337
|
-
|
|
1755
|
+
Log12.warn(`Guild ${guildId} not found`);
|
|
2338
1756
|
return [];
|
|
2339
1757
|
}
|
|
2340
1758
|
return Array.from(guild.channels.cache.values()).filter((c) => c instanceof NewsChannel);
|
|
@@ -2350,6 +1768,7 @@ var NewsChannelManager = class extends GuildChannelManager {
|
|
|
2350
1768
|
|
|
2351
1769
|
// src/manager/guild/ChannelManager/StageChannelManager.ts
|
|
2352
1770
|
import { ChannelType as ChannelType5, StageChannel } from "discord.js";
|
|
1771
|
+
import { Log as Log13 } from "@spatulox/utils";
|
|
2353
1772
|
var StageChannelManager = class extends GuildChannelManager {
|
|
2354
1773
|
static async findInGuild(guildId, channelId) {
|
|
2355
1774
|
const channel = await super.findInGuild(guildId, channelId);
|
|
@@ -2362,7 +1781,7 @@ var StageChannelManager = class extends GuildChannelManager {
|
|
|
2362
1781
|
static findAll(guildId) {
|
|
2363
1782
|
const guild = Bot.client.guilds.cache.get(guildId);
|
|
2364
1783
|
if (!guild) {
|
|
2365
|
-
|
|
1784
|
+
Log13.warn(`Guild ${guildId} not found`);
|
|
2366
1785
|
return [];
|
|
2367
1786
|
}
|
|
2368
1787
|
return Array.from(guild.channels.cache.values()).filter((c) => c instanceof StageChannel);
|
|
@@ -2419,6 +1838,7 @@ var ThreadChannelManager = class {
|
|
|
2419
1838
|
|
|
2420
1839
|
// src/manager/guild/ChannelManager/GuildVoiceChannelManager.ts
|
|
2421
1840
|
import { ChannelType as ChannelType6, VoiceChannel } from "discord.js";
|
|
1841
|
+
import { Log as Log14 } from "@spatulox/utils";
|
|
2422
1842
|
var GuildVoiceChannelManager = class extends GuildChannelManager {
|
|
2423
1843
|
static async findInGuild(guildId, channelId) {
|
|
2424
1844
|
const channel = await super.findInGuild(guildId, channelId);
|
|
@@ -2431,7 +1851,7 @@ var GuildVoiceChannelManager = class extends GuildChannelManager {
|
|
|
2431
1851
|
static findAll(guildId) {
|
|
2432
1852
|
const guild = Bot.client.guilds.cache.get(guildId);
|
|
2433
1853
|
if (!guild) {
|
|
2434
|
-
|
|
1854
|
+
Log14.warn(`Guild ${guildId} not found`);
|
|
2435
1855
|
return [];
|
|
2436
1856
|
}
|
|
2437
1857
|
return Array.from(guild.channels.cache.values()).filter((c) => c instanceof VoiceChannel);
|
|
@@ -2457,6 +1877,7 @@ var GuildChannelList = class {
|
|
|
2457
1877
|
};
|
|
2458
1878
|
|
|
2459
1879
|
// src/manager/guild/InviteManager.ts
|
|
1880
|
+
import { Log as Log15 } from "@spatulox/utils";
|
|
2460
1881
|
var InviteManager = class {
|
|
2461
1882
|
/**
|
|
2462
1883
|
* Create an invite for a channel
|
|
@@ -2475,10 +1896,10 @@ var InviteManager = class {
|
|
|
2475
1896
|
reason: options.reason
|
|
2476
1897
|
};
|
|
2477
1898
|
const invite = await guild.invites.create(channelId, inviteOptions);
|
|
2478
|
-
|
|
1899
|
+
Log15.info(`Created invite ${invite.code} for channel ${channelId}`);
|
|
2479
1900
|
return invite;
|
|
2480
1901
|
} catch (error) {
|
|
2481
|
-
|
|
1902
|
+
Log15.error(`Failed to create invite for channel ${channelId}: ${error}`);
|
|
2482
1903
|
throw error;
|
|
2483
1904
|
}
|
|
2484
1905
|
}
|
|
@@ -2488,10 +1909,10 @@ var InviteManager = class {
|
|
|
2488
1909
|
static async delete(invite) {
|
|
2489
1910
|
try {
|
|
2490
1911
|
await invite.delete();
|
|
2491
|
-
|
|
1912
|
+
Log15.info(`Deleted invite ${invite.code} from guild ${invite.guild?.id}`);
|
|
2492
1913
|
return true;
|
|
2493
1914
|
} catch (error) {
|
|
2494
|
-
|
|
1915
|
+
Log15.error(`Failed to delete invite ${invite.code}: ${error}`);
|
|
2495
1916
|
return false;
|
|
2496
1917
|
}
|
|
2497
1918
|
}
|
|
@@ -2506,10 +1927,10 @@ var InviteManager = class {
|
|
|
2506
1927
|
}
|
|
2507
1928
|
const invites = await guild.invites.fetch();
|
|
2508
1929
|
const inviteList = Array.from(invites.values());
|
|
2509
|
-
|
|
1930
|
+
Log15.info(`Fetched ${inviteList.length} invites for guild ${guildId}`);
|
|
2510
1931
|
return inviteList;
|
|
2511
1932
|
} catch (error) {
|
|
2512
|
-
|
|
1933
|
+
Log15.error(`Failed to fetch invites for guild ${guildId}: ${error}`);
|
|
2513
1934
|
throw error;
|
|
2514
1935
|
}
|
|
2515
1936
|
}
|
|
@@ -2530,7 +1951,7 @@ var GuildManager = class {
|
|
|
2530
1951
|
if (cached) return cached;
|
|
2531
1952
|
return await Bot.client.guilds.fetch(guild_id);
|
|
2532
1953
|
} catch (error) {
|
|
2533
|
-
|
|
1954
|
+
Log16.error(`GuildManager: Guild ${guild_id} : ${error} `);
|
|
2534
1955
|
return null;
|
|
2535
1956
|
}
|
|
2536
1957
|
}
|
|
@@ -2541,7 +1962,7 @@ var GuildManager = class {
|
|
|
2541
1962
|
try {
|
|
2542
1963
|
return await GuildChannelManager.findInGuild(guildId, channelId);
|
|
2543
1964
|
} catch (error) {
|
|
2544
|
-
|
|
1965
|
+
Log16.error(`Failed to fetch channel ${channelId}: ${error}`);
|
|
2545
1966
|
return null;
|
|
2546
1967
|
}
|
|
2547
1968
|
}
|
|
@@ -2552,7 +1973,7 @@ var GuildManager = class {
|
|
|
2552
1973
|
try {
|
|
2553
1974
|
return await this.user.findInGuild(guildId, guildId);
|
|
2554
1975
|
} catch (error) {
|
|
2555
|
-
|
|
1976
|
+
Log16.error(`Failed to fetch member ${memberId} in guild ${guildId}: ${error}`);
|
|
2556
1977
|
return null;
|
|
2557
1978
|
}
|
|
2558
1979
|
}
|
|
@@ -2569,7 +1990,7 @@ var GuildManager = class {
|
|
|
2569
1990
|
/**
|
|
2570
1991
|
* Fetch all members with retry (heavy operation)
|
|
2571
1992
|
*/
|
|
2572
|
-
static async fetchAllMembers(guildId, MAX_ATTEMPTS = 3, RETRY_DELAY =
|
|
1993
|
+
static async fetchAllMembers(guildId, MAX_ATTEMPTS = 3, RETRY_DELAY = Time2.minute.MIN_05.toMilliseconds()) {
|
|
2573
1994
|
let guild;
|
|
2574
1995
|
if (guildId instanceof Guild2) {
|
|
2575
1996
|
guild = guildId;
|
|
@@ -2580,10 +2001,10 @@ var GuildManager = class {
|
|
|
2580
2001
|
}
|
|
2581
2002
|
for (let attempt = 1; attempt <= MAX_ATTEMPTS; attempt++) {
|
|
2582
2003
|
try {
|
|
2583
|
-
|
|
2004
|
+
Log16.info(`UserManager: Fetching ${guild.name} members (attempt ${attempt})`);
|
|
2584
2005
|
return await guild.members.fetch();
|
|
2585
2006
|
} catch (error) {
|
|
2586
|
-
|
|
2007
|
+
Log16.error(`UserManager: Fetch failed (attempt ${attempt}): ${error}`);
|
|
2587
2008
|
if (attempt < MAX_ATTEMPTS) {
|
|
2588
2009
|
await new Promise((r) => setTimeout(r, RETRY_DELAY));
|
|
2589
2010
|
}
|
|
@@ -2600,7 +2021,7 @@ var GuildManager = class {
|
|
|
2600
2021
|
const bans = await guild.bans.fetch({ limit });
|
|
2601
2022
|
return Array.from(bans.values());
|
|
2602
2023
|
} catch (error) {
|
|
2603
|
-
|
|
2024
|
+
Log16.error(`Failed to list bans in guild ${guildId}: ${error}`);
|
|
2604
2025
|
throw error;
|
|
2605
2026
|
}
|
|
2606
2027
|
}
|
|
@@ -2635,26 +2056,27 @@ var GuildManager = class {
|
|
|
2635
2056
|
}
|
|
2636
2057
|
try {
|
|
2637
2058
|
await member.voice.setChannel(toChannel);
|
|
2638
|
-
|
|
2059
|
+
Log16.info(`Moved member ${memberId} from ${fromChannelId} to ${toChannelId}`);
|
|
2639
2060
|
} catch (error) {
|
|
2640
|
-
|
|
2061
|
+
Log16.error(`Failed to move member ${memberId} from ${fromChannelId} to ${toChannelId}: ${error}`);
|
|
2641
2062
|
throw error;
|
|
2642
2063
|
}
|
|
2643
2064
|
return true;
|
|
2644
2065
|
} catch (e) {
|
|
2645
|
-
|
|
2066
|
+
Log16.error(`Failed to move member ${e}`);
|
|
2646
2067
|
return false;
|
|
2647
2068
|
}
|
|
2648
2069
|
}
|
|
2649
2070
|
};
|
|
2650
2071
|
|
|
2651
2072
|
// src/manager/direct/UserManager.ts
|
|
2073
|
+
import { Log as Log17 } from "@spatulox/utils";
|
|
2652
2074
|
var UserManager = class extends BasicUserManager {
|
|
2653
2075
|
static async find(userId) {
|
|
2654
2076
|
const cached = Bot.client.users.cache.get(userId);
|
|
2655
2077
|
if (cached) return cached;
|
|
2656
2078
|
const user = await Bot.client.users.fetch(userId).catch(() => null);
|
|
2657
|
-
if (!user)
|
|
2079
|
+
if (!user) Log17.error(`UserManager: User ${userId} not found`);
|
|
2658
2080
|
return user;
|
|
2659
2081
|
}
|
|
2660
2082
|
};
|
|
@@ -2909,7 +2331,7 @@ var ComponentManager = class {
|
|
|
2909
2331
|
options.value && container.addTextDisplayComponents(new TextDisplayBuilder().setContent(options.value));
|
|
2910
2332
|
}
|
|
2911
2333
|
static field(container, field) {
|
|
2912
|
-
const hasText = "name" in field
|
|
2334
|
+
const hasText = ("name" in field || "value" in field) && (field.name || field.value);
|
|
2913
2335
|
if ("button" in field && Array.isArray(field.button) && field.button.length > 0) {
|
|
2914
2336
|
const actionRow = new ActionRowBuilder4().addComponents(field.button);
|
|
2915
2337
|
if (hasText) this.fieldAddText(container, { name: field.name, value: field.value });
|
|
@@ -3114,46 +2536,10 @@ var ButtonManager = class _ButtonManager {
|
|
|
3114
2536
|
}
|
|
3115
2537
|
};
|
|
3116
2538
|
|
|
3117
|
-
// src/
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
queue;
|
|
3122
|
-
// File d'attente des fonctions de résolution
|
|
3123
|
-
constructor() {
|
|
3124
|
-
this._locked = false;
|
|
3125
|
-
this.queue = [];
|
|
3126
|
-
}
|
|
3127
|
-
/**
|
|
3128
|
-
* Verrouille le mutex. Si le mutex est déjà verrouillé, la méthode retourne une promesse qui sera résolue une fois que le mutex sera disponible.
|
|
3129
|
-
* @returns Une promesse résolue lorsque le mutex est verrouillé.
|
|
3130
|
-
*/
|
|
3131
|
-
async lock() {
|
|
3132
|
-
if (this._locked) {
|
|
3133
|
-
return new Promise((resolve2) => {
|
|
3134
|
-
this.queue.push(resolve2);
|
|
3135
|
-
});
|
|
3136
|
-
}
|
|
3137
|
-
this._locked = true;
|
|
3138
|
-
return Promise.resolve();
|
|
3139
|
-
}
|
|
3140
|
-
/**
|
|
3141
|
-
* Déverrouille le mutex. Si une file d'attente existe, débloque le prochain élément dans la file.
|
|
3142
|
-
*/
|
|
3143
|
-
unlock() {
|
|
3144
|
-
if (this.queue.length > 0) {
|
|
3145
|
-
const nextResolve = this.queue.shift();
|
|
3146
|
-
if (nextResolve) {
|
|
3147
|
-
nextResolve();
|
|
3148
|
-
}
|
|
3149
|
-
return;
|
|
3150
|
-
}
|
|
3151
|
-
this._locked = false;
|
|
3152
|
-
}
|
|
3153
|
-
get locked() {
|
|
3154
|
-
return this._locked;
|
|
3155
|
-
}
|
|
3156
|
-
};
|
|
2539
|
+
// src/index.ts
|
|
2540
|
+
import { Time as Time3 } from "@spatulox/utils";
|
|
2541
|
+
import { Log as Log18 } from "@spatulox/utils";
|
|
2542
|
+
import { SimpleMutex } from "@spatulox/utils";
|
|
3157
2543
|
|
|
3158
2544
|
// src/constants/DiscordRegex.ts
|
|
3159
2545
|
var DiscordRegex = class {
|
|
@@ -3278,7 +2664,7 @@ export {
|
|
|
3278
2664
|
EmbedManager,
|
|
3279
2665
|
FileManager,
|
|
3280
2666
|
GuildManager,
|
|
3281
|
-
Log,
|
|
2667
|
+
Log18 as Log,
|
|
3282
2668
|
ModalFieldType,
|
|
3283
2669
|
ModalManager,
|
|
3284
2670
|
ReactionManager,
|
|
@@ -3286,7 +2672,7 @@ export {
|
|
|
3286
2672
|
SimpleColor,
|
|
3287
2673
|
SimpleDiscordBotInfo,
|
|
3288
2674
|
SimpleMutex,
|
|
3289
|
-
Time,
|
|
2675
|
+
Time3 as Time,
|
|
3290
2676
|
UserManager,
|
|
3291
2677
|
WebhookManager
|
|
3292
2678
|
};
|