Skip to content

Commit

Permalink
enhancement: separate moderator logs from event logs
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewL246 committed Aug 4, 2024
1 parent 14e15b4 commit 7fdd16d
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 21 deletions.
6 changes: 3 additions & 3 deletions src/commands/ban.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { EmbedBuilder, MessageMentions } from 'discord.js';
import { SlashCommandBuilder } from '@discordjs/builders';
import { Ban } from '@/models/bans';
import { sendEventLogMessage, ordinal } from '@/util';
import { sendModLogMessage, ordinal } from '@/util';
import { untrustUser } from '@/leveling';
import type { ChatInputCommandInteraction } from 'discord.js';

Expand Down Expand Up @@ -64,8 +64,8 @@ async function banHandler(interaction: ChatInputCommandInteraction): Promise<voi
iconURL: guild.iconURL()!
});

await sendEventLogMessage(guild, null, eventLogEmbed);
await sendModLogMessage(guild, eventLogEmbed);

const { count, rows } = await Ban.findAndCountAll({
where: {
user_id: member.id
Expand Down
4 changes: 2 additions & 2 deletions src/commands/kick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { MessageMentions, EmbedBuilder } from 'discord.js';
import { SlashCommandBuilder } from '@discordjs/builders';
import { Kick } from '@/models/kicks';
import { Ban } from '@/models/bans';
import { ordinal, sendEventLogMessage } from '@/util';
import { ordinal, sendModLogMessage } from '@/util';
import { untrustUser } from '@/leveling';
import type { ChatInputCommandInteraction } from 'discord.js';

Expand Down Expand Up @@ -134,7 +134,7 @@ async function kickHandler(interaction: ChatInputCommandInteraction): Promise<vo
sendMemberEmbeds.push(kickEmbed);
}

await sendEventLogMessage(guild, null, eventLogEmbed);
await sendModLogMessage(guild, eventLogEmbed);

if (count > 0) {
const pastKicksEmbed = new EmbedBuilder();
Expand Down
1 change: 1 addition & 0 deletions src/commands/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const editableOptions = [
'channels.nsfw-logs',
'channels.event-logs',
'channels.event-logs.blacklist',
'channels.mod-logs',
'channels.matchmaking',
'channels.notifications',
'matchmaking.lock-timeout-seconds',
Expand Down
16 changes: 8 additions & 8 deletions src/commands/slow-mode.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SlowMode, SlowModeStage } from '@/models/slow-mode';
import handleSlowMode from '@/slow-mode';
import { SlashCommandBuilder } from '@discordjs/builders';
import { sendEventLogMessage } from '@/util';
import { sendModLogMessage } from '@/util';
import { ChannelType, EmbedBuilder } from 'discord.js';
import type { GuildTextBasedChannel, ChatInputCommandInteraction } from 'discord.js';

Expand Down Expand Up @@ -116,8 +116,8 @@ async function setStageHandler(interaction: ChatInputCommandInteraction): Promis
}
]);
}
await sendEventLogMessage(interaction.guild!, channel.id, auditLogEmbed);

await sendModLogMessage(interaction.guild!, auditLogEmbed);

await interaction.followUp({ content: `Set a limit of 1 message every ${limit} seconds above ${threshold} messages per minute on <#${channel.id}>` });
}
Expand Down Expand Up @@ -190,8 +190,8 @@ async function unsetStageHandler(interaction: ChatInputCommandInteraction): Prom
}
]);
}
await sendEventLogMessage(interaction.guild!, channel.id, auditLogEmbed);

await sendModLogMessage(interaction.guild!, auditLogEmbed);

await interaction.followUp({ content: `Unset the limit at ${threshold} messages per minute on <#${channel.id}>` });
}
Expand Down Expand Up @@ -270,7 +270,7 @@ async function enableAutoSlowModeHandler(interaction: ChatInputCommandInteractio
]);
}

await sendEventLogMessage(interaction.guild!, channel.id, auditLogEmbed);
await sendModLogMessage(interaction.guild!, auditLogEmbed);

await interaction.followUp({ content: `Auto slow mode enabled for <#${channel.id}>` });
}
Expand Down Expand Up @@ -324,7 +324,7 @@ async function enableStaticSlowModeHandler(interaction: ChatInputCommandInteract
iconURL: interaction.guild!.iconURL()!
});

await sendEventLogMessage(interaction.guild!, channel.id, auditLogEmbed);
await sendModLogMessage(interaction.guild!, auditLogEmbed);

await interaction.followUp({ content: `Static slow mode enabled for <#${channel.id}>` });
}
Expand Down Expand Up @@ -376,7 +376,7 @@ async function disableSlowModeHandler(interaction: ChatInputCommandInteraction):
iconURL: interaction.guild!.iconURL()!
});

