diff --git a/src/commands/settings.ts b/src/commands/settings.ts index 2a6b126..0857e06 100644 --- a/src/commands/settings.ts +++ b/src/commands/settings.ts @@ -1,5 +1,6 @@ import { ApplicationIntegrationType, ChannelType, ChatInputCommandInteraction, Client, InteractionContextType, MessageFlags, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js'; import { Database } from '../shared/Database'; +import { CreateDefaultEmbed, SetSeverity } from '../utils'; export default { name: 'settings', @@ -117,138 +118,154 @@ export default { .setDescription('Set the github release channel.') .setRequired(false) ), + handler: async function (client: Client, interaction: ChatInputCommandInteraction) { if (!interaction.guildId) return; // This shouldn't occur, but TypeScript doesn't know that. await interaction.deferReply({ flags: [MessageFlags.Ephemeral] }); - let response = ''; + const response: string[] = []; const settings = await Database.getGuildSettings(interaction.guildId!); if (!settings) await Database.putGuild(interaction.guildId); const generalChannel = interaction.options.getChannel('general-channel'); if (generalChannel) { await Database.updateGuildSettings(interaction.guildId, 'general_chat_id', generalChannel.id); - response += `\`general_chat_id\` has been set to: ${generalChannel}.\n`; + response.push(`**general_chat_id** has been set to: ${generalChannel}.`); } const ticketsChannel = interaction.options.getChannel('tickets-channel'); if (ticketsChannel) { await Database.updateGuildSettings(interaction.guildId, 'tickets_channel_id', ticketsChannel.id); - response += `\`tickets_channel_id\` has been set to: ${ticketsChannel}.\n`; + response.push(`**tickets_channel_id** has been set to: ${ticketsChannel}.`); } const eventLogsChannel = interaction.options.getChannel('event-logs-channel'); if (eventLogsChannel) { await Database.updateGuildSettings(interaction.guildId, 'event_logs_channel_id', eventLogsChannel.id); - response += `\`event_logs_channel_id\` has been set to: ${eventLogsChannel}.\n`; + response.push(`**event_logs_channel_id** has been set to: ${eventLogsChannel}.`); } const discordLogsChannel = interaction.options.getChannel('discord-logs-channel'); if (discordLogsChannel) { await Database.updateGuildSettings(interaction.guildId, 'discord_logs_channel_id', discordLogsChannel.id); - response += `\`discord_logs_channel_id\` has been set to: ${discordLogsChannel}.\n`; + response.push(`**discord_logs_channel_id** has been set to: ${discordLogsChannel}.`); } const auditLogsChannel = interaction.options.getChannel('audit-logs-channel'); if (auditLogsChannel) { await Database.updateGuildSettings(interaction.guildId, 'audit_logs_channel_id', auditLogsChannel.id); - response += `\`audit_logs_channel_id\` has been set to: ${auditLogsChannel}.\n`; + response.push(`**audit_logs_channel_id** has been set to: ${auditLogsChannel}.`); } const voiceLogsChannel = interaction.options.getChannel('voice-logs-channel'); if (voiceLogsChannel) { await Database.updateGuildSettings(interaction.guildId, 'voice_logs_channel_id', voiceLogsChannel.id); - response += `\`voice_logs_channel_id\` has been set to: ${voiceLogsChannel}.\n`; + response.push(`**voice_logs_channel_id** has been set to: ${voiceLogsChannel}.`); } const newMemberLogsChannel = interaction.options.getChannel('new-member-channel'); if (newMemberLogsChannel) { await Database.updateGuildSettings(interaction.guildId, 'new_member_channel_id', newMemberLogsChannel.id); - response += `\`new_member_channel_id\` has been set to: ${newMemberLogsChannel}.\n`; + response.push(`**new_member_channel_id** has been set to: ${newMemberLogsChannel}.`); } const moderatorChannel = interaction.options.getChannel('moderator-channel'); if (moderatorChannel) { await Database.updateGuildSettings(interaction.guildId, 'moderator_channel_id', moderatorChannel.id); - response += `\`moderator_channel_id\` has been set to": ${moderatorChannel}.\n`; + response.push(`**moderator_channel_id** has been set to": ${moderatorChannel}.`); } const adminRole = interaction.options.getRole('admin-role'); if (adminRole) { await Database.updateGuildSettings(interaction.guildId, 'admin_role_id', adminRole.id); - response += `\`admin_role_id\` has been set to: ${adminRole}.\n`; + response.push(`**admin_role_id** has been set to: ${adminRole}.`); } const privateHelperRole = interaction.options.getRole('private-helper-role'); if (privateHelperRole) { await Database.updateGuildSettings(interaction.guildId, 'private_help_role_id', privateHelperRole.id); - response += `\`private_help_role_id\` has been set to: ${privateHelperRole}.\n`; + response.push(`**private_help_role_id** has been set to: ${privateHelperRole}.`); } const devWatchRole = interaction.options.getRole('devwatch-role'); if (devWatchRole) { await Database.updateGuildSettings(interaction.guildId, 'devwatch_role_id', devWatchRole.id); - response += `\`private_help_role_id\` has been set to ${devWatchRole}.\n`; + response.push(`**private_help_role_id** has been set to ${devWatchRole}.`); } const addCategory = interaction.options.getChannel('add-staff-category'); if (addCategory) { if (addCategory.type == ChannelType.GuildCategory) { await Database.putGuildArraySetting('staff_categories', interaction.guildId, addCategory.id); - response += `Added ${addCategory.toString()} as a staff category.\n`; - } else response += `Error adding staff category: ${addCategory.toString()} isn't a category.`; + response.push(`Added ${addCategory.toString()} as a staff category.`); + } else response.push(`Error adding staff category: ${addCategory.toString()} isn't a category.`); } const removeCategory = interaction.options.getChannel('remove-staff-category'); if (removeCategory) { if (removeCategory.type == ChannelType.GuildCategory) if (await Database.removeGuildArraySetting('staff_categories', interaction.guildId, removeCategory.id)) - response += `Removed ${removeCategory.toString()} as a staff category\n`; - else response += `Error removing staff category: ${removeCategory.toString()} isn't a staff category.`; - else response += `Error removing staff category: ${removeCategory.toString()} isn't a category.`; + response.push(`Removed ${removeCategory.toString()} as a staff category`); + else response.push(`Error removing staff category: ${removeCategory.toString()} isn't a staff category.`); + else response.push(`Error removing staff category: ${removeCategory.toString()} isn't a category.`); } const addSafeChannel = interaction.options.getChannel('add-safe-channel'); if (addSafeChannel) { if (addSafeChannel.type == ChannelType.GuildText) { await Database.putGuildArraySetting('safe_channels', interaction.guildId, addSafeChannel.id); - response += `Added ${addSafeChannel.toString()} as a SFW cannel.\n`; - } else response += `Error adding SFW channel: ${addSafeChannel.toString()} isn't a text channel.`; + response.push(`Added ${addSafeChannel.toString()} as a SFW cannel.`); + } else response.push(`Error adding SFW channel: ${addSafeChannel.toString()} isn't a text channel.`); } const removeSafeChannel = interaction.options.getChannel('remove-safe-channel'); if (removeSafeChannel) { if (removeSafeChannel.type == ChannelType.GuildText) if (await Database.removeGuildArraySetting('safe_channels', interaction.guildId, removeSafeChannel.id)) - response += `Removed ${removeSafeChannel.toString()} as a safe channel\n`; - else response += `Error removing safe channel: ${removeSafeChannel.toString()} isn't a safe channel.`; - else response += `Error removing safe channel: ${removeSafeChannel.toString()} isn't a text channel.`; + response.push(`Removed ${removeSafeChannel.toString()} as a safe channel`); + else response.push(`Error removing safe channel: ${removeSafeChannel.toString()} isn't a safe channel.`); + else response.push(`Error removing safe channel: ${removeSafeChannel.toString()} isn't a text channel.`); } const addLinkSkipChannel = interaction.options.getChannel('add-link-skip-channel'); if (addLinkSkipChannel) { if (addLinkSkipChannel.type == ChannelType.GuildText) { await Database.putGuildArraySetting('link_skip_channels', interaction.guildId, addLinkSkipChannel.id); - response += `Added ${addLinkSkipChannel.toString()} as a link skip channel.\n`; - } else response += `Error adding link skip channel: ${addLinkSkipChannel.toString()} isn't a text channel.`; + response.push(`Added ${addLinkSkipChannel.toString()} as a link skip channel.`); + } else response.push(`Error adding link skip channel: ${addLinkSkipChannel.toString()} isn't a text channel.`); } const removeLinkSkipChannel = interaction.options.getChannel('remove-link-skip-channel'); if (removeLinkSkipChannel) { if (removeLinkSkipChannel.type == ChannelType.GuildText) if (await Database.removeGuildArraySetting('link_skip_channels', interaction.guildId, removeLinkSkipChannel.id)) - response += `Removed ${removeLinkSkipChannel.toString()} as a staff category\n`; - else response += `Error removing link skip channel: ${removeLinkSkipChannel.toString()} isn't a link skip channel.`; - else response += `Error removing link skip channel: ${removeLinkSkipChannel.toString()} isn't a text channel.`; + response.push(`Removed ${removeLinkSkipChannel.toString()} as a staff category`); + else response.push(`Error removing link skip channel: ${removeLinkSkipChannel.toString()} isn't a link skip channel.`); + else response.push(`Error removing link skip channel: ${removeLinkSkipChannel.toString()} isn't a text channel.`); } const githubReleaseChannel = interaction.options.getChannel('github-release-channel'); if (githubReleaseChannel) { await Database.updateGuildSettings(interaction.guildId, 'github_release_channel', githubReleaseChannel.id); - response += `\`github_release_channel\` has been set to ${githubReleaseChannel}.\n`; + response.push(`**github_release_channel** has been set to ${githubReleaseChannel}.`); } - if (response.length == 0) return interaction.editReply({ content: 'No settings provided.' }); - interaction.editReply({ content: response }); + if (response.length == 0) return interaction.editReply({ + embeds: [{ + ...CreateDefaultEmbed(client), + ...SetSeverity('warning'), + + description: 'No settings were modified.' + }] + }); + + interaction.editReply({ + embeds: [{ + ...CreateDefaultEmbed(client), + ...SetSeverity('success'), + + description: response.join('\n') + }] + }); } }; diff --git a/src/utils/embed-utils.ts b/src/utils/embed-utils.ts new file mode 100644 index 0000000..6fcbe9a --- /dev/null +++ b/src/utils/embed-utils.ts @@ -0,0 +1,31 @@ +import { APIEmbed, Client } from 'discord.js'; + +type EmbedSeverity = + | 'default' + | 'info' + | 'warning' + | 'error' + | 'success' + +export function CreateDefaultEmbed(context: Client): APIEmbed { + if (!context.user) return {}; + + return { + footer: { + icon_url: context.user.avatarURL()!, + text: context.user.username + }, + + timestamp: new Date().toISOString() + } +} + +export function SetSeverity(severity: EmbedSeverity): APIEmbed { + switch (severity) { + case 'default': return { color: 0x014995 } + case 'info': return { color: 0x5865F2 } + case 'warning': return { color: 0xFEE75C } + case 'error': return { color: 0xED4245 } + case 'success': return { color: 0x57F287 } + } +} diff --git a/src/utils/index.ts b/src/utils/index.ts index 2ced0b1..1d24584 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,29 +1,30 @@ -export * from './alt-utils'; -export * from './array-utils'; -export * from './audit-log-utils'; -export * from './ban-events'; -export * from './ban-utils'; -export * from './channel-utils'; -export * from './commands'; -export * from './debug-utils'; -export * from './discord-user-utils'; -export * from './e621-utils'; -export * from './event-log-utils'; -export * from './file-utils'; -export * from './github-user-utils'; -export * from './interaction-utils'; -export * from './message-matcher-regex'; -export * from './message-utils'; -export * from './modal-utils'; -export * from './ms-to-human'; -export * from './name-sync'; -export * from './note-utils'; -export * from './oauth2'; -export * from './private-help-utils'; -export * from './record-utils'; -export * from './refresh-commands'; -export * from './string-utils'; -export * from './ticket-events'; -export * from './ticket-utils'; -export * from './wait'; -export * from './whois'; +export * from './alt-utils'; +export * from './array-utils'; +export * from './audit-log-utils'; +export * from './ban-events'; +export * from './ban-utils'; +export * from './channel-utils'; +export * from './commands'; +export * from './debug-utils'; +export * from './discord-user-utils'; +export * from './embed-utils'; +export * from './e621-utils'; +export * from './event-log-utils'; +export * from './file-utils'; +export * from './github-user-utils'; +export * from './interaction-utils'; +export * from './message-matcher-regex'; +export * from './message-utils'; +export * from './modal-utils'; +export * from './ms-to-human'; +export * from './name-sync'; +export * from './note-utils'; +export * from './oauth2'; +export * from './private-help-utils'; +export * from './record-utils'; +export * from './refresh-commands'; +export * from './string-utils'; +export * from './ticket-events'; +export * from './ticket-utils'; +export * from './wait'; +export * from './whois';