Skip to content

Commit 71f2a1f

Browse files
author
xyzjesper
committed
Improved logging for all log types.
1 parent 7bb3000 commit 71f2a1f

File tree

61 files changed

+3891
-1990
lines changed

Some content is hidden

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

61 files changed

+3891
-1990
lines changed

src/helper/loggingHelper.ts

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export async function loggingHelper(
1919
eventName: string,
2020
) {
2121

22-
const fileBuffer = Buffer.from(eventJSON, "utf-8");
22+
2323

2424
const uuid = randomUUID()
2525

@@ -37,40 +37,12 @@ export async function loggingHelper(
3737
.addActionRowComponents(
3838
new ActionRowBuilder<ButtonBuilder>().addComponents(
3939
new ButtonBuilder()
40-
.setCustomId("logging-add-note:" + uuid)
41-
.setLabel("Add Note")
42-
.setStyle(ButtonStyle.Secondary),
43-
new ButtonBuilder()
44-
.setCustomId("logging-delete-note:" + uuid)
45-
.setLabel("Delete Note by Id")
46-
.setStyle(ButtonStyle.Secondary),
47-
new ButtonBuilder()
48-
.setCustomId("logging-show-note:" + uuid)
49-
.setLabel("Show all notes")
5040
.setStyle(ButtonStyle.Secondary)
41+
.setLabel("More Actions")
42+
.setEmoji("<:list:1404137033496002591>")
43+
.setCustomId("logging-actions:" + uuid + ":" + eventName)
5144
)
5245
)
53-
.addTextDisplayComponents(new TextDisplayBuilder().setContent("-# **Send this Log to a User (DM)**"))
54-
.addActionRowComponents(
55-
new ActionRowBuilder<UserSelectMenuBuilder>().addComponents(
56-
new UserSelectMenuBuilder()
57-
.setCustomId("logging-to-user:" + uuid)
58-
)
59-
)
60-
.addTextDisplayComponents(new TextDisplayBuilder().setContent("-# **Send this log to a Channel (In this Guild)**"))
61-
.addActionRowComponents(
62-
new ActionRowBuilder<ChannelSelectMenuBuilder>().addComponents(
63-
new ChannelSelectMenuBuilder()
64-
.setCustomId("logging-to-channel:" + uuid)
65-
.setChannelTypes(ChannelType.GuildText, ChannelType.PublicThread, ChannelType.PrivateThread, ChannelType.AnnouncementThread, ChannelType.GuildAnnouncement)
66-
)
67-
)
68-
.addFileComponents(
69-
new FileBuilder().setURL(`attachment://${eventName}.json`)
70-
)
71-
],
72-
files: [
73-
new AttachmentBuilder(fileBuffer).setName(`${eventName}.json`),
7446
],
7547
flags: MessageFlags.IsComponentsV2
7648
})
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import {
2+
ActionRowBuilder, AttachmentBuilder,
3+
ButtonBuilder,
4+
ButtonInteraction,
5+
ButtonStyle, ChannelSelectMenuBuilder, ChannelType, ContainerBuilder,
6+
EmbedBuilder, FileBuilder,
7+
MessageFlags,
8+
ModalBuilder, PermissionFlagsBits, TextDisplayBuilder, TextInputBuilder, TextInputStyle, UserSelectMenuBuilder
9+
} from "discord.js";
10+
import {ExtendedClient} from "../../../types/ExtendedClient.js";
11+
import {PermissionType} from "../../../enums/permissionType.js";
12+
import {database} from "../../../main/database.js";
13+
14+
export default {
15+
id: "logging-actions",
16+
options: {
17+
once: false,
18+
permission: PermissionType.Logging,
19+
cooldown: 3000,
20+
botPermissions: [
21+
PermissionFlagsBits.SendMessages,
22+
PermissionFlagsBits.ManageGuild,
23+
PermissionFlagsBits.ViewChannel,
24+
PermissionFlagsBits.ReadMessageHistory
25+
],
26+
userPermissions: [PermissionFlagsBits.ManageGuild],
27+
userHasOnePermission: true,
28+
isGuildOwner: false,
29+
},
30+
/**
31+
*
32+
* @param {ButtonInteraction} interaction
33+
* @param {ExtendedClient} client
34+
*/
35+
async execute(interaction: ButtonInteraction, client: ExtendedClient) {
36+
37+
const uuid = interaction.customId.split(":")[1]
38+
const eventName = interaction.customId.split(":")[2]
39+
40+
const data = await database.guildLogs.findFirst({
41+
where: {
42+
UUID: uuid
43+
}
44+
})
45+
46+
const fileBuffer = Buffer.from(JSON.parse(data.LogJSON), "utf-8");
47+
48+
await interaction.reply({
49+
flags: MessageFlags.Ephemeral | MessageFlags.IsComponentsV2,
50+
components: [
51+
new ContainerBuilder()
52+
.addActionRowComponents(
53+
new ActionRowBuilder<ButtonBuilder>().addComponents(
54+
new ButtonBuilder()
55+
.setCustomId("logging-add-note:" + uuid)
56+
.setLabel("Add Note")
57+
.setStyle(ButtonStyle.Secondary),
58+
new ButtonBuilder()
59+
.setCustomId("logging-delete-note:" + uuid)
60+
.setLabel("Delete Note by Id")
61+
.setStyle(ButtonStyle.Secondary),
62+
new ButtonBuilder()
63+
.setCustomId("logging-show-note:" + uuid)
64+
.setLabel("Show all notes")
65+
.setStyle(ButtonStyle.Secondary)
66+
)
67+
)
68+
.addTextDisplayComponents(new TextDisplayBuilder().setContent("-# **Send this Log to a User (DM)**"))
69+
.addActionRowComponents(
70+
new ActionRowBuilder<UserSelectMenuBuilder>().addComponents(
71+
new UserSelectMenuBuilder()
72+
.setCustomId("logging-to-user:" + uuid)
73+
)
74+
)
75+
.addTextDisplayComponents(new TextDisplayBuilder().setContent("-# **Send this log to a Channel (In this Guild)**"))
76+
.addActionRowComponents(
77+
new ActionRowBuilder<ChannelSelectMenuBuilder>().addComponents(
78+
new ChannelSelectMenuBuilder()
79+
.setCustomId("logging-to-channel:" + uuid)
80+
.setChannelTypes(ChannelType.GuildText, ChannelType.PublicThread, ChannelType.PrivateThread, ChannelType.AnnouncementThread, ChannelType.GuildAnnouncement)
81+
)
82+
)
83+
.addFileComponents(
84+
new FileBuilder().setURL(`attachment://${eventName}.json`)
85+
)
86+
],
87+
files: [
88+
new AttachmentBuilder(fileBuffer).setName(`${eventName}.json`),
89+
],
90+
})
91+
}
92+
};
Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
import {
22
ApplicationCommandPermissionsUpdateData,
33
ApplicationCommandPermissionType,
4-
AuditLogChange,
54
AuditLogEvent,
65
Client,
7-
EmbedBuilder,
86
Events,
97
WebhookClient
108
} from "discord.js";
119
import {ExtendedClient} from "../../../types/ExtendedClient.js";
12-
1310
import {loggingHelper} from "../../../helper/loggingHelper.js";
1411
import {database} from "../../../main/database.js";
1512

