@spatulox/simplediscordbot 1.0.24 → 1.0.26

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.
Files changed (37) hide show
  1. package/.env.example +2 -0
  2. package/dist/SimpleDiscordBotInfo.js +14 -0
  3. package/dist/bot/Bot.js +92 -0
  4. package/dist/bot/BotEnv.js +24 -0
  5. package/dist/bot/BotInteraction.js +74 -0
  6. package/dist/bot/BotLog.js +134 -0
  7. package/dist/bot/BotMessage.js +110 -0
  8. package/dist/manager/FileManager.js +136 -0
  9. package/dist/manager/builder/SendableComponentBuilder.js +62 -0
  10. package/dist/manager/direct/BasicUserManager.js +81 -0
  11. package/dist/manager/direct/UserManager.js +18 -0
  12. package/dist/manager/guild/ChannelManager/ForumChannelManager.js +33 -0
  13. package/dist/manager/guild/ChannelManager/GuildChannelList.js +20 -0
  14. package/dist/manager/guild/ChannelManager/GuildChannelManager.js +91 -0
  15. package/dist/manager/guild/ChannelManager/GuildMessageManager.js +93 -0
  16. package/dist/manager/guild/ChannelManager/GuildTextChannelManager.js +33 -0
  17. package/dist/manager/guild/ChannelManager/GuildVoiceChannelManager.js +33 -0
  18. package/dist/manager/guild/ChannelManager/NewsChannelManager.js +33 -0
  19. package/dist/manager/guild/ChannelManager/StageChannelManager.js +33 -0
  20. package/dist/manager/guild/ChannelManager/ThreadChannelManager.js +49 -0
  21. package/dist/manager/guild/GuildManager.js +144 -0
  22. package/dist/manager/guild/GuildUserManager.js +251 -0
  23. package/dist/manager/guild/InviteManager.js +68 -0
  24. package/dist/manager/guild/InviteManager_old.js +89 -0
  25. package/dist/manager/guild/RoleManager.js +83 -0
  26. package/dist/manager/interactions/ModalManager.js +113 -0
  27. package/dist/manager/interactions/SelectMenuManager.js +123 -0
  28. package/dist/manager/messages/EmbedManager.js +161 -0
  29. package/dist/manager/messages/ReactionManager.js +99 -0
  30. package/dist/manager/messages/WebhookManager.js +108 -0
  31. package/dist/type/FolderName.js +9 -0
  32. package/dist/utils/DiscordRegex.js +117 -0
  33. package/dist/utils/Log.js +28 -0
  34. package/dist/utils/SimpleMutex.js +39 -0
  35. package/dist/utils/network/InternetChecker.js +54 -0
  36. package/dist/utils/times/UnitTime.js +85 -0
  37. package/package.json +2 -4
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BasicUserManager = void 0;
4
+ const discord_js_1 = require("discord.js");
5
+ const Bot_1 = require("../../bot/Bot");
6
+ const Log_1 = require("../../utils/Log");
7
+ const SendableComponentBuilder_1 = require("../builder/SendableComponentBuilder");
8
+ class BasicUserManager {
9
+ /**
10
+ * Find member in specific guild
11
+ */
12
+ static async findInGuild(guildId, memberId) {
13
+ try {
14
+ const guild = Bot_1.Bot.client.guilds.cache.get(guildId);
15
+ if (!guild)
16
+ throw new Error(`Guild ${guildId} not found`);
17
+ const member = await guild.members.fetch({ user: memberId, force: true });
18
+ return member ?? null;
19
+ }
20
+ catch (error) {
21
+ Log_1.Log.error(`UserManager: Member ${memberId} not found in ${guildId}`);
22
+ return null;
23
+ }
24
+ }
25
+ /**
26
+ * Check if user is still in guild
27
+ */
28
+ static async isInGuild(guildId, userId) {
29
+ try {
30
+ const guild = Bot_1.Bot.client.guilds.cache.get(guildId);
31
+ if (!guild)
32
+ return false;
33
+ await guild.members.fetch({ user: userId, force: true });
34
+ return true;
35
+ }
36
+ catch (error) {
37
+ return error.code !== 10007; // Unknown Member
38
+ }
39
+ }
40
+ /**
41
+ * Impl
42
+ */
43
+ static async send(user_id_or_user, content_or_component_or_options, component) {
44
+ try {
45
+ let user;
46
+ if (typeof user_id_or_user === 'string') {
47
+ user = await Bot_1.Bot.client.users.fetch(user_id_or_user);
48
+ }
49
+ else {
50
+ user = user_id_or_user;
51
+ }
52
+ const dmChannel = await user.createDM();
53
+ let payload;
54
+ if (component && typeof content_or_component_or_options == "string") { // component + content
55
+ payload = SendableComponentBuilder_1.SendableComponentBuilder.buildMessage(content_or_component_or_options, component);
56
+ }
57
+ else if (typeof content_or_component_or_options === 'string') { // content only
58
+ payload = SendableComponentBuilder_1.SendableComponentBuilder.buildMessage(content_or_component_or_options);
59
+ }
60
+ else if (SendableComponentBuilder_1.SendableComponentBuilder.isSendableComponent(content_or_component_or_options)) { // component only
61
+ payload = SendableComponentBuilder_1.SendableComponentBuilder.buildMessage(content_or_component_or_options);
62
+ }
63
+ else { // MessageCreationOptionOnly
64
+ payload = content_or_component_or_options;
65
+ }
66
+ const message = await dmChannel.send(payload);
67
+ if (user instanceof discord_js_1.GuildMember) {
68
+ Log_1.Log.info(`Sent DM to ${user.id} (${user.user.username}): "${(payload.content || 'Embed/Component').substring(0, 50)}..."`);
69
+ }
70
+ else {
71
+ Log_1.Log.info(`Sent DM to ${user.id} (${user.username}): "${(payload.content || 'Embed/Component').substring(0, 50)}..."`);
72
+ }
73
+ return message;
74
+ }
75
+ catch (error) {
76
+ Log_1.Log.error(`Failed to send DM to ${user_id_or_user}: ${error}`);
77
+ throw new Error(`Cannot send DM to ${user_id_or_user}`);
78
+ }
79
+ }
80
+ }
81
+ exports.BasicUserManager = BasicUserManager;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UserManager = void 0;
4
+ const BasicUserManager_1 = require("./BasicUserManager");
5
+ const Bot_1 = require("../../bot/Bot");
6
+ const Log_1 = require("../../utils/Log");
7
+ class UserManager extends BasicUserManager_1.BasicUserManager {
8
+ static async find(userId) {
9
+ try {
10
+ return await Bot_1.Bot.client.users.fetch(userId);
11
+ }
12
+ catch (error) {
13
+ Log_1.Log.error(`UserManager: Member ${userId} not found`);
14
+ return null;
15
+ }
16
+ }
17
+ }
18
+ exports.UserManager = UserManager;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ForumChannelManager = void 0;
4
+ const GuildChannelManager_1 = require("./GuildChannelManager");
5
+ const discord_js_1 = require("discord.js");
6
+ const Bot_1 = require("../../../bot/Bot");
7
+ const Log_1 = require("../../../utils/Log");
8
+ class ForumChannelManager extends GuildChannelManager_1.GuildChannelManager {
9
+ static async findInGuild(guildId, channelId) {
10
+ const channel = await super.findInGuild(guildId, channelId);
11
+ return channel instanceof discord_js_1.ForumChannel ? channel : null;
12
+ }
13
+ static async find(channelId) {
14
+ const channel = await super.find(channelId);
15
+ return channel instanceof discord_js_1.ForumChannel ? channel : null;
16
+ }
17
+ static findAll(guildId) {
18
+ const guild = Bot_1.Bot.client.guilds.cache.get(guildId);
19
+ if (!guild) {
20
+ Log_1.Log.warn(`Guild ${guildId} not found`);
21
+ return [];
22
+ }
23
+ return Array.from(guild.channels.cache.values()).filter(c => c instanceof discord_js_1.ForumChannel);
24
+ }
25
+ static async create(guildId, name, options) {
26
+ return await super._create(guildId, {
27
+ name,
28
+ type: discord_js_1.ChannelType.GuildForum,
29
+ ...options
30
+ });
31
+ }
32
+ }
33
+ exports.ForumChannelManager = ForumChannelManager;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GuildChannelList = void 0;
4
+ const GuildChannelManager_1 = require("./GuildChannelManager");
5
+ const ForumChannelManager_1 = require("./ForumChannelManager");
6
+ const NewsChannelManager_1 = require("./NewsChannelManager");
7
+ const StageChannelManager_1 = require("./StageChannelManager");
8
+ const GuildTextChannelManager_1 = require("./GuildTextChannelManager");
9
+ const ThreadChannelManager_1 = require("./ThreadChannelManager");
10
+ const GuildVoiceChannelManager_1 = require("./GuildVoiceChannelManager");
11
+ class GuildChannelList {
12
+ }
13
+ exports.GuildChannelList = GuildChannelList;
14
+ GuildChannelList.forum = ForumChannelManager_1.ForumChannelManager;
15
+ GuildChannelList.any = GuildChannelManager_1.GuildChannelManager;
16
+ GuildChannelList.news = NewsChannelManager_1.NewsChannelManager;
17
+ GuildChannelList.stage = StageChannelManager_1.StageChannelManager;
18
+ GuildChannelList.text = GuildTextChannelManager_1.GuildTextChannelManager;
19
+ GuildChannelList.thread = ThreadChannelManager_1.ThreadChannelManager;
20
+ GuildChannelList.voice = GuildVoiceChannelManager_1.GuildVoiceChannelManager;
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GuildChannelManager = void 0;
4
+ const Bot_1 = require("../../../bot/Bot");
5
+ const Log_1 = require("../../../utils/Log");
6
+ const GuildMessageManager_1 = require("./GuildMessageManager");
7
+ class GuildChannelManager {
8
+ /**
9
+ * Recherche un channel par ID dans une guild spécifique
10
+ */
11
+ static async findInGuild(guildId, channelId) {
12
+ try {
13
+ const guild = Bot_1.Bot.client.guilds.cache.get(guildId);
14
+ if (!guild) {
15
+ Log_1.Log.warn(`Guild ${guildId} not found`);
16
+ return null;
17
+ }
18
+ const channel = await guild.channels.fetch(channelId);
19
+ return channel ?? null;
20
+ }
21
+ catch (error) {
22
+ Log_1.Log.error(`Failed to find channel ${channelId} in guild ${guildId}: ${error}`);
23
+ return null;
24
+ }
25
+ }
26
+ static async find(channelId) {
27
+ for (const guild of Bot_1.Bot.client.guilds.cache.values()) {
28
+ try {
29
+ const channel = await guild.channels.fetch(channelId);
30
+ if (channel)
31
+ return channel;
32
+ }
33
+ catch {
34
+ }
35
+ }
36
+ Log_1.Log.warn(`Channel ${channelId} not found in any guild`);
37
+ return null;
38
+ }
39
+ static findAll(guildId) {
40
+ const guild = Bot_1.Bot.client.guilds.cache.get(guildId);
41
+ if (!guild) {
42
+ Log_1.Log.warn(`Guild ${guildId} not found`);
43
+ return [];
44
+ }
45
+ return Array.from(guild.channels.cache.values());
46
+ }
47
+ /**
48
+ * Recherche channels par nom (insensible à la casse)
49
+ */
50
+ static findByName(guildId, name) {
51
+ const guild = Bot_1.Bot.client.guilds.cache.get(guildId);
52
+ if (!guild) {
53
+ Log_1.Log.warn(`Guild ${guildId} not found`);
54
+ return [];
55
+ }
56
+ return Array.from(guild.channels.cache.values())
57
+ .filter(channel => channel.name.toLowerCase().includes(name.toLowerCase()));
58
+ }
59
+ static async _create(guildId, options) {
60
+ try {
61
+ const guild = Bot_1.Bot.client.guilds.cache.get(guildId);
62
+ if (!guild) {
63
+ throw new Error(`Guild ${guildId} not found`);
64
+ }
65
+ const channel = await guild.channels.create(options);
66
+ Log_1.Log.info(`Created channel ${channel.name} (${channel.id}) in guild ${guildId}`);
67
+ return channel;
68
+ }
69
+ catch (error) {
70
+ Log_1.Log.error(`Failed to create channel in guild ${guildId}: ${error}`);
71
+ throw error;
72
+ }
73
+ }
74
+ static async delete(channelId) {
75
+ try {
76
+ const channel = await GuildChannelManager.find(channelId);
77
+ if (!channel) {
78
+ throw new Error(`Channel ${channelId} not found`);
79
+ }
80
+ await channel.delete();
81
+ Log_1.Log.info(`Deleted channel ${channelId}`);
82
+ return true;
83
+ }
84
+ catch (error) {
85
+ Log_1.Log.error(`Failed to delete channel ${channelId}: ${error}`);
86
+ throw error;
87
+ }
88
+ }
89
+ }
90
+ exports.GuildChannelManager = GuildChannelManager;
91
+ GuildChannelManager.message = GuildMessageManager_1.GuildMessageManager;
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GuildMessageManager = void 0;
4
+ const GuildTextChannelManager_1 = require("./GuildTextChannelManager");
5
+ const Log_1 = require("../../../utils/Log");
6
+ const SendableComponentBuilder_1 = require("../../builder/SendableComponentBuilder");
7
+ class GuildMessageManager {
8
+ /**
9
+ * Impl
10
+ */
11
+ static async send(channelId, content_or_component_or_options) {
12
+ try {
13
+ const channel = await GuildTextChannelManager_1.GuildTextChannelManager.find(channelId);
14
+ if (!channel) {
15
+ Log_1.Log.error(`Channel ${channelId} not found in guild`);
16
+ return null;
17
+ }
18
+ let payload;
19
+ if (typeof content_or_component_or_options === 'string') {
20
+ payload = SendableComponentBuilder_1.SendableComponentBuilder.buildMessage(content_or_component_or_options);
21
+ }
22
+ else if (SendableComponentBuilder_1.SendableComponentBuilder.isSendableComponent(content_or_component_or_options) || Array.isArray(content_or_component_or_options)) {
23
+ payload = SendableComponentBuilder_1.SendableComponentBuilder.buildMessage(content_or_component_or_options);
24
+ }
25
+ else {
26
+ payload = content_or_component_or_options;
27
+ }
28
+ return await channel.send(payload);
29
+ }
30
+ catch (error) {
31
+ Log_1.Log.error(`Failed to send message to ${channelId}: ${error}`);
32
+ throw error;
33
+ }
34
+ }
35
+ /**
36
+ * Delete message
37
+ */
38
+ static async delete(channelId, messageId) {
39
+ try {
40
+ const channel = await GuildTextChannelManager_1.GuildTextChannelManager.find(channelId);
41
+ if (!channel) {
42
+ Log_1.Log.error(`Channel ${channelId} not found`);
43
+ return false;
44
+ }
45
+ const message = await channel.messages.fetch(messageId);
46
+ await message.delete();
47
+ Log_1.Log.info(`Deleted message ${messageId} from ${channelId}`);
48
+ return true;
49
+ }
50
+ catch (error) {
51
+ Log_1.Log.error(`Failed to delete message ${messageId} from ${channelId}: ${error}`);
52
+ return false;
53
+ }
54
+ }
55
+ /**
56
+ * Fetch messages (last X messages, default 10)
57
+ */
58
+ static async fetch(channelId, limit = 10) {
59
+ try {
60
+ const channel = await GuildTextChannelManager_1.GuildTextChannelManager.find(channelId);
61
+ if (!channel) {
62
+ Log_1.Log.error(`Channel ${channelId} not found`);
63
+ return [];
64
+ }
65
+ const messages = await channel.messages.fetch({ limit });
66
+ Log_1.Log.info(`Fetched ${messages.size} messages from ${channelId}`);
67
+ return Array.from(messages.values());
68
+ }
69
+ catch (error) {
70
+ Log_1.Log.error(`Failed to fetch messages from ${channelId}: ${error}`);
71
+ return [];
72
+ }
73
+ }
74
+ /**
75
+ * Fetch single message
76
+ */
77
+ static async fetchOne(channelId, messageId) {
78
+ try {
79
+ const channel = await GuildTextChannelManager_1.GuildTextChannelManager.find(channelId);
80
+ if (!channel) {
81
+ Log_1.Log.error(`Channel ${channelId} not found`);
82
+ return null;
83
+ }
84
+ const message = await channel.messages.fetch(messageId);
85
+ return message;
86
+ }
87
+ catch (error) {
88
+ Log_1.Log.error(`Failed to fetch message ${messageId} from ${channelId}: ${error}`);
89
+ return null;
90
+ }
91
+ }
92
+ }
93
+ exports.GuildMessageManager = GuildMessageManager;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GuildTextChannelManager = void 0;
4
+ const discord_js_1 = require("discord.js");
5
+ const GuildChannelManager_1 = require("./GuildChannelManager");
6
+ const Bot_1 = require("../../../bot/Bot");
7
+ const Log_1 = require("../../../utils/Log");
8
+ class GuildTextChannelManager extends GuildChannelManager_1.GuildChannelManager {
9
+ static async findInGuild(guildId, channelId) {
10
+ const channel = await super.findInGuild(guildId, channelId);
11
+ return channel?.isTextBased() ? channel : null;
12
+ }
13
+ static async find(channelId) {
14
+ const channel = await super.find(channelId);
15
+ return channel?.isTextBased() ? channel : null;
16
+ }
17
+ static findAll(guildId) {
18
+ const guild = Bot_1.Bot.client.guilds.cache.get(guildId);
19
+ if (!guild) {
20
+ Log_1.Log.warn(`Guild ${guildId} not found`);
21
+ return [];
22
+ }
23
+ return Array.from(guild.channels.cache.values()).filter(c => c instanceof discord_js_1.TextChannel);
24
+ }
25
+ static async create(guildId, name, options) {
26
+ return await super._create(guildId, {
27
+ name,
28
+ type: discord_js_1.ChannelType.GuildText,
29
+ ...options
30
+ });
31
+ }
32
+ }
33
+ exports.GuildTextChannelManager = GuildTextChannelManager;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GuildVoiceChannelManager = void 0;
4
+ const discord_js_1 = require("discord.js");
5
+ const GuildChannelManager_1 = require("./GuildChannelManager");
6
+ const Bot_1 = require("../../../bot/Bot");
7
+ const Log_1 = require("../../../utils/Log");
8
+ class GuildVoiceChannelManager extends GuildChannelManager_1.GuildChannelManager {
9
+ static async findInGuild(guildId, channelId) {
10
+ const channel = await super.findInGuild(guildId, channelId);
11
+ return channel?.isVoiceBased() ? channel : null;
12
+ }
13
+ static async find(channelId) {
14
+ const channel = await super.find(channelId);
15
+ return channel?.isVoiceBased() ? channel : null;
16
+ }
17
+ static findAll(guildId) {
18
+ const guild = Bot_1.Bot.client.guilds.cache.get(guildId);
19
+ if (!guild) {
20
+ Log_1.Log.warn(`Guild ${guildId} not found`);
21
+ return [];
22
+ }
23
+ return Array.from(guild.channels.cache.values()).filter(c => c instanceof discord_js_1.VoiceChannel);
24
+ }
25
+ static async create(guildId, name, options) {
26
+ return await super._create(guildId, {
27
+ name,
28
+ type: discord_js_1.ChannelType.GuildVoice,
29
+ ...options
30
+ });
31
+ }
32
+ }
33
+ exports.GuildVoiceChannelManager = GuildVoiceChannelManager;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NewsChannelManager = void 0;
4
+ const discord_js_1 = require("discord.js");
5
+ const GuildChannelManager_1 = require("./GuildChannelManager");
6
+ const Bot_1 = require("../../../bot/Bot");
7
+ const Log_1 = require("../../../utils/Log");
8
+ class NewsChannelManager extends GuildChannelManager_1.GuildChannelManager {
9
+ static async findInGuild(guildId, channelId) {
10
+ const channel = await super.findInGuild(guildId, channelId);
11
+ return channel instanceof discord_js_1.NewsChannel ? channel : null;
12
+ }
13
+ static async find(channelId) {
14
+ const channel = await super.find(channelId);
15
+ return channel instanceof discord_js_1.NewsChannel ? channel : null;
16
+ }
17
+ static findAll(guildId) {
18
+ const guild = Bot_1.Bot.client.guilds.cache.get(guildId);
19
+ if (!guild) {
20
+ Log_1.Log.warn(`Guild ${guildId} not found`);
21
+ return [];
22
+ }
23
+ return Array.from(guild.channels.cache.values()).filter(c => c instanceof discord_js_1.NewsChannel);
24
+ }
25
+ static async create(guildId, name, options) {
26
+ return await super._create(guildId, {
27
+ name,
28
+ type: discord_js_1.ChannelType.GuildAnnouncement,
29
+ ...options
30
+ });
31
+ }
32
+ }
33
+ exports.NewsChannelManager = NewsChannelManager;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StageChannelManager = void 0;
4
+ const discord_js_1 = require("discord.js");
5
+ const GuildChannelManager_1 = require("./GuildChannelManager");
6
+ const Bot_1 = require("../../../bot/Bot");
7
+ const Log_1 = require("../../../utils/Log");
8
+ class StageChannelManager extends GuildChannelManager_1.GuildChannelManager {
9
+ static async findInGuild(guildId, channelId) {
10
+ const channel = await super.findInGuild(guildId, channelId);
11
+ return channel instanceof discord_js_1.StageChannel ? channel : null;
12
+ }
13
+ static async find(channelId) {
14
+ const channel = await super.find(channelId);
15
+ return channel instanceof discord_js_1.StageChannel ? channel : null;
16
+ }
17
+ static findAll(guildId) {
18
+ const guild = Bot_1.Bot.client.guilds.cache.get(guildId);
19
+ if (!guild) {
20
+ Log_1.Log.warn(`Guild ${guildId} not found`);
21
+ return [];
22
+ }
23
+ return Array.from(guild.channels.cache.values()).filter(c => c instanceof discord_js_1.StageChannel);
24
+ }
25
+ static async create(guildId, name, options) {
26
+ return await super._create(guildId, {
27
+ name,
28
+ type: discord_js_1.ChannelType.GuildStageVoice,
29
+ ...options
30
+ });
31
+ }
32
+ }
33
+ exports.StageChannelManager = StageChannelManager;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ThreadChannelManager = void 0;
4
+ const GuildChannelManager_1 = require("./GuildChannelManager");
5
+ const GuildTextChannelManager_1 = require("./GuildTextChannelManager");
6
+ const SendableComponentBuilder_1 = require("../../builder/SendableComponentBuilder");
7
+ class ThreadChannelManager {
8
+ static async findInGuild(guildId, channelId) {
9
+ const channel = await GuildChannelManager_1.GuildChannelManager.findInGuild(guildId, channelId);
10
+ return channel?.isThread() ? channel : null;
11
+ }
12
+ static async find(channelId) {
13
+ const channel = await GuildChannelManager_1.GuildChannelManager.find(channelId);
14
+ return channel?.isThread() ? channel : null;
15
+ }
16
+ static findAll(guildId) {
17
+ const channels = GuildChannelManager_1.GuildChannelManager.findAll(guildId);
18
+ return channels.filter(c => c.isThread());
19
+ }
20
+ static async createFromChannel(parentId, options) {
21
+ const channel = await GuildTextChannelManager_1.GuildTextChannelManager.find(parentId);
22
+ if (!channel || !channel.isTextBased()) {
23
+ throw new Error('Parent must be a text-based channel');
24
+ }
25
+ const thread = await channel.threads.create(options);
26
+ return thread;
27
+ }
28
+ static async createFromMessage(message, options) {
29
+ const channel = await GuildChannelManager_1.GuildChannelManager.find(message.id);
30
+ if (!channel)
31
+ throw new Error('Message channel not found');
32
+ return await message.startThread(options);
33
+ }
34
+ /**
35
+ * Impl
36
+ */
37
+ static async send(channelId, content_or_component_or_options) {
38
+ if (typeof content_or_component_or_options == 'string') {
39
+ return await GuildTextChannelManager_1.GuildTextChannelManager.message.send(channelId, content_or_component_or_options);
40
+ }
41
+ else if (SendableComponentBuilder_1.SendableComponentBuilder.isSendableComponent(content_or_component_or_options) || Array.isArray(content_or_component_or_options)) {
42
+ return await GuildTextChannelManager_1.GuildTextChannelManager.message.send(channelId, content_or_component_or_options);
43
+ }
44
+ else {
45
+ return await GuildTextChannelManager_1.GuildTextChannelManager.message.send(channelId, content_or_component_or_options);
46
+ }
47
+ }
48
+ }
49
+ exports.ThreadChannelManager = ThreadChannelManager;
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GuildManager = void 0;
4
+ const discord_js_1 = require("discord.js");
5
+ const Log_1 = require("../../utils/Log");
6
+ const UnitTime_1 = require("../../utils/times/UnitTime");
7
+ const GuildUserManager_1 = require("./GuildUserManager");
8
+ const Bot_1 = require("../../bot/Bot");
9
+ const GuildChannelManager_1 = require("./ChannelManager/GuildChannelManager");
10
+ const RoleManager_1 = require("./RoleManager");
11
+ const GuildChannelList_1 = require("./ChannelManager/GuildChannelList");
12
+ const InviteManager_1 = require("./InviteManager");
13
+ class GuildManager {
14
+ static list() {
15
+ return Array.from(Bot_1.Bot.client.guilds.cache.values());
16
+ }
17
+ static async find(guild_id) {
18
+ return await Bot_1.Bot.client.guilds.fetch(guild_id);
19
+ }
20
+ /**
21
+ * Search channel by ID (TextChannel, DMChannel, ThreadChannel)
22
+ */
23
+ static async searchChannel(guildId, channelId) {
24
+ try {
25
+ return await GuildChannelManager_1.GuildChannelManager.findInGuild(guildId, channelId);
26
+ }
27
+ catch (error) {
28
+ Log_1.Log.error(`Failed to fetch channel ${channelId}: ${error}`);
29
+ return null;
30
+ }
31
+ }
32
+ /**
33
+ * Search guild member by ID
34
+ */
35
+ static async searchMember(memberId, guildId) {
36
+ try {
37
+ return await this.user.findInGuild(guildId, guildId);
38
+ }
39
+ catch (error) {
40
+ Log_1.Log.error(`Failed to fetch member ${memberId} in guild ${guildId}: ${error}`);
41
+ return null;
42
+ }
43
+ }
44
+ /**
45
+ * Check if member is still in guild
46
+ */
47
+ static async isMemberInGuild(memberId, guildId) {
48
+ try {
49
+ return await this.user.isInGuild(memberId, guildId);
50
+ }
51
+ catch (error) {
52
+ return error.code !== 10007; // Unknown Member
53
+ }
54
+ }
55
+ /**
56
+ * Fetch all members with retry (heavy operation)
57
+ */
58
+ static async fetchAllMembers(guildId, MAX_ATTEMPTS = 3, RETRY_DELAY = UnitTime_1.Time.minute.MIN_05.toMilliseconds()) {
59
+ let guild;
60
+ if (guildId instanceof discord_js_1.Guild) {
61
+ guild = guildId;
62
+ }
63
+ else {
64
+ let tmp = Bot_1.Bot.client.guilds.cache.get(guildId);
65
+ if (!tmp)
66
+ throw new Error(`Guild ${guildId} not found`);
67
+ guild = tmp;
68
+ }
69
+ for (let attempt = 1; attempt <= MAX_ATTEMPTS; attempt++) {
70
+ try {
71
+ Log_1.Log.info(`UserManager: Fetching ${guild.name} members (attempt ${attempt})`);
72
+ return await guild.members.fetch();
73
+ }
74
+ catch (error) {
75
+ Log_1.Log.error(`UserManager: Fetch failed (attempt ${attempt}): ${error}`);
76
+ if (attempt < MAX_ATTEMPTS) {
77
+ await new Promise(r => setTimeout(r, RETRY_DELAY));
78
+ }
79
+ }
80
+ }
81
+ throw new Error(`Failed to fetch members after ${MAX_ATTEMPTS} attempts`);
82
+ }
83
+ static async listban(guildId, limit) {
84
+ const guild = Bot_1.Bot.client.guilds.cache.get(guildId);
85
+ if (!guild) {
86
+ throw new Error(`Guild ${guildId} not found`);
87
+ }
88
+ try {
89
+ const bans = await guild.bans.fetch({ limit });
90
+ return Array.from(bans.values());
91
+ }
92
+ catch (error) {
93
+ Log_1.Log.error(`Failed to list bans in guild ${guildId}: ${error}`);
94
+ throw error;
95
+ }
96
+ }
97
+ static async moveMember(memberId, fromChannelId, toChannelId) {
98
+ try {
99
+ const guild = Bot_1.Bot.client.guilds.cache.find(g => g.channels.cache.has(fromChannelId) || g.channels.cache.has(toChannelId));
100
+ if (!guild) {
101
+ throw new Error(`Guild containing channels ${fromChannelId} or ${toChannelId} not found`);
102
+ }
103
+ const member = await guild.members.fetch(memberId).catch(() => null);
104
+ if (!member) {
105
+ throw new Error(`Member ${memberId} not found in guild ${guild.id}`);
106
+ }
107
+ const fromChannel = guild.channels.cache.get(fromChannelId);
108
+ const toChannel = guild.channels.cache.get(toChannelId);
109
+ if (!fromChannel) {
110
+ throw new Error(`From channel ${fromChannelId} not found`);
111
+ }
112
+ if (!toChannel) {
113
+ throw new Error(`To channel ${toChannelId} not found`);
114
+ }
115
+ if (!(fromChannel instanceof discord_js_1.VoiceChannel || fromChannel instanceof discord_js_1.StageChannel)) {
116
+ throw new Error(`From channel ${fromChannelId} is not a voice/stage channel`);
117
+ }
118
+ if (!(toChannel instanceof discord_js_1.VoiceChannel || toChannel instanceof discord_js_1.StageChannel)) {
119
+ throw new Error(`To channel ${toChannelId} is not a voice/stage channel`);
120
+ }
121
+ if (member.voice.channelId !== fromChannelId) {
122
+ throw new Error(`Member ${memberId} is not in channel ${fromChannelId}`);
123
+ }
124
+ try {
125
+ await member.voice.setChannel(toChannel);
126
+ Log_1.Log.info(`Moved member ${memberId} from ${fromChannelId} to ${toChannelId}`);
127
+ }
128
+ catch (error) {
129
+ Log_1.Log.error(`Failed to move member ${memberId} from ${fromChannelId} to ${toChannelId}: ${error}`);
130
+ throw error;
131
+ }
132
+ return true;
133
+ }
134
+ catch (e) {
135
+ Log_1.Log.error(`Failed to move member ${e}`);
136
+ return false;
137
+ }
138
+ }
139
+ }
140
+ exports.GuildManager = GuildManager;
141
+ GuildManager.role = RoleManager_1.RoleManager;
142
+ GuildManager.user = GuildUserManager_1.GuildUserManager;
143
+ GuildManager.channel = GuildChannelList_1.GuildChannelList;
144
+ GuildManager.invite = InviteManager_1.InviteManager;