@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,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,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UserManager = void 0;
|
|
4
|
+
const Bot_1 = require("../../bot/Bot");
|
|
5
|
+
const Log_1 = require("../../utils/Log");
|
|
6
|
+
const UnitTime_1 = require("../../utils/times/UnitTime");
|
|
7
|
+
class UserManager {
|
|
8
|
+
/**
|
|
9
|
+
* Find member in specific guild
|
|
10
|
+
*/
|
|
11
|
+
static async find(userId) {
|
|
12
|
+
try {
|
|
13
|
+
return await Bot_1.Bot.client.users.fetch(userId);
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
Log_1.Log.error(`UserManager: Member ${userId} not found`);
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Find member in specific guild
|
|
22
|
+
*/
|
|
23
|
+
static async findInGuild(memberId, guildId) {
|
|
24
|
+
try {
|
|
25
|
+
const guild = await Bot_1.Bot.client.guilds.fetch(guildId);
|
|
26
|
+
const member = await guild.members.fetch({ user: memberId, force: true });
|
|
27
|
+
return member ?? null;
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
Log_1.Log.error(`UserManager: Member ${memberId} not found in ${guildId}`);
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Check if user is still in guild
|
|
36
|
+
*/
|
|
37
|
+
static async isInGuild(userId, guildId) {
|
|
38
|
+
try {
|
|
39
|
+
const guild = await Bot_1.Bot.client.guilds.fetch(guildId);
|
|
40
|
+
await guild.members.fetch({ user: userId, force: true });
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
return error.code !== 10007;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Fetch all members with retry (heavy operation)
|
|
49
|
+
*/
|
|
50
|
+
static async fetchAllMembers(guildId, MAX_ATTEMPTS = 3, RETRY_DELAY = UnitTime_1.Time.minute.MIN_05.toMilliseconds()) {
|
|
51
|
+
const guild = Bot_1.Bot.client.guilds.cache.get(guildId);
|
|
52
|
+
if (!guild)
|
|
53
|
+
throw new Error(`Guild ${guildId} not found`);
|
|
54
|
+
for (let attempt = 1; attempt <= MAX_ATTEMPTS; attempt++) {
|
|
55
|
+
try {
|
|
56
|
+
Log_1.Log.info(`UserManager: Fetching ${guild.name} members (attempt ${attempt})`);
|
|
57
|
+
return await guild.members.fetch();
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
Log_1.Log.error(`UserManager: Fetch failed (attempt ${attempt}): ${error}`);
|
|
61
|
+
if (attempt < MAX_ATTEMPTS) {
|
|
62
|
+
await new Promise(r => setTimeout(r, RETRY_DELAY));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
throw new Error(`Failed to fetch members after ${MAX_ATTEMPTS} attempts`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
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,85 @@
|
|
|
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
|
+
class GuildMessageManager {
|
|
7
|
+
/**
|
|
8
|
+
* Impl
|
|
9
|
+
*/
|
|
10
|
+
static async send(channelId, content_or_options) {
|
|
11
|
+
try {
|
|
12
|
+
const channel = await GuildTextChannelManager_1.GuildTextChannelManager.find(channelId);
|
|
13
|
+
if (!channel) {
|
|
14
|
+
Log_1.Log.error(`Channel ${channelId} not found in guild`);
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
const payload = typeof content_or_options === 'string'
|
|
18
|
+
? { content: content_or_options }
|
|
19
|
+
: content_or_options;
|
|
20
|
+
return await channel.send(payload);
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
Log_1.Log.error(`Failed to send message to ${channelId}: ${error}`);
|
|
24
|
+
throw error;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Delete message
|
|
29
|
+
*/
|
|
30
|
+
static async delete(channelId, messageId) {
|
|
31
|
+
try {
|
|
32
|
+
const channel = await GuildTextChannelManager_1.GuildTextChannelManager.find(channelId);
|
|
33
|
+
if (!channel) {
|
|
34
|
+
Log_1.Log.error(`Channel ${channelId} not found`);
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
const message = await channel.messages.fetch(messageId);
|
|
38
|
+
await message.delete();
|
|
39
|
+
Log_1.Log.info(`Deleted message ${messageId} from ${channelId}`);
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
Log_1.Log.error(`Failed to delete message ${messageId} from ${channelId}: ${error}`);
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Fetch messages (last X messages, default 10)
|
|
49
|
+
*/
|
|
50
|
+
static async fetch(channelId, limit = 10) {
|
|
51
|
+
try {
|
|
52
|
+
const channel = await GuildTextChannelManager_1.GuildTextChannelManager.find(channelId);
|
|
53
|
+
if (!channel) {
|
|
54
|
+
Log_1.Log.error(`Channel ${channelId} not found`);
|
|
55
|
+
return [];
|
|
56
|
+
}
|
|
57
|
+
const messages = await channel.messages.fetch({ limit });
|
|
58
|
+
Log_1.Log.info(`Fetched ${messages.size} messages from ${channelId}`);
|
|
59
|
+
return Array.from(messages.values());
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
Log_1.Log.error(`Failed to fetch messages from ${channelId}: ${error}`);
|
|
63
|
+
return [];
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Fetch single message
|
|
68
|
+
*/
|
|
69
|
+
static async fetchOne(channelId, messageId) {
|
|
70
|
+
try {
|
|
71
|
+
const channel = await GuildTextChannelManager_1.GuildTextChannelManager.find(channelId);
|
|
72
|
+
if (!channel) {
|
|
73
|
+
Log_1.Log.error(`Channel ${channelId} not found`);
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
const message = await channel.messages.fetch(messageId);
|
|
77
|
+
return message;
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
Log_1.Log.error(`Failed to fetch message ${messageId} from ${channelId}: ${error}`);
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
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,34 @@
|
|
|
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
|
+
class ThreadChannelManager {
|
|
7
|
+
static async findInGuild(guildId, channelId) {
|
|
8
|
+
const channel = await GuildChannelManager_1.GuildChannelManager.findInGuild(guildId, channelId);
|
|
9
|
+
return channel?.isThread() ? channel : null;
|
|
10
|
+
}
|
|
11
|
+
static async find(channelId) {
|
|
12
|
+
const channel = await GuildChannelManager_1.GuildChannelManager.find(channelId);
|
|
13
|
+
return channel?.isThread() ? channel : null;
|
|
14
|
+
}
|
|
15
|
+
static findAll(guildId) {
|
|
16
|
+
const channels = GuildChannelManager_1.GuildChannelManager.findAll(guildId);
|
|
17
|
+
return channels.filter(c => c.isThread());
|
|
18
|
+
}
|
|
19
|
+
static async createFromChannel(parentId, options) {
|
|
20
|
+
const channel = await GuildTextChannelManager_1.GuildTextChannelManager.find(parentId);
|
|
21
|
+
if (!channel || !channel.isTextBased()) {
|
|
22
|
+
throw new Error('Parent must be a text-based channel');
|
|
23
|
+
}
|
|
24
|
+
const thread = await channel.threads.create(options);
|
|
25
|
+
return thread;
|
|
26
|
+
}
|
|
27
|
+
static async createFromMessage(message, options) {
|
|
28
|
+
const channel = await GuildChannelManager_1.GuildChannelManager.find(message.id);
|
|
29
|
+
if (!channel)
|
|
30
|
+
throw new Error('Message channel not found');
|
|
31
|
+
return await message.startThread(options);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.ThreadChannelManager = ThreadChannelManager;
|