await sendEventLogMessage(interaction.guild!, channel.id, auditLogEmbed);
await sendModLogMessage(interaction.guild!, auditLogEmbed);

await interaction.followUp({ content: `Slow mode disabled for <#${channel.id}>` });
}
Expand Down
4 changes: 2 additions & 2 deletions src/commands/warn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { SlashCommandBuilder } from '@discordjs/builders';
import { Warning } from '@/models/warnings';
import { Kick } from '@/models/kicks';
import { Ban } from '@/models/bans';
import { ordinal, sendEventLogMessage } from '@/util';
import { ordinal, sendModLogMessage } from '@/util';
import { untrustUser } from '@/leveling';
import type { ChatInputCommandInteraction } from 'discord.js';

Expand Down Expand Up @@ -141,7 +141,7 @@ async function warnHandler(interaction: ChatInputCommandInteraction): Promise<vo
isBan = true;
}

await sendEventLogMessage(guild, null, eventLogEmbed);
await sendModLogMessage(guild, eventLogEmbed);

if (punishmentEmbed) {
const pastWarningsEmbed = new EmbedBuilder();
Expand Down
8 changes: 4 additions & 4 deletions src/events/guildAuditLogEntryCreate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AuditLogEvent, EmbedBuilder } from 'discord.js';
import { sendEventLogMessage } from '@/util';
import { sendEventLogMessage, sendModLogMessage } from '@/util';
import type { Guild, User, GuildAuditLogsEntry } from 'discord.js';

export default async function guildAuditLogEntryCreateHandler(auditLogEntry: GuildAuditLogsEntry, guild: Guild): Promise<void> {
Expand Down Expand Up @@ -76,7 +76,7 @@ async function handleMemberTimedOut(guild: Guild, user: User, executor: User, re
}
);

await sendEventLogMessage(guild, null, embed);
await sendModLogMessage(guild, embed);
}

async function handleMemberNicknameChange(guild: Guild, user: User, oldName?: string, newName?: string): Promise<void> {
Expand Down Expand Up @@ -160,7 +160,7 @@ async function handleMemberKick(auditLogEntry: GuildAuditLogsEntry<AuditLogEvent
iconURL: guild.iconURL()!
});

await sendEventLogMessage(guild, null, embed);
await sendModLogMessage(guild, embed);
}

async function handleMemberBanAdd(auditLogEntry: GuildAuditLogsEntry<AuditLogEvent.MemberBanAdd>, guild: Guild): Promise<void> {
Expand Down Expand Up @@ -208,7 +208,7 @@ async function handleMemberBanAdd(auditLogEntry: GuildAuditLogsEntry<AuditLogEve
iconURL: guild.iconURL()!
});

await sendEventLogMessage(guild, null, embed);
await sendModLogMessage(guild, embed);
}

function logIsForEvent<EventType extends AuditLogEvent>(log: GuildAuditLogsEntry, eventType: EventType): log is GuildAuditLogsEntry<EventType> {
Expand Down
4 changes: 2 additions & 2 deletions src/leveling.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { EmbedBuilder } from 'discord.js';
import { getDB, getDBList } from '@/db';
import { User } from '@/models/users';
import { getRoleFromSettings, sendEventLogMessage } from '@/util';
import { getRoleFromSettings, sendEventLogMessage, sendModLogMessage } from '@/util';
import { sequelize } from '@/sequelize-instance';
import { notifyUser } from '@/notifications';
import type { GuildMember, Message } from 'discord.js';
Expand Down Expand Up @@ -215,5 +215,5 @@ export async function untrustUser(member: GuildMember, newStartDate: Date): Prom
text: 'Pretendo Network',
iconURL: member.guild.iconURL()!
});
await sendEventLogMessage(member.guild, null, eventLogEmbed);
await sendModLogMessage(member.guild, eventLogEmbed);
}
10 changes: 10 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ export async function sendEventLogMessage(guild: Guild, originId: string | null,
return logChannel.send({ content, embeds: [embed] });
}

export async function sendModLogMessage(guild: Guild, embed: EmbedBuilder, content?: string): Promise<Message | null> {
const logChannel = await getChannelFromSettings(guild, 'channels.mod-logs');
if (!logChannel || logChannel.type !== ChannelType.GuildText) {
console.log('Missing mod log channel!');
return null;
}

return logChannel.send({ content, embeds: [embed] });
}

export async function getChannelFromSettings(guild: Guild, channelName: string): Promise<Channel | null> {
const channelID = getDB().get(channelName);
if (!channelID) {
Expand Down

0 comments on commit 7fdd16d

Please sign in to comment.