Skip to content

Commit 6e8a31f

Browse files
author
xyzjesper
committed
Added Multi Embeds to Messate Templates and to Edit this Message Context Menu. Fixed issue #4
1 parent 55253ec commit 6e8a31f

File tree

66 files changed

+2768
-2201
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+2768
-2201
lines changed

src/handler/files/buttons.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ export async function loadButtons(client: ExtendedClient): Promise<void> {
1919
console.warn("Modules folder does not exist.".red);
2020
return;
2121
}
22-
23-
// Alle Unterordner in modules/ durchsuchen
2422
const moduleDirectories = fs.readdirSync(modulesFolder, { withFileTypes: true })
2523
.filter(dirent => dirent.isDirectory())
2624
.map(dirent => dirent.name);
@@ -31,7 +29,7 @@ export async function loadButtons(client: ExtendedClient): Promise<void> {
3129
const buttonFolder = path.join(modulesFolder, moduleDir, "buttons");
3230

3331
if (!fs.existsSync(buttonFolder)) {
34-
continue; // Skip if no button folder exists
32+
continue;
3533
}
3634

3735
const buttonFiles = getFilesRecursively(buttonFolder, [".js"]);

src/handler/files/commands.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import colors from "colors";
22
import fs from "fs";
33
import path from "path";
4-
import { pathToFileURL } from "url";
5-
import { getFilesRecursively } from "../../helper/fileHelper.js";
6-
import type { ExtendedClient } from "../../types/client.js";
7-
import { Logger } from "../../main/logger.js";
8-
import { LoggingAction } from "../../enums/loggingTypes.js";
4+
import {pathToFileURL} from "url";
5+
import {getFilesRecursively} from "../../helper/fileHelper.js";
6+
import type {ExtendedClient} from "../../types/client.js";
7+
import {Logger} from "../../main/logger.js";
8+
import {LoggingAction} from "../../enums/loggingTypes.js";
99
import {Config} from "../../main/config.js";
1010

1111
colors.enable();
@@ -22,8 +22,7 @@ export async function loadCommands(client: ExtendedClient) {
2222
return;
2323
}
2424

25-
// Alle Unterordner in modules/ durchsuchen
26-
const moduleDirectories = fs.readdirSync(modulesFolder, { withFileTypes: true })
25+
const moduleDirectories = fs.readdirSync(modulesFolder, {withFileTypes: true})
2726
.filter(dirent => dirent.isDirectory())
2827
.map(dirent => dirent.name);
2928

src/handler/files/modals.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ export async function loadModals(client: ExtendedClient): Promise<void> {
2222
console.warn("Modules folder does not exist.".red);
2323
return;
2424
}
25-
26-
// Alle Unterordner in modules/ durchsuchen
25+
2726
const moduleDirectories = fs.readdirSync(modulesFolder, {withFileTypes: true})
2827
.filter(dirent => dirent.isDirectory())
2928
.map(dirent => dirent.name);
@@ -34,7 +33,7 @@ export async function loadModals(client: ExtendedClient): Promise<void> {
3433
const modalFolder = path.join(modulesFolder, moduleDir, "modals");
3534

3635
if (!fs.existsSync(modalFolder)) {
37-
continue; // Skip if no modal folder exists
36+
continue;
3837
}
3938

4039
const modalFiles = getFilesRecursively(modalFolder, [".js"]);

src/handler/files/selectmenus.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ export async function loadSelectMenus(client: ExtendedClient): Promise<void> {
2323
return;
2424
}
2525

26-
// Alle Unterordner in modules/ durchsuchen
2726
const moduleDirectories = fs.readdirSync(modulesFolder, { withFileTypes: true })
2827
.filter(dirent => dirent.isDirectory())
2928
.map(dirent => dirent.name);
@@ -34,7 +33,7 @@ export async function loadSelectMenus(client: ExtendedClient): Promise<void> {
3433
const selectmenuFolder = path.join(modulesFolder, moduleDir, "selectmenus");
3534

3635
if (!fs.existsSync(selectmenuFolder)) {
37-
continue; // Skip if no selectmenu folder exists
36+
continue;
3837
}
3938

4039
const selectmenuFiles = getFilesRecursively(selectmenuFolder, [".js"]);

src/helper/CommandHelper.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ export class CommandHelper {
3939
return;
4040
}
4141

42-
// Alle Unterordner in modules/ durchsuchen
4342
const moduleDirectories = fs.readdirSync(modulesFolder, {withFileTypes: true})
4443
.filter(dirent => dirent.isDirectory())
4544
.map(dirent => dirent.name);
@@ -48,10 +47,9 @@ export class CommandHelper {
4847
const moduleCommandFolder = path.join(modulesFolder, moduleDir, "commands");
4948

5049
if (!fs.existsSync(moduleCommandFolder)) {
51-
continue; // Skip if no command folder exists
50+
continue
5251
}
5352

54-
// Command Pfade für jedes Modul
5553
const commandDirs = {
5654
commands: moduleCommandFolder,
5755
contextMenus: path.join(modulesFolder, moduleDir, "contextmenu"),
@@ -162,8 +160,7 @@ export class CommandHelper {
162160
};
163161
}
164162
return cmd;
165-
});
166-
163+
})
167164

