Skip to content

Commit 63148c8

Browse files
author
xyzjesper
committed
Added fixes for tempvoice.list.ts and logging.settings.ts. Added permissions-view-user-permissions.ts for permissions.ts module. Renamed command and update imports...
1 parent 226ea45 commit 63148c8

File tree

9 files changed

+424
-348
lines changed

9 files changed

+424
-348
lines changed

src/helper/CommandHelper.ts

Lines changed: 79 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export class CommandHelper {
125125
}
126126

127127
if (!Config.Bot.DiscordApplicationId || !Config.Bot.DiscordBotToken) {
128-
throw new Error("Missing environment variables: APPLICATIONID or TOKEN");
128+
throw new Error("Missing Config variables: DiscordApplicationId or DiscordBotToken");
129129
}
130130

131131
const restClient = new REST({version: "10"}).setToken(Config.Bot.DiscordBotToken);
@@ -135,92 +135,106 @@ export class CommandHelper {
135135
body: [],
136136
});
137137

138+
138139
const allGuilds = await client.guilds.fetch();
139140
for (const guild of allGuilds.values()) {
140141
const buildInCommandOverrides = await database.buildInCommands.findMany({
141142
where: {
142143
GuildCommandMangerId: guild.id
143144
}
144145
})
146+
try {
147+
cmdlist = cmdlist
148+
.filter(cmd => {
149+
const override = buildInCommandOverrides.find(o => o.CodeName === cmd.name);
150+
return !(override && override.IsEnabled === false);
151+
})
152+
.map(cmd => {
153+
const override = buildInCommandOverrides.find(o => o.CodeName === cmd.name);
154+
if (override) {
155+
return {
156+
...cmd,
157+
name: override.CustomName,
158+
description: override.Description ?? client.commands.get(override.CodeName).data.description,
159+
default_member_permissions: override.Permissions ?? client.commands.get(override.CodeName).data.default_member_permissions
160+
};
161+
}
162+
return cmd;
163+
})
145164

146-
cmdlist = cmdlist
147-
.filter(cmd => {
148-
const override = buildInCommandOverrides.find(o => o.CodeName === cmd.name);
149-
return !(override && override.IsEnabled === false);
150-
})
151-
.map(cmd => {
152-
const override = buildInCommandOverrides.find(o => o.CodeName === cmd.name);
153-
if (override) {
154-
return {
155-
...cmd,
156-
name: override.CustomName,
157-
description: override.Description ?? client.commands.get(override.CodeName).data.description,
158-
default_member_permissions: override.Permissions ?? client.commands.get(override.CodeName).data.default_member_permissions
159-
};
160-
}
161-
return cmd;
162-
})
165+
await restClient.put(Routes.applicationGuildCommands(Config.Bot.DiscordApplicationId, guild.id), {
166+
body: cmdlist,
167+
});
163168

164-
await restClient.put(Routes.applicationGuildCommands(Config.Bot.DiscordApplicationId, guild.id), {
165-
body: cmdlist,
166-
});
167169

168-
const ticketCommands = await database.ticketSetups.findMany({
169-
where: {
170-
GuildId: guild.id
171-
}
172-
})
170+
const ticketCommands = await database.ticketSetups.findMany({
171+
where: {
172+
GuildId: guild.id
173+
}
174+
})
173175

174-
for (const ticketCommand of ticketCommands) {
175-
const clientGuild = await client.guilds.fetch(guild.id);
176+
for (const ticketCommand of ticketCommands) {
177+
const clientGuild = await client.guilds.fetch(guild.id);
176178

177-
let guildCommand = null;
178-
try {
179-
guildCommand = await clientGuild.commands.fetch(ticketCommand.SlashCommandId);
180-
} catch {
181-
}
179+
let guildCommand = null;
180+
try {
181+
guildCommand = await clientGuild.commands.fetch(ticketCommand.SlashCommandId);
182+
} catch {
183+
}
182184

183-
if (!guildCommand) {
184-
guildCommand = await clientGuild.commands.create({
185-
name: ticketCommand.SlashCommandName ?? `open-${ticketCommand.CustomId}-ticket`,
186-
description: ticketCommand.SlashCommandDescription ?? ticketCommand.CustomId,
187-
});
188-
189-
await database.ticketSetups.update({
190-
where: {
191-
CustomId: ticketCommand.CustomId,
192-
},
193-
data: {
194-
SlashCommandId: guildCommand.id,
195-
},
196-
});
197-
} else {
198-
if (
199-
guildCommand.name !== ticketCommand.SlashCommandName ||
200-
guildCommand.description !== ticketCommand.SlashCommandDescription
201-
) {
202-
const updated = await guildCommand.edit({
203-
name: ticketCommand.SlashCommandName ?? guildCommand.name,
204-
description: ticketCommand.SlashCommandDescription ?? guildCommand.description,
185+
if (!guildCommand) {
186+
guildCommand = await clientGuild.commands.create({
187+
name: ticketCommand.SlashCommandName ?? `open-${ticketCommand.CustomId}-ticket`,
188+
description: ticketCommand.SlashCommandDescription ?? ticketCommand.CustomId,
205189
});
206190

207191
await database.ticketSetups.update({
208-
where: {CustomId: ticketCommand.CustomId},
209-
data: {SlashCommandId: updated.id},
192+
where: {
193+
CustomId: ticketCommand.CustomId,
194+
},
195+
data: {
196+
SlashCommandId: guildCommand.id,
197+
},
210198
});
199+
} else {
200+
if (
201+
guildCommand.name !== ticketCommand.SlashCommandName ||
202+
guildCommand.description !== ticketCommand.SlashCommandDescription
203+
) {
204+
const updated = await guildCommand.edit({
205+
name: ticketCommand.SlashCommandName ?? guildCommand.name,
206+
description: ticketCommand.SlashCommandDescription ?? guildCommand.description,
207+
});
208+
209+
await database.ticketSetups.update({
210+
where: {CustomId: ticketCommand.CustomId},
211+
data: {SlashCommandId: updated.id},
212+
});
213+
}
211214
}
212215
}
216+
217+
} catch (e) {
218+
Logger.error({
219+
timestamp: new Date().toISOString(),
220+
level: "error",
221+
label: "CommandHelper",
222+
message: `Command loading failed with error: ${e} - Commands failed at ${cmdlist.map((c) => c.name)} commands`,
223+
botType: Config.BotType.toString() || "Unknown",
224+
action: LoggingAction.Command,
225+
});
213226
}
214227

228+
Logger.info({
229+
timestamp: new Date().toISOString(),
230+
level: "info",
231+
label: "CommandHelper",
232+
message: `Discord added ${cmdlist.length} commands (${stats.subCommands} subCommands, ${stats.subCommandGroups} subCommandGroups), ${stats.userInstall} userInstall commands, ${stats.contextMenus} context menu commands from ${moduleDirectories.length} module(s) for ${allGuilds.size} Guilds`,
233+
botType: Config.BotType.toString() || "Unknown",
234+
action: LoggingAction.Command,
235+
});
215236
}
216-
Logger.info({
217-
timestamp: new Date().toISOString(),
218-
level: "info",
219-
label: "CommandHelper",
220-
message: `Discord added ${cmdlist.length} commands (${stats.subCommands} subCommands, ${stats.subCommandGroups} subCommandGroups), ${stats.userInstall} userInstall commands, ${stats.contextMenus} context menu commands from ${moduleDirectories.length} module(s) for ${allGuilds.size} Guilds`,
221-
botType: Config.BotType.toString() || "Unknown",
222-
action: LoggingAction.Command,
223-
});
237+
224238
}
225239

226240
public static async guildLoadCommands(client: ExtendedClient) {

src/helper/loggingHelper.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
ContainerBuilder,
55
FileBuilder,
66
MessageFlags, SeparatorBuilder, SeparatorSpacingSize,
7-
TextDisplayBuilder, UserSelectMenuBuilder,
7+
TextDisplayBuilder, UserSelectMenuBuilder, Webhook,
88
WebhookClient
99
} from "discord.js";
1010
import {database} from "../main/database.js";
@@ -74,19 +74,21 @@ export async function loggingHelper(
7474
],
7575
flags: MessageFlags.IsComponentsV2
7676
})
77-
78-
const webhookData = await client.fetchWebhook(webhookMessage.webhook_id)
79-
80-
81-
await database.guildLogs.create({
82-
data: {
83-
GuildId: webhookData.guildId,
84-
UUID: uuid,
85-
Notes: [],
86-
LogMessage: message,
87-
LogJSON: JSON.stringify(eventJSON)
88-
}
89-
})
77+
78+
try {
79+
const webhookData = await client.fetchWebhook(webhookMessage.webhook_id)
80+
await database.guildLogs.create({
81+
data: {
82+
GuildId: webhookData.guildId,
83+
UUID: uuid,
84+
Notes: [],
85+
LogMessage: message,
86+
LogJSON: JSON.stringify(eventJSON)
87+
}
88+
})
89+
} catch (e) {
90+
return
91+
}
9092

9193

9294
}

src/main/bot.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import colors from "colors";
33
import {
44
ActivityType,
55
Client,
6-
Collection,
6+
Collection, Events,
77
GatewayIntentBits,
88
Guild,
99
Partials,
@@ -178,7 +178,7 @@ client
178178
botType: Config.BotType.toString() || "Unknown",
179179
action: LoggingAction.Other,
180180
});
181-
client.once("ready", async () => {
181+
client.once(Events.ClientReady, async () => {
182182
clientReady(client);
183183
await initDataToDatabase(client)
184184
});

src/modules/automation/commands/automation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default {
2828
isGuildOwner: false,
2929
},
3030
data: new SlashCommandBuilder()
31-
.setName("automation")
31+
.setName("automations")
3232
.setDescription("Manage all automations")
3333
.setDescriptionLocalizations({
3434
de: "Automatisierungen verwalten",
@@ -59,7 +59,7 @@ export default {
5959
.setPlaceholder("Select an automation")
6060
.addOptions(
6161
{
62-
label: "guildAutoRoles",
62+
label: "AutoRoles",
6363
value: "guildAutoRoles",
6464
description: "Automatically assign roles to new members",
6565
emoji: "<:packageplus:1362545377030701167>",

0 commit comments

Comments
 (0)