@@ -24,7 +21,6 @@ export default {
2421
data: ApplicationCommandPermissionsUpdateData,
2522
client: ExtendedClient
2623
) {
27-
2824
const guildId = data.guildId;
2925
const guild = await client.guilds.fetch(guildId);
3026

@@ -36,6 +32,7 @@ export default {
3632
});
3733

3834
if (!enabled || !enabled.LoggingEnabled) return;
35+
3936
const loggingData = await database.guildLogging.findFirst({
4037
where: {
4138
GuildId: guildId
@@ -55,35 +52,52 @@ export default {
5552

5653
const permissionsText = data.permissions
5754
.map((permission) => {
58-
if (permission.type == ApplicationCommandPermissionType.User) {
59-
return `> **- User** <@${permission.id}> (\`${permission.id}\`) - **Allowed**: \`${permission.permission}\``;
60-
}
55+
let type = "Unknown";
56+
let mention = permission.id;
6157

62-
if (permission.type == ApplicationCommandPermissionType.Role) {
63-
return `> **- Role** <@&${permission.id}> (\`${permission.id}\`) - **Allowed**: \`${permission.permission}\``;
64-
}
65-
66-
if (permission.type == ApplicationCommandPermissionType.Channel) {
67-
return `> **- Channel** <#${permission.id}> (\`${permission.id}\`) - **Allowed**: \`${permission.permission}\``;
58+
if (permission.type == ApplicationCommandPermissionType.User) {
59+
type = "User";
60+
mention = `<@${permission.id}>`;
61+
} else if (permission.type == ApplicationCommandPermissionType.Role) {
62+
type = "Role";
63+
mention = `<@&${permission.id}>`;
64+
} else if (permission.type == ApplicationCommandPermissionType.Channel) {
65+
type = "Channel";
66+
mention = `<#${permission.id}>`;
6867
}
6968

70-
return `> **- Unknown Type** ${permission.id} - **Allowed**: \`${permission.permission}\``;
69+
return `> **${type}:** ${mention} (\`${permission.id}\`) - **Allowed:** \`${permission.permission}\``;
7170
})
7271
.join("\n");
7372

74-
await loggingHelper(client,
75-
[
76-
`### Application Command Permissions Updated`,
77-
``,
78-
`> **Command Id:** \`${data.id ? data.id : "Unknown Command"}\``,
79-
`> **Permissions:**`,
80-
`${permissionsText}`,
81-
``,
82-
`-# **Executor: @${executor?.tag}**`
83-
].join("\n"),
73+
const logMessage = [
74+
`### 🔧 Command Permissions Updated`,
75+
``,
76+
`### Executor`,
77+
...(executor ? [
78+
`> <@${executor.id}>`,
79+
`> **User ID:** \`${executor.id}\``,
80+
`> **Username:** \`${executor.tag}\``
81+
] : [
82+
`> *Unknown Executor*`
83+
]),
84+
``,
85+
`### Details`,
86+
`> **Command ID:** \`${data.id || "Unknown"}\``,
87+
`> **Application ID:** \`${data.applicationId}\``,
88+
``,
89+
`### Permissions`,
90+
permissionsText,
91+
``,
92+
`**Timestamp:** <t:${Math.floor(Date.now() / 1000)}:F>`
93+
].join("\n");
94+
95+
await loggingHelper(
96+
client,
97+
logMessage,
8498
webhook,
85-
JSON.stringify(data),
99+
JSON.stringify(data, null, 2),
86100
"ApplicationCommandPermissionsUpdate"
87-
)
101+
);
88102
}
89-
};
103+
};

src/modules/logging/events/auditLogAutoModerationRuleCreatets.ts

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,45 @@
11
import {
22
AuditLogEvent,
3+
AutoModerationActionType,
34
AutoModerationRule,
5+
AutoModerationRuleEventType,
6+
AutoModerationRuleTriggerType,
47
Events,
58
WebhookClient
69
} from "discord.js";
710
import {ExtendedClient} from "../../../types/ExtendedClient.js";
8-
import {database} from "../../../main/database.js"; // Prisma DB
11+
import {database} from "../../../main/database.js";
912
import {loggingHelper} from "../../../helper/loggingHelper.js";
1013

14+
function getTriggerTypeName(type: AutoModerationRuleTriggerType): string {
15+
const types: Record<AutoModerationRuleTriggerType, string> = {
16+
[AutoModerationRuleTriggerType.Keyword]: "Keyword",
17+
[AutoModerationRuleTriggerType.Spam]: "Spam",
18+
[AutoModerationRuleTriggerType.KeywordPreset]: "Keyword Preset",
19+
[AutoModerationRuleTriggerType.MentionSpam]: "Mention Spam",
20+
[AutoModerationRuleTriggerType.MemberProfile]: "Member Profile"
21+
};
22+
return types[type] || `Unknown (${type})`;
23+
}
24+
25+
function getEventTypeName(type: AutoModerationRuleEventType): string {
26+
const types: Record<AutoModerationRuleEventType, string> = {
27+
[AutoModerationRuleEventType.MessageSend]: "Message Send",
28+
[AutoModerationRuleEventType.MemberUpdate]: ""
29+
};
30+
return types[type] || `Unknown (${type})`;
31+
}
32+
33+
function getActionTypeName(type: AutoModerationActionType): string {
34+
const types: Record<AutoModerationActionType, string> = {
35+
[AutoModerationActionType.BlockMessage]: "Block Message",
36+
[AutoModerationActionType.SendAlertMessage]: "Send Alert Message",
37+
[AutoModerationActionType.Timeout]: "Timeout User",
38+
[AutoModerationActionType.BlockMemberInteraction]: "Block Member Interaction"
39+
};
40+
return types[type] || `Unknown (${type})`;
41+
}
42+
1143
export default {
1244
name: Events.AutoModerationRuleCreate,
1345

@@ -44,21 +76,39 @@ export default {
4476
const executor = rule.executor;
4577
const ruleTarget = rule.target as unknown as AutoModerationRule;
4678

79+
const actionsText = ruleTarget.actions
80+
.map(action => `> **${getActionTypeName(action.type)}**`)
81+
.join("\n");
82+
4783
const message = [
48-
`### Auto Moderation Rule Created`,
84+
`### 🛡️ AutoMod Rule Created`,
85+
``,
86+
`### Executor`,
87+
`> <@${executor?.id}>`,
88+
`> **User ID:** \`${executor?.id}\``,
89+
`> **Username:** \`${executor?.tag}\``,
90+
``,
91+
`### Rule Details`,
92+
`> **Name:** \`${ruleTarget.name}\``,
93+
`> **Rule ID:** \`${ruleTarget.id}\``,
94+
`> **Enabled:** \`${ruleTarget.enabled ? "Yes" : "No"}\``,
95+
``,
96+
`### Configuration`,
97+
`> **Trigger Type:** \`${getTriggerTypeName(ruleTarget.triggerType)}\``,
98+
`> **Event Type:** \`${getEventTypeName(ruleTarget.eventType)}\``,
4999
``,
50-
`> **Rule Name**: \`${ruleTarget.name}\``,
51-
`> **Rule ID**: \`${ruleTarget.id}\``,
52-
`> **Created By**: ${executor} (\`${executor?.id}\`)`,
100+
`### Actions`,
101+
actionsText,
53102
``,
54-
`-# **Executor: ${executor}**`
103+
`**Timestamp:** <t:${Math.floor(Date.now() / 1000)}:F>`
55104
].join("\n");
56105

57-
await loggingHelper(client,
106+
await loggingHelper(
107+
client,
58108
message,
59109
webhook,
60110
JSON.stringify(auditLog, null, 2),
61111
"AutoModerationRuleCreate"
62112
);
63113
}
64-
};
114+
};

0 commit comments

Comments
 (0)