168165
await restClient.put(Routes.applicationGuildCommands(Config.Bot.DiscordApplicationId, guild.id), {
169166
body: cmdlist,

src/helper/loggingHelper.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ export async function loggingHelper(
2525

2626
const webhookMessage = await webhookClient.send(
2727
{
28+
allowedMentions: {
29+
roles: [],
30+
users: []
31+
},
2832
withComponents: true,
2933
components: [
3034
new ContainerBuilder()

src/internal/commands/reload.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import {ChatInputCommandInteraction, MessageFlags, PermissionFlagsBits, SlashCommandBuilder} from "discord.js";
2+
import {database} from "../../main/database.js";
3+
import {ExtendedClient} from "types/client.js";
4+
import {cli} from "winston/lib/winston/config/index.js";
5+
import {CommandHelper} from "../../helper/CommandHelper.js";
6+
import {loadBans} from "../../systems/backup/load.js";
7+
import {loadCommands} from "../../handler/files/commands.js";
8+
import {loadButtons} from "../../handler/files/buttons.js";
9+
import {loadEvents} from "../../handler/files/events.js";
10+
import {loadSelectMenus} from "../../handler/files/selectmenus.js";
11+
import {loadModals} from "../../handler/files/modals.js";
12+
13+
export default {
14+
data: new SlashCommandBuilder().setName("bot-reload").setDescription("Reload the Bot Modules").setDefaultMemberPermissions(PermissionFlagsBits.Administrator),
15+
async execute(interaction: ChatInputCommandInteraction, client: ExtendedClient) {
16+
17+
await loadCommands(client);
18+
await loadSelectMenus(client);
19+
await loadModals(client);
20+
await loadButtons(client);
21+
await loadEvents(client);
22+
23+
await CommandHelper.loadCommands(client);
24+
await CommandHelper.guildLoadCommands(client);
25+
26+
await interaction.reply({
27+
content: "## Reload the Bot Modules",
28+
flags: MessageFlags.Ephemeral,
29+
})
30+
31+
32+
}
33+
}
File renamed without changes.

src/modules/commands/buttons/commands-manager-toggle.ts

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@ import {
33
ButtonInteraction,
44
ButtonStyle,
55
MessageFlags,
6-
ModalBuilder,
6+
ModalBuilder, REST, Routes,
77
TextInputBuilder,
88
TextInputStyle
99
} from "discord.js";
1010
import {convertToEmojiPng} from "../../../helper/emojis.js";
1111
import {ExtendedClient} from "../../../types/client.js";
1212
import {protectedCommands} from "../../../main/data.js";
1313
import {database} from "../../../main/database.js";
14+
import {Logger} from "../../../main/logger.js";
15+
import {Config} from "../../../main/config.js";
1416

1517
export default {
1618
id: "commands-manager-toggle",
@@ -49,8 +51,31 @@ export default {
4951
for (const command of commands.values()) {
5052
if (
5153
command.name != data.CustomName &&
52-
command.guildId == interaction.guild?.id
54+
command.guildId == interaction.guild?.id && !data.IsEnabled
5355
) {
56+
57+
const restClient = new REST({version: "10"}).setToken(Config.Bot.DiscordBotToken);
58+
59+
const json = client.commands.get(data.CodeName).data.toJSON();
60+
61+
json.name = data.CustomName;
62+
json.description = data.Description;
63+
json.default_member_permissions = data.Permissions;
64+
65+
const currentCommands = await restClient.get(
66+
Routes.applicationGuildCommands(Config.Bot.DiscordApplicationId, interaction.guild.id)
67+
) as any[]
68+
69+
const newCommands = [...currentCommands, json];
70+
71+
await restClient.put(
72+
Routes.applicationGuildCommands(Config.Bot.DiscordApplicationId, interaction.guild.id),
73+
{
74+
body: newCommands,
75+
}
76+
);
77+
78+
5479
await database.buildInCommands.update({
5580
where: {
5681
UUID: interaction.customId.split(":")[1]
@@ -59,17 +84,6 @@ export default {
5984
IsEnabled: true
6085
}
6186
})
62-
await interaction.guild.commands.create(
63-
{
64-
name: data.CustomName,
65-
description: client.commands.get(data.CodeName).data.description,
66-
contexts: client.commands.get(data.CodeName).data.contexts,
67-
options: client.commands.get(data.CodeName).data.options as any,
68-
default_member_permissions: client.commands.get(data.CodeName).data.default_member_permissions,
69-
integrationTypes: client.commands.get(data.CodeName).data.integration_types,
70-
dmPermission: false
71-
}
72-
)
7387

7488
return await interaction.reply({
7589
flags: MessageFlags.Ephemeral,
@@ -80,8 +94,7 @@ export default {
8094
command.name == data.CustomName &&
8195
command.guildId == interaction.guild?.id
8296
) {
83-
84-
await interaction.guild.commands.delete(command.id)
97+
await command.delete()
8598
await database.buildInCommands.update({
8699
where: {
87100
UUID: interaction.customId.split(":")[1]
@@ -97,6 +110,7 @@ export default {
97110
}
98111
}
99112
} catch (error) {
113+
Logger.error(error);
100114
return await interaction.reply({
101115
flags: MessageFlags.Ephemeral,
102116
content: `## ${await convertToEmojiPng("error", client.user.id)} Can't remove this command from the Guild!`

src/modules/commands/modals/commands-manager-name-modal.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ export default {
3030
for (const command of commands.values()) {
3131
if (
3232
command.name == data.CustomName &&
33-
data.CustomName != name &&
34-
command.guildId == interaction.guild?.id
33+
data.IsEnabled &&
34+
command.guildId == interaction.guild?.id &&
35+
command.name != name
3536
) {
3637
await interaction.guild?.commands.edit(command.id, {
3738
name: name,
@@ -48,7 +49,7 @@ export default {
4849
});
4950
}
5051
}
51-
52+
5253
return await interaction.reply({
5354
flags: MessageFlags.Ephemeral,
5455
content: `## ${await convertToEmojiPng("error", client.user.id)} Could not find a matching command.`

0 commit comments

Comments
 (0)