diff --git a/src/commands/settings.ts b/src/commands/settings.ts index 91a0147..c8d7459 100644 --- a/src/commands/settings.ts +++ b/src/commands/settings.ts @@ -24,8 +24,14 @@ export default { ) .addChannelOption(option => option - .setName('message-logs-channel') - .setDescription('Set the message logs channel.') + .setName('event-logs-channel') + .setDescription('Set the event logs channel.') + .setRequired(false) + ) + .addChannelOption(option => + option + .setName('discord-logs-channel') + .setDescription('Set the discord logs channel.') .setRequired(false) ) .addChannelOption(option => @@ -139,12 +145,20 @@ export default { response += `Tickets logs channel set to ${ticketsChannel}.\n`; } - const messageLogsChannel = interaction.options.getChannel('message-logs-channel'); + const eventLogsChannel = interaction.options.getChannel('event-logs-channel'); - if (messageLogsChannel) { - await Database.setGuildEventsLogsChannelId(interaction.guildId!, messageLogsChannel.id); + if (eventLogsChannel) { + await Database.setGuildEventsLogsChannelId(interaction.guildId!, eventLogsChannel.id); - response += `Message logs channel set to ${messageLogsChannel}.\n`; + response += `Event logs channel set to ${eventLogsChannel}.\n`; + } + + const discordLogsChannel = interaction.options.getChannel('discord-logs-channel'); + + if (discordLogsChannel) { + await Database.setGuildDiscordLogsChannelId(interaction.guildId!, discordLogsChannel.id); + + response += `Discord logs channel set to ${discordLogsChannel}.\n`; } const auditLogsChannel = interaction.options.getChannel('audit-logs-channel'); diff --git a/src/shared/Database.ts b/src/shared/Database.ts index 2754583..e9855ba 100644 --- a/src/shared/Database.ts +++ b/src/shared/Database.ts @@ -21,6 +21,7 @@ const DB_SCHEMA = ` new_member_channel_id TEXT, tickets_channel_id TEXT, event_logs_channel_id TEXT, + discord_logs_channel_id TEXT, audit_logs_channel_id TEXT, voice_logs_channel_id TEXT, admin_role_id TEXT, @@ -169,6 +170,10 @@ export class Database { await Database.db.run('UPDATE settings SET event_logs_channel_id = ? WHERE guild_id = ?', id, guildId); } + static async setGuildDiscordLogsChannelId(guildId: string, id: string) { + await Database.db.run('UPDATE settings SET discord_logs_channel_id = ? WHERE guild_id = ?', id, guildId); + } + static async setGuildAuditLogsChannelId(guildId: string, id: string) { await Database.db.run('UPDATE settings SET audit_logs_channel_id = ? WHERE guild_id = ?', id, guildId); } diff --git a/src/types/database-types.d.ts b/src/types/database-types.d.ts index 2bcd86f..7bd4855 100644 --- a/src/types/database-types.d.ts +++ b/src/types/database-types.d.ts @@ -14,6 +14,7 @@ export type GuildSettings = { new_member_channel_id?: string tickets_channel_id?: string event_logs_channel_id?: string + discord_logs_channel_id?: string audit_logs_channel_id?: string voice_logs_channel_id?: string admin_role_id?: string diff --git a/src/utils/event-log-utils.ts b/src/utils/event-log-utils.ts index a7b282f..6b4fa9c 100644 --- a/src/utils/event-log-utils.ts +++ b/src/utils/event-log-utils.ts @@ -13,7 +13,7 @@ type CustomEventLogData = { } export async function logEdit(loggedMessage: LoggedMessage, newMessage: Message) { - const channel = await getEventLogChannel(newMessage.guild); + const channel = await getEventLogChannel(newMessage.guild, newMessage.channel.parentId); if (!channel) return; @@ -31,7 +31,7 @@ export async function logEdit(loggedMessage: LoggedMessage, newMessage: Message< } export async function logDeletion(loggedMessage: LoggedMessage, deletedMessage: Message) { - const channel = await getEventLogChannel(deletedMessage.guild); + const channel = await getEventLogChannel(deletedMessage.guild, deletedMessage.channel.parentId); if (!channel) return; @@ -63,16 +63,30 @@ export async function logCustomEvent(guild: Guild, data: CustomEventLogData) { channel.send({ embeds: [embed] }); } -async function getEventLogChannel(guild: Guild): Promise { +async function getEventLogChannel(guild: Guild, parentId: string | null = null): Promise { const settings = await Database.getGuildSettings(guild.id); - if (!settings || !settings.event_logs_channel_id) return null; + if (!settings) return null; - const channel = await guild.channels.fetch(settings.event_logs_channel_id); + const staffCategories = await Database.getGuildArraySetting('staff_categories', guild.id); - if (!channel || !channel.isSendable()) return null; + if (parentId != null && staffCategories.includes(parentId)) { + if (!settings.event_logs_channel_id) return null; - return channel; + const channel = await guild.channels.fetch(settings.event_logs_channel_id); + + if (!channel || !channel.isSendable()) return null; + + return channel; + } else { + if (!settings.discord_logs_channel_id) return null; + + const channel = await guild.channels.fetch(settings.discord_logs_channel_id); + + if (!channel || !channel.isSendable()) return null; + + return channel; + } } function getMainEmbeds(loggedMessage: LoggedMessage, newMessage: Message): APIEmbedField[] {