New logs channel

This commit is contained in:
Tarrgon
2025-07-21 14:23:55 -04:00
parent 5b045de4bd
commit 5a0aab69ff
4 changed files with 47 additions and 13 deletions
+20 -6
View File
@@ -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');
+5
View File
@@ -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);
}
+1
View File
@@ -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
+18 -4
View File
@@ -13,7 +13,7 @@ type CustomEventLogData = {
}
export async function logEdit(loggedMessage: LoggedMessage, newMessage: Message<true>) {
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<true>) {
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<GuildTextBasedChannel | null> {
async function getEventLogChannel(guild: Guild, parentId: string | null = null): Promise<GuildTextBasedChannel | null> {
const settings = await Database.getGuildSettings(guild.id);
if (!settings || !settings.event_logs_channel_id) return null;
if (!settings) return null;
const staffCategories = await Database.getGuildArraySetting('staff_categories', guild.id);
if (parentId != null && staffCategories.includes(parentId)) {
if (!settings.event_logs_channel_id) return null;
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<true>): APIEmbedField[] {