@spatulox/simplediscordbot 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +2 -0
- package/LICENSE.md +21 -0
- package/README.md +1 -0
- package/dist/bot/Bot.js +107 -0
- package/dist/bot/BotEnv.js +29 -0
- package/dist/bot/BotLog.js +90 -0
- package/dist/bot/BotMessage.js +79 -0
- package/dist/cli/BaseCLI.js +165 -0
- package/dist/cli/GenerationCLI/ContextMenuGeneratorCLI.js +109 -0
- package/dist/cli/GenerationCLI/GenerationCLI.js +25 -0
- package/dist/cli/GenerationCLI/InteractionGeneratorCLI.js +20 -0
- package/dist/cli/GenerationCLI/ModalGeneratorCLI.js +166 -0
- package/dist/cli/GenerationCLI/SlashCommandsGeneratorCLI.js +221 -0
- package/dist/cli/GenerationCLI.js +36 -0
- package/dist/cli/GuildListManager.js +61 -0
- package/dist/cli/InputCLI.js +25 -0
- package/dist/cli/InteractionCLI/InteractionCLI.js +30 -0
- package/dist/cli/InteractionCLI/InteractionCLIManager.js +80 -0
- package/dist/cli/InteractionCLI.js +109 -0
- package/dist/cli/MainCLI.js +32 -0
- package/dist/cli/type/ContextMenuConfig.js +2 -0
- package/dist/cli/type/InteractionType.js +14 -0
- package/dist/cli/type/SlashCommandConfig.js +2 -0
- package/dist/index.js +31 -0
- package/dist/manager/FileManager.js +136 -0
- package/dist/manager/direct/UserManager.js +76 -0
- package/dist/manager/discord/ChannelManager.js +48 -0
- package/dist/manager/discord/DiscordRegex.js +114 -0
- package/dist/manager/discord/GuildManager.js +67 -0
- package/dist/manager/discord/InviteManager.js +89 -0
- package/dist/manager/discord/RoleManager.js +83 -0
- package/dist/manager/discord/UserManager.js +69 -0
- package/dist/manager/guild/ChannelManager/ForumChannelManager.js +33 -0
- package/dist/manager/guild/ChannelManager/GuildChannelList.js +20 -0
- package/dist/manager/guild/ChannelManager/GuildChannelManager.js +91 -0
- package/dist/manager/guild/ChannelManager/GuildMessageManager.js +85 -0
- package/dist/manager/guild/ChannelManager/GuildTextChannelManager.js +33 -0
- package/dist/manager/guild/ChannelManager/GuildVoiceChannelManager.js +33 -0
- package/dist/manager/guild/ChannelManager/NewsChannelManager.js +33 -0
- package/dist/manager/guild/ChannelManager/StageChannelManager.js +33 -0
- package/dist/manager/guild/ChannelManager/ThreadChannelManager.js +34 -0
- package/dist/manager/guild/GuildManager.js +134 -0
- package/dist/manager/guild/GuildUserManager.js +212 -0
- package/dist/manager/guild/InviteManager.js +68 -0
- package/dist/manager/guild/InviteManager_old.js +89 -0
- package/dist/manager/guild/RoleManager.js +83 -0
- package/dist/manager/hadlers_old/builder/ModalManager.js +111 -0
- package/dist/manager/hadlers_old/builder/delete.js +49 -0
- package/dist/manager/hadlers_old/builder/deploy.js +225 -0
- package/dist/manager/hadlers_old/builder/interactions/CommandManager.js +14 -0
- package/dist/manager/hadlers_old/builder/interactions/ContextMenuManager.js +14 -0
- package/dist/manager/hadlers_old/builder/interactions/InteractionBase.js +341 -0
- package/dist/manager/hadlers_old/builder/interactions/InteractionManager.js +65 -0
- package/dist/manager/hadlers_old/builder/list.js +166 -0
- package/dist/manager/messages/EmbedManager.js +131 -0
- package/dist/manager/messages/ReactionManager.js +99 -0
- package/dist/manager/messages/WebhookManager.js +105 -0
- package/dist/type/FolderName.js +9 -0
- package/dist/utils/DiscordRegex.js +116 -0
- package/dist/utils/Log.js +28 -0
- package/dist/utils/SimpleMutex.js +39 -0
- package/dist/utils/network/InternetChecker.js +54 -0
- package/dist/utils/times/UnitTime.js +85 -0
- package/package.json +40 -0
|
@@ -0,0 +1,134 @@
|
|
|
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
|
+
/**
|
|
18
|
+
* Search channel by ID (TextChannel, DMChannel, ThreadChannel)
|
|
19
|
+
*/
|
|
20
|
+
static async searchChannel(guildId, channelId) {
|
|
21
|
+
try {
|
|
22
|
+
return await GuildChannelManager_1.GuildChannelManager.findInGuild(guildId, channelId);
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
Log_1.Log.error(`Failed to fetch channel ${channelId}: ${error}`);
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Search guild member by ID
|
|
31
|
+
*/
|
|
32
|
+
static async searchMember(memberId, guildId) {
|
|
33
|
+
try {
|
|
34
|
+
return await this.user.findInGuild(guildId, guildId);
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
Log_1.Log.error(`Failed to fetch member ${memberId} in guild ${guildId}: ${error}`);
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Check if member is still in guild
|
|
43
|
+
*/
|
|
44
|
+
static async isMemberInGuild(memberId, guildId) {
|
|
45
|
+
try {
|
|
46
|
+
return await this.user.isInGuild(memberId, guildId);
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
return error.code !== 10007; // Unknown Member
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Fetch all members with retry (heavy operation)
|
|
54
|
+
*/
|
|
55
|
+
static async fetchAllMembers(guildId, MAX_ATTEMPTS = 3, RETRY_DELAY = UnitTime_1.Time.minute.MIN_05.toMilliseconds()) {
|
|
56
|
+
const guild = Bot_1.Bot.client.guilds.cache.get(guildId);
|
|
57
|
+
if (!guild)
|
|
58
|
+
throw new Error(`Guild ${guildId} not found`);
|
|
59
|
+
for (let attempt = 1; attempt <= MAX_ATTEMPTS; attempt++) {
|
|
60
|
+
try {
|
|
61
|
+
Log_1.Log.info(`UserManager: Fetching ${guild.name} members (attempt ${attempt})`);
|
|
62
|
+
return await guild.members.fetch();
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
Log_1.Log.error(`UserManager: Fetch failed (attempt ${attempt}): ${error}`);
|
|
66
|
+
if (attempt < MAX_ATTEMPTS) {
|
|
67
|
+
await new Promise(r => setTimeout(r, RETRY_DELAY));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
throw new Error(`Failed to fetch members after ${MAX_ATTEMPTS} attempts`);
|
|
72
|
+
}
|
|
73
|
+
static async listban(guildId, limit) {
|
|
74
|
+
const guild = Bot_1.Bot.client.guilds.cache.get(guildId);
|
|
75
|
+
if (!guild) {
|
|
76
|
+
throw new Error(`Guild ${guildId} not found`);
|
|
77
|
+
}
|
|
78
|
+
try {
|
|
79
|
+
const bans = await guild.bans.fetch({ limit });
|
|
80
|
+
return Array.from(bans.values());
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
Log_1.Log.error(`Failed to list bans in guild ${guildId}: ${error}`);
|
|
84
|
+
throw error;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
static async moveMember(memberId, fromChannelId, toChannelId) {
|
|
88
|
+
try {
|
|
89
|
+
const guild = Bot_1.Bot.client.guilds.cache.find(g => g.channels.cache.has(fromChannelId) || g.channels.cache.has(toChannelId));
|
|
90
|
+
if (!guild) {
|
|
91
|
+
throw new Error(`Guild containing channels ${fromChannelId} or ${toChannelId} not found`);
|
|
92
|
+
}
|
|
93
|
+
const member = await guild.members.fetch(memberId).catch(() => null);
|
|
94
|
+
if (!member) {
|
|
95
|
+
throw new Error(`Member ${memberId} not found in guild ${guild.id}`);
|
|
96
|
+
}
|
|
97
|
+
const fromChannel = guild.channels.cache.get(fromChannelId);
|
|
98
|
+
const toChannel = guild.channels.cache.get(toChannelId);
|
|
99
|
+
if (!fromChannel) {
|
|
100
|
+
throw new Error(`From channel ${fromChannelId} not found`);
|
|
101
|
+
}
|
|
102
|
+
if (!toChannel) {
|
|
103
|
+
throw new Error(`To channel ${toChannelId} not found`);
|
|
104
|
+
}
|
|
105
|
+
if (!(fromChannel instanceof discord_js_1.VoiceChannel || fromChannel instanceof discord_js_1.StageChannel)) {
|
|
106
|
+
throw new Error(`From channel ${fromChannelId} is not a voice/stage channel`);
|
|
107
|
+
}
|
|
108
|
+
if (!(toChannel instanceof discord_js_1.VoiceChannel || toChannel instanceof discord_js_1.StageChannel)) {
|
|
109
|
+
throw new Error(`To channel ${toChannelId} is not a voice/stage channel`);
|
|
110
|
+
}
|
|
111
|
+
if (member.voice.channelId !== fromChannelId) {
|
|
112
|
+
throw new Error(`Member ${memberId} is not in channel ${fromChannelId}`);
|
|
113
|
+
}
|
|
114
|
+
try {
|
|
115
|
+
await member.voice.setChannel(toChannel);
|
|
116
|
+
Log_1.Log.info(`Moved member ${memberId} from ${fromChannelId} to ${toChannelId}`);
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
Log_1.Log.error(`Failed to move member ${memberId} from ${fromChannelId} to ${toChannelId}: ${error}`);
|
|
120
|
+
throw error;
|
|
121
|
+
}
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
catch (e) {
|
|
125
|
+
Log_1.Log.error(`Failed to move member ${e}`);
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
exports.GuildManager = GuildManager;
|
|
131
|
+
GuildManager.role = RoleManager_1.RoleManager;
|
|
132
|
+
GuildManager.user = GuildUserManager_1.GuildUserManager;
|
|
133
|
+
GuildManager.channel = GuildChannelList_1.GuildChannelList;
|
|
134
|
+
GuildManager.invite = InviteManager_1.InviteManager;
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GuildUserManager = void 0;
|
|
4
|
+
const Bot_1 = require("../../bot/Bot");
|
|
5
|
+
const Log_1 = require("../../utils/Log");
|
|
6
|
+
const UserManager_1 = require("../direct/UserManager");
|
|
7
|
+
class GuildUserManager extends UserManager_1.UserManager {
|
|
8
|
+
/**
|
|
9
|
+
* Check if user is banned from guild
|
|
10
|
+
*/
|
|
11
|
+
static async isBanned(guildId, userId) {
|
|
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 false;
|
|
17
|
+
}
|
|
18
|
+
const ban = await guild.bans.fetch(userId);
|
|
19
|
+
return !!ban;
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
Log_1.Log.debug(`User ${userId} is not banned from guild ${guildId}`);
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Deconnect a member from a voice
|
|
28
|
+
*/
|
|
29
|
+
static async deconnectFromVoice(guildId, memberId) {
|
|
30
|
+
try {
|
|
31
|
+
const guild = Bot_1.Bot.client.guilds.cache.get(guildId);
|
|
32
|
+
if (!guild) {
|
|
33
|
+
throw new Error(`Guild ${guildId} not found`);
|
|
34
|
+
}
|
|
35
|
+
const member = await guild.members.fetch(memberId);
|
|
36
|
+
if (!member.voice.channel) {
|
|
37
|
+
throw new Error(`Member ${memberId} is not in a voice channel`);
|
|
38
|
+
}
|
|
39
|
+
await member.voice.disconnect();
|
|
40
|
+
Log_1.Log.info(`Disconnected member ${memberId} from voice in guild ${guildId}`);
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
Log_1.Log.error(`Failed to disconnect member ${memberId} from voice in ${guildId}: ${error}`);
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Check if a member is in voice
|
|
49
|
+
*/
|
|
50
|
+
static async isInVoice(memberId, guildId) {
|
|
51
|
+
try {
|
|
52
|
+
const guild = Bot_1.Bot.client.guilds.cache.get(guildId);
|
|
53
|
+
if (!guild)
|
|
54
|
+
return false;
|
|
55
|
+
const member = await guild.members.fetch(memberId);
|
|
56
|
+
return member.voice.channelId !== null;
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
Log_1.Log.debug(`Member ${memberId} not found or not in voice in guild ${guildId}`);
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Mute a member
|
|
65
|
+
*/
|
|
66
|
+
static async mute(guildId, memberId, reason) {
|
|
67
|
+
try {
|
|
68
|
+
const guild = Bot_1.Bot.client.guilds.cache.get(guildId);
|
|
69
|
+
if (!guild)
|
|
70
|
+
throw new Error(`Guild ${guildId} not found`);
|
|
71
|
+
const member = await guild.members.fetch(memberId);
|
|
72
|
+
await member.voice.setMute(true, reason);
|
|
73
|
+
Log_1.Log.info(`Server muted ${memberId} in guild ${guildId}: ${reason || 'No reason'}`);
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
Log_1.Log.error(`Failed to server mute ${memberId} in ${guildId}:, error`);
|
|
77
|
+
throw error;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Unmute a member
|
|
82
|
+
*/
|
|
83
|
+
static async unmute(guildId, memberId, reason) {
|
|
84
|
+
try {
|
|
85
|
+
const guild = Bot_1.Bot.client.guilds.cache.get(guildId);
|
|
86
|
+
if (!guild)
|
|
87
|
+
throw new Error(`Guild ${guildId} not found`);
|
|
88
|
+
const member = await guild.members.fetch(memberId);
|
|
89
|
+
await member.voice.setMute(false, reason);
|
|
90
|
+
Log_1.Log.info(`Server unmuted ${memberId} in guild ${guildId}: ${reason || 'No reason'}`);
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
Log_1.Log.error(`Failed to server unmute ${memberId} in ${guildId}: ${error}`);
|
|
94
|
+
throw error;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Deafen a member
|
|
99
|
+
*/
|
|
100
|
+
static async deafen(guildId, memberId, reason) {
|
|
101
|
+
try {
|
|
102
|
+
const guild = Bot_1.Bot.client.guilds.cache.get(guildId);
|
|
103
|
+
if (!guild)
|
|
104
|
+
throw new Error(`Guild ${guildId} not found`);
|
|
105
|
+
const member = await guild.members.fetch(memberId);
|
|
106
|
+
await member.voice.setDeaf(true, reason);
|
|
107
|
+
Log_1.Log.info(`Server deafened ${memberId} in guild ${guildId}: ${reason || 'No reason'}`);
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
Log_1.Log.error(`Failed to server deafen ${memberId} in ${guildId}: ${error}`);
|
|
111
|
+
throw error;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Undeafen member voice
|
|
116
|
+
*/
|
|
117
|
+
static async undeafen(guildId, memberId, reason) {
|
|
118
|
+
try {
|
|
119
|
+
const guild = Bot_1.Bot.client.guilds.cache.get(guildId);
|
|
120
|
+
if (!guild)
|
|
121
|
+
throw new Error(`Guild ${guildId} not found`);
|
|
122
|
+
const member = await guild.members.fetch(memberId);
|
|
123
|
+
await member.voice.setDeaf(false, reason);
|
|
124
|
+
Log_1.Log.info(`Server undeafened ${memberId} in guild ${guildId}: ${reason || 'No reason'}`);
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
Log_1.Log.error(`Failed to server undeafen ${memberId} in ${guildId}: ${error}`);
|
|
128
|
+
throw error;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Timeout a member
|
|
133
|
+
*/
|
|
134
|
+
static async timeout(guildId, memberId, duration, reason) {
|
|
135
|
+
try {
|
|
136
|
+
const guild = Bot_1.Bot.client.guilds.cache.get(guildId);
|
|
137
|
+
if (!guild)
|
|
138
|
+
throw new Error(`Guild ${guildId} not found`);
|
|
139
|
+
const member = await guild.members.fetch(memberId);
|
|
140
|
+
const expires = Date.now() + duration;
|
|
141
|
+
await member.timeout(expires, reason);
|
|
142
|
+
Log_1.Log.info(`Timed out ${memberId} for ${duration}ms in guild ${guildId}: ${reason || 'No reason'}`);
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
Log_1.Log.error(`Failed to timeout ${memberId} in ${guildId}: ${error}`);
|
|
146
|
+
throw error;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Remove the timeout of a member
|
|
151
|
+
*/
|
|
152
|
+
static async untimeout(guildId, memberId, reason) {
|
|
153
|
+
try {
|
|
154
|
+
const guild = Bot_1.Bot.client.guilds.cache.get(guildId);
|
|
155
|
+
if (!guild)
|
|
156
|
+
throw new Error(`Guild ${guildId} not found`);
|
|
157
|
+
const member = await guild.members.fetch(memberId);
|
|
158
|
+
await member.timeout(null, reason);
|
|
159
|
+
Log_1.Log.info(`Untimed out ${memberId} in guild ${guildId}: ${reason || 'No reason'}`);
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
Log_1.Log.error(`Failed to untimeout ${memberId} in ${guildId}: ${error}`);
|
|
163
|
+
throw error;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Kick a member
|
|
168
|
+
*/
|
|
169
|
+
static async kick(guildId, memberId, reason) {
|
|
170
|
+
try {
|
|
171
|
+
const guild = Bot_1.Bot.client.guilds.cache.get(guildId);
|
|
172
|
+
if (!guild)
|
|
173
|
+
throw new Error(`Guild ${guildId} not found`);
|
|
174
|
+
const member = await guild.members.fetch(memberId);
|
|
175
|
+
await member.kick(reason);
|
|
176
|
+
Log_1.Log.info(`Kicked ${memberId} from guild ${guildId}: ${reason || 'No reason'}`);
|
|
177
|
+
}
|
|
178
|
+
catch (error) {
|
|
179
|
+
Log_1.Log.error(`Failed to kick ${memberId} from ${guildId}: ${error}`);
|
|
180
|
+
throw error;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
static async ban(guildId, userId, banOption) {
|
|
184
|
+
const guild = Bot_1.Bot.client.guilds.cache.get(guildId);
|
|
185
|
+
if (!guild) {
|
|
186
|
+
throw new Error(`Guild ${guildId} not found`);
|
|
187
|
+
}
|
|
188
|
+
try {
|
|
189
|
+
await guild.members.ban(userId, banOption);
|
|
190
|
+
Log_1.Log.info(`Banned user ${userId} from guild ${guildId}`);
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
Log_1.Log.error(`Failed to ban user ${userId} from guild ${guildId}: ${error}`);
|
|
194
|
+
throw error;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
static async unban(guildId, userId, reason) {
|
|
198
|
+
const guild = Bot_1.Bot.client.guilds.cache.get(guildId);
|
|
199
|
+
if (!guild) {
|
|
200
|
+
throw new Error(`Guild ${guildId} not found`);
|
|
201
|
+
}
|
|
202
|
+
try {
|
|
203
|
+
await guild.members.unban(userId, reason);
|
|
204
|
+
Log_1.Log.info(`Unbanned user ${userId} from guild ${guildId}`);
|
|
205
|
+
}
|
|
206
|
+
catch (error) {
|
|
207
|
+
Log_1.Log.error(`Failed to unban user ${userId} from guild ${guildId}: ${error}`);
|
|
208
|
+
throw error;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
exports.GuildUserManager = GuildUserManager;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InviteManager = void 0;
|
|
4
|
+
const Log_1 = require("../../utils/Log");
|
|
5
|
+
const Bot_1 = require("../../bot/Bot");
|
|
6
|
+
const GuildChannelManager_1 = require("./ChannelManager/GuildChannelManager");
|
|
7
|
+
class InviteManager {
|
|
8
|
+
/**
|
|
9
|
+
* Create an invite for a channel
|
|
10
|
+
*/
|
|
11
|
+
static async create(channelId, options = {}) {
|
|
12
|
+
try {
|
|
13
|
+
const channel = await GuildChannelManager_1.GuildChannelManager.find(channelId);
|
|
14
|
+
if (!channel) {
|
|
15
|
+
throw new Error(`Channel ${channelId} not found`);
|
|
16
|
+
}
|
|
17
|
+
const guild = channel.guild;
|
|
18
|
+
const inviteOptions = {
|
|
19
|
+
maxAge: options.maxAge ?? 86400,
|
|
20
|
+
maxUses: options.maxUses ?? 0,
|
|
21
|
+
temporary: options.temporary ?? false,
|
|
22
|
+
reason: options.reason
|
|
23
|
+
};
|
|
24
|
+
// ✅ guild.invites.create(channelId, options)
|
|
25
|
+
const invite = await guild.invites.create(channelId, inviteOptions);
|
|
26
|
+
Log_1.Log.info(`Created invite ${invite.code} for channel ${channelId}`);
|
|
27
|
+
return invite;
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
Log_1.Log.error(`Failed to create invite for channel ${channelId}: ${error}`);
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Delete an invitation
|
|
36
|
+
*/
|
|
37
|
+
static async delete(invite) {
|
|
38
|
+
try {
|
|
39
|
+
await invite.delete();
|
|
40
|
+
Log_1.Log.info(`Deleted invite ${invite.code} from guild ${invite.guild?.id}`);
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
Log_1.Log.error(`Failed to delete invite ${invite.code}: ${error}`);
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* List every invitation from a guild
|
|
50
|
+
*/
|
|
51
|
+
static async list(guildId) {
|
|
52
|
+
try {
|
|
53
|
+
const guild = Bot_1.Bot.client.guilds.cache.get(guildId);
|
|
54
|
+
if (!guild) {
|
|
55
|
+
throw new Error(`Guild ${guildId} not found`);
|
|
56
|
+
}
|
|
57
|
+
const invites = await guild.invites.fetch();
|
|
58
|
+
const inviteList = Array.from(invites.values());
|
|
59
|
+
Log_1.Log.info(`Fetched ${inviteList.length} invites for guild ${guildId}`);
|
|
60
|
+
return inviteList;
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
Log_1.Log.error(`Failed to fetch invites for guild ${guildId}: ${error}`);
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.InviteManager = InviteManager;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InviteManager = 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
|
+
class InviteManager {
|
|
8
|
+
/**
|
|
9
|
+
* Check if invite is old (more than 1 hour)
|
|
10
|
+
*/
|
|
11
|
+
static isOld(invite, excludedInvite = []) {
|
|
12
|
+
const oneHourAgo = new Date(Date.now() - 60 * 60 * 1000); // 1h
|
|
13
|
+
if (!invite.createdAt) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
return (invite.maxAge !== 0 &&
|
|
17
|
+
!excludedInvite.includes(invite.code) &&
|
|
18
|
+
invite.createdAt < oneHourAgo);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Delete single invite
|
|
22
|
+
*/
|
|
23
|
+
static async delete(invite) {
|
|
24
|
+
try {
|
|
25
|
+
await invite.delete();
|
|
26
|
+
if (invite.createdAt) {
|
|
27
|
+
Log_1.Log.info(`🗑️ Deleted invite \`${invite.code}\` created ${invite.createdAt.toDateString()}`);
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
Log_1.Log.warn(`Invite ${invite.code} deleted but no createdAt`);
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
Log_1.Log.error(`Failed to delete invite ${invite.code}: ${error.message}`);
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Delete all old invites from guild
|
|
40
|
+
*/
|
|
41
|
+
static async cleanupGuild(guildId) {
|
|
42
|
+
try {
|
|
43
|
+
const guild = Bot_1.Bot.client.guilds.cache.get(guildId);
|
|
44
|
+
if (!guild) {
|
|
45
|
+
Log_1.Log.error(`Guild ${guildId} not found for invite cleanup`);
|
|
46
|
+
return 0;
|
|
47
|
+
}
|
|
48
|
+
const invites = await guild.invites.fetch();
|
|
49
|
+
let deletedCount = 0;
|
|
50
|
+
for (const [_code, invite] of invites) {
|
|
51
|
+
if (this.isOld(invite)) {
|
|
52
|
+
const success = await this.delete(invite);
|
|
53
|
+
if (success)
|
|
54
|
+
deletedCount++;
|
|
55
|
+
// Rate limit protection
|
|
56
|
+
await new Promise(r => setTimeout(r, 100));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
Log_1.Log.info(`Invite cleanup ${guild.name}: ${deletedCount} old invites deleted`);
|
|
60
|
+
return deletedCount;
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
Log_1.Log.error(`Invite cleanup failed for ${guildId}: ${error}`);
|
|
64
|
+
return 0;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Get all invites from guild
|
|
69
|
+
*/
|
|
70
|
+
static async fetchGuildInvites(guildId) {
|
|
71
|
+
try {
|
|
72
|
+
const guild = Bot_1.Bot.client.guilds.cache.get(guildId);
|
|
73
|
+
if (!guild)
|
|
74
|
+
throw new Error(`Guild ${guildId} not found`);
|
|
75
|
+
return await guild.invites.fetch();
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
Log_1.Log.error(`Failed to fetch invites for ${guildId}: ${error}`);
|
|
79
|
+
return new discord_js_1.Collection();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Get old invites only
|
|
84
|
+
*/
|
|
85
|
+
static getOldInvites(invites) {
|
|
86
|
+
return invites.filter(invite => this.isOld(invite)).map(invite => invite);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
exports.InviteManager = InviteManager;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RoleManager = void 0;
|
|
4
|
+
const Log_1 = require("../../utils/Log");
|
|
5
|
+
class RoleManager {
|
|
6
|
+
/**
|
|
7
|
+
* Add role - CACHE ONLY
|
|
8
|
+
* @param member - GuildMember ALREADY FETCHED
|
|
9
|
+
* @param roleId - Role ID (string)
|
|
10
|
+
*/
|
|
11
|
+
static async add(member, roleId) {
|
|
12
|
+
try {
|
|
13
|
+
const role = member.roles.cache.get(roleId);
|
|
14
|
+
if (!role) {
|
|
15
|
+
Log_1.Log.warn(`Role ${roleId} not found in cache`);
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
await member.roles.add(role);
|
|
19
|
+
Log_1.Log.info(`✅ Added ${role.name} to ${member.displayName}`);
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
Log_1.Log.error(`Failed to add role ${roleId}: ${error}`);
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Remove role - CACHE ONLY
|
|
29
|
+
* @param member - GuildMember ALREADY FETCHED
|
|
30
|
+
* @param roleIdOrName - Role ID or name
|
|
31
|
+
*/
|
|
32
|
+
static async remove(member, roleIdOrName) {
|
|
33
|
+
try {
|
|
34
|
+
let role;
|
|
35
|
+
if (typeof roleIdOrName === 'string' && roleIdOrName.length === 18) {
|
|
36
|
+
role = member.roles.cache.get(roleIdOrName);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
role = member.roles.cache.find(r => r.id === roleIdOrName || r.name.toLowerCase() === roleIdOrName.toString().toLowerCase());
|
|
40
|
+
}
|
|
41
|
+
if (!role) {
|
|
42
|
+
Log_1.Log.warn(`Role ${roleIdOrName} not found for ${member.displayName}`);
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
await member.roles.remove(role);
|
|
46
|
+
Log_1.Log.info(`✅ Removed ${role.name} from ${member.displayName}`);
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
Log_1.Log.error(`Failed to remove role ${roleIdOrName}: ${error}`);
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Toggle role (add/remove)
|
|
56
|
+
*/
|
|
57
|
+
static async toggle(member, roleIdOrName) {
|
|
58
|
+
const role = member.roles.cache.get(roleIdOrName) ||
|
|
59
|
+
member.roles.cache.find(r => r.name.toLowerCase() === roleIdOrName.toString().toLowerCase());
|
|
60
|
+
if (!role) {
|
|
61
|
+
Log_1.Log.warn(`Role ${roleIdOrName} not found`);
|
|
62
|
+
throw new Error(`Role not found`);
|
|
63
|
+
}
|
|
64
|
+
if (member.roles.cache.has(role.id)) {
|
|
65
|
+
await this.remove(member, role.id);
|
|
66
|
+
return 'removed';
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
await this.add(member, role.id);
|
|
70
|
+
return 'added';
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Check if member has role
|
|
75
|
+
*/
|
|
76
|
+
static hasRole(member, roleIdOrName) {
|
|
77
|
+
if (typeof roleIdOrName === 'string' && roleIdOrName.length === 18) {
|
|
78
|
+
return member.roles.cache.has(roleIdOrName);
|
|
79
|
+
}
|
|
80
|
+
return member.roles.cache.some(r => r.id === roleIdOrName || r.name.toLowerCase() === roleIdOrName.toString().toLowerCase());
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.RoleManager = RoleManager;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ModalManager = void 0;
|
|
4
|
+
const discord_js_1 = require("discord.js");
|
|
5
|
+
const Log_1 = require("../../../utils/Log");
|
|
6
|
+
const FileManager_1 = require("../../FileManager");
|
|
7
|
+
const MAX_COMPONENTS = 5;
|
|
8
|
+
class ModalManager {
|
|
9
|
+
/**
|
|
10
|
+
* Load and build modal from JSON file
|
|
11
|
+
*/
|
|
12
|
+
static async load(name) {
|
|
13
|
+
const formData = await FileManager_1.FileManager.readJsonFile(`./form/${name}.json`);
|
|
14
|
+
if (formData === 'Error') {
|
|
15
|
+
Log_1.Log.error(`Form ${name} not found!`);
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
if (!this.validateForm(formData)) {
|
|
19
|
+
Log_1.Log.error(`${name}.json is not a valid modal json`);
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
return this.buildModal(formData);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Validate form structure
|
|
26
|
+
*/
|
|
27
|
+
static validateForm(form) {
|
|
28
|
+
if (!form?.title || typeof form.title !== 'string') {
|
|
29
|
+
Log_1.Log.error(`Form needs 'title' (string)`);
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
if (!form?.id || typeof form.id !== 'string') {
|
|
33
|
+
Log_1.Log.error(`Form needs 'id' (string)`);
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
if (!form?.inputs || !Array.isArray(form.inputs)) {
|
|
37
|
+
Log_1.Log.error(`Form needs 'inputs' array`);
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Build ModalBuilder from validated form
|
|
44
|
+
*/
|
|
45
|
+
static buildModal(form) {
|
|
46
|
+
const modal = new discord_js_1.ModalBuilder()
|
|
47
|
+
.setCustomId(form.id)
|
|
48
|
+
.setTitle(form.title);
|
|
49
|
+
let componentCount = 0;
|
|
50
|
+
for (const input of form.inputs.slice(0, MAX_COMPONENTS)) {
|
|
51
|
+
if (!this.isValidInput(input)) {
|
|
52
|
+
Log_1.Log.error(`Invalid input in form '${form.title}'`);
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const row = this.createInputRow(input);
|
|
56
|
+
modal.addComponents(row);
|
|
57
|
+
componentCount++;
|
|
58
|
+
}
|
|
59
|
+
if (form.inputs.length > MAX_COMPONENTS) {
|
|
60
|
+
Log_1.Log.warn(`Form '${form.title}': ${form.inputs.length} inputs → ${MAX_COMPONENTS} max, Discord will force hide the 5th+ component`);
|
|
61
|
+
}
|
|
62
|
+
return modal;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Validate single input
|
|
66
|
+
*/
|
|
67
|
+
static isValidInput(input) {
|
|
68
|
+
const requiredFields = ['type', 'id', 'title'];
|
|
69
|
+
return requiredFields.every(field => input?.[field]);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Create ActionRowBuilder from input config
|
|
73
|
+
*/
|
|
74
|
+
static createInputRow(input) {
|
|
75
|
+
let textInput = new discord_js_1.TextInputBuilder()
|
|
76
|
+
.setCustomId(input.id)
|
|
77
|
+
.setLabel(input.title)
|
|
78
|
+
.setRequired(input.required ?? false);
|
|
79
|
+
// Style mapping
|
|
80
|
+
const style = input.style === 'paragraph' ? discord_js_1.TextInputStyle.Paragraph : discord_js_1.TextInputStyle.Short;
|
|
81
|
+
textInput = textInput.setStyle(style);
|
|
82
|
+
// Type-specific options
|
|
83
|
+
switch (input.type) {
|
|
84
|
+
case 'text_placeholder':
|
|
85
|
+
textInput = textInput.setPlaceholder(input.placeholder ?? '');
|
|
86
|
+
break;
|
|
87
|
+
case 'text_minmax_length':
|
|
88
|
+
textInput = textInput
|
|
89
|
+
.setMinLength(input.minLength ?? 0)
|
|
90
|
+
.setMaxLength(input.maxLength ?? 4000);
|
|
91
|
+
break;
|
|
92
|
+
case 'number':
|
|
93
|
+
textInput = textInput
|
|
94
|
+
.setStyle(discord_js_1.TextInputStyle.Short)
|
|
95
|
+
.setPlaceholder('Enter a number');
|
|
96
|
+
break;
|
|
97
|
+
case 'date':
|
|
98
|
+
textInput = textInput
|
|
99
|
+
.setStyle(discord_js_1.TextInputStyle.Short)
|
|
100
|
+
.setPlaceholder('DD/MM/YYYY');
|
|
101
|
+
break;
|
|
102
|
+
case 'date-hour':
|
|
103
|
+
textInput = textInput
|
|
104
|
+
.setStyle(discord_js_1.TextInputStyle.Short)
|
|
105
|
+
.setPlaceholder('DD/MM/YYYY HH:MM');
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
return new discord_js_1.ActionRowBuilder().addComponents(textInput);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
exports.ModalManager = ModalManager;
|