Added a embed pre-builder to make all the embeds consistent.
This commit is contained in:
+47
-30
@@ -1,5 +1,6 @@
|
|||||||
import { ApplicationIntegrationType, ChannelType, ChatInputCommandInteraction, Client, InteractionContextType, MessageFlags, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
|
import { ApplicationIntegrationType, ChannelType, ChatInputCommandInteraction, Client, InteractionContextType, MessageFlags, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
|
||||||
import { Database } from '../shared/Database';
|
import { Database } from '../shared/Database';
|
||||||
|
import { CreateDefaultEmbed, SetSeverity } from '../utils';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'settings',
|
name: 'settings',
|
||||||
@@ -117,138 +118,154 @@ export default {
|
|||||||
.setDescription('Set the github release channel.')
|
.setDescription('Set the github release channel.')
|
||||||
.setRequired(false)
|
.setRequired(false)
|
||||||
),
|
),
|
||||||
|
|
||||||
handler: async function (client: Client, interaction: ChatInputCommandInteraction) {
|
handler: async function (client: Client, interaction: ChatInputCommandInteraction) {
|
||||||
if (!interaction.guildId) return; // This shouldn't occur, but TypeScript doesn't know that.
|
if (!interaction.guildId) return; // This shouldn't occur, but TypeScript doesn't know that.
|
||||||
await interaction.deferReply({ flags: [MessageFlags.Ephemeral] });
|
await interaction.deferReply({ flags: [MessageFlags.Ephemeral] });
|
||||||
|
|
||||||
let response = '';
|
const response: string[] = [];
|
||||||
const settings = await Database.getGuildSettings(interaction.guildId!);
|
const settings = await Database.getGuildSettings(interaction.guildId!);
|
||||||
if (!settings) await Database.putGuild(interaction.guildId);
|
if (!settings) await Database.putGuild(interaction.guildId);
|
||||||
|
|
||||||
const generalChannel = interaction.options.getChannel('general-channel');
|
const generalChannel = interaction.options.getChannel('general-channel');
|
||||||
if (generalChannel) {
|
if (generalChannel) {
|
||||||
await Database.updateGuildSettings(interaction.guildId, 'general_chat_id', generalChannel.id);
|
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');
|
const ticketsChannel = interaction.options.getChannel('tickets-channel');
|
||||||
if (ticketsChannel) {
|
if (ticketsChannel) {
|
||||||
await Database.updateGuildSettings(interaction.guildId, 'tickets_channel_id', ticketsChannel.id);
|
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');
|
const eventLogsChannel = interaction.options.getChannel('event-logs-channel');
|
||||||
if (eventLogsChannel) {
|
if (eventLogsChannel) {
|
||||||
await Database.updateGuildSettings(interaction.guildId, 'event_logs_channel_id', eventLogsChannel.id);
|
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');
|
const discordLogsChannel = interaction.options.getChannel('discord-logs-channel');
|
||||||
if (discordLogsChannel) {
|
if (discordLogsChannel) {
|
||||||
await Database.updateGuildSettings(interaction.guildId, 'discord_logs_channel_id', discordLogsChannel.id);
|
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');
|
const auditLogsChannel = interaction.options.getChannel('audit-logs-channel');
|
||||||
if (auditLogsChannel) {
|
if (auditLogsChannel) {
|
||||||
await Database.updateGuildSettings(interaction.guildId, 'audit_logs_channel_id', auditLogsChannel.id);
|
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');
|
const voiceLogsChannel = interaction.options.getChannel('voice-logs-channel');
|
||||||
if (voiceLogsChannel) {
|
if (voiceLogsChannel) {
|
||||||
await Database.updateGuildSettings(interaction.guildId, 'voice_logs_channel_id', voiceLogsChannel.id);
|
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');
|
const newMemberLogsChannel = interaction.options.getChannel('new-member-channel');
|
||||||
if (newMemberLogsChannel) {
|
if (newMemberLogsChannel) {
|
||||||
await Database.updateGuildSettings(interaction.guildId, 'new_member_channel_id', newMemberLogsChannel.id);
|
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');
|
const moderatorChannel = interaction.options.getChannel('moderator-channel');
|
||||||
if (moderatorChannel) {
|
if (moderatorChannel) {
|
||||||
await Database.updateGuildSettings(interaction.guildId, 'moderator_channel_id', moderatorChannel.id);
|
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');
|
const adminRole = interaction.options.getRole('admin-role');
|
||||||
if (adminRole) {
|
if (adminRole) {
|
||||||
await Database.updateGuildSettings(interaction.guildId, 'admin_role_id', adminRole.id);
|
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');
|
const privateHelperRole = interaction.options.getRole('private-helper-role');
|
||||||
if (privateHelperRole) {
|
if (privateHelperRole) {
|
||||||
await Database.updateGuildSettings(interaction.guildId, 'private_help_role_id', privateHelperRole.id);
|
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');
|
const devWatchRole = interaction.options.getRole('devwatch-role');
|
||||||
if (devWatchRole) {
|
if (devWatchRole) {
|
||||||
await Database.updateGuildSettings(interaction.guildId, 'devwatch_role_id', devWatchRole.id);
|
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');
|
const addCategory = interaction.options.getChannel('add-staff-category');
|
||||||
if (addCategory) {
|
if (addCategory) {
|
||||||
if (addCategory.type == ChannelType.GuildCategory) {
|
if (addCategory.type == ChannelType.GuildCategory) {
|
||||||
await Database.putGuildArraySetting('staff_categories', interaction.guildId, addCategory.id);
|
await Database.putGuildArraySetting('staff_categories', interaction.guildId, addCategory.id);
|
||||||
response += `Added ${addCategory.toString()} as a staff category.\n`;
|
response.push(`Added ${addCategory.toString()} as a staff category.`);
|
||||||
} else response += `Error adding staff category: ${addCategory.toString()} isn't a category.`;
|
} else response.push(`Error adding staff category: ${addCategory.toString()} isn't a category.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const removeCategory = interaction.options.getChannel('remove-staff-category');
|
const removeCategory = interaction.options.getChannel('remove-staff-category');
|
||||||
if (removeCategory) {
|
if (removeCategory) {
|
||||||
if (removeCategory.type == ChannelType.GuildCategory)
|
if (removeCategory.type == ChannelType.GuildCategory)
|
||||||
if (await Database.removeGuildArraySetting('staff_categories', interaction.guildId, removeCategory.id))
|
if (await Database.removeGuildArraySetting('staff_categories', interaction.guildId, removeCategory.id))
|
||||||
response += `Removed ${removeCategory.toString()} as a staff category\n`;
|
response.push(`Removed ${removeCategory.toString()} as a staff category`);
|
||||||
else response += `Error removing staff category: ${removeCategory.toString()} isn't a staff category.`;
|
else response.push(`Error removing staff category: ${removeCategory.toString()} isn't a staff category.`);
|
||||||
else response += `Error removing staff category: ${removeCategory.toString()} isn't a category.`;
|
else response.push(`Error removing staff category: ${removeCategory.toString()} isn't a category.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const addSafeChannel = interaction.options.getChannel('add-safe-channel');
|
const addSafeChannel = interaction.options.getChannel('add-safe-channel');
|
||||||
if (addSafeChannel) {
|
if (addSafeChannel) {
|
||||||
if (addSafeChannel.type == ChannelType.GuildText) {
|
if (addSafeChannel.type == ChannelType.GuildText) {
|
||||||
await Database.putGuildArraySetting('safe_channels', interaction.guildId, addSafeChannel.id);
|
await Database.putGuildArraySetting('safe_channels', interaction.guildId, addSafeChannel.id);
|
||||||
response += `Added ${addSafeChannel.toString()} as a SFW cannel.\n`;
|
response.push(`Added ${addSafeChannel.toString()} as a SFW cannel.`);
|
||||||
} else response += `Error adding SFW channel: ${addSafeChannel.toString()} isn't a text channel.`;
|
} else response.push(`Error adding SFW channel: ${addSafeChannel.toString()} isn't a text channel.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const removeSafeChannel = interaction.options.getChannel('remove-safe-channel');
|
const removeSafeChannel = interaction.options.getChannel('remove-safe-channel');
|
||||||
if (removeSafeChannel) {
|
if (removeSafeChannel) {
|
||||||
if (removeSafeChannel.type == ChannelType.GuildText)
|
if (removeSafeChannel.type == ChannelType.GuildText)
|
||||||
if (await Database.removeGuildArraySetting('safe_channels', interaction.guildId, removeSafeChannel.id))
|
if (await Database.removeGuildArraySetting('safe_channels', interaction.guildId, removeSafeChannel.id))
|
||||||
response += `Removed ${removeSafeChannel.toString()} as a safe channel\n`;
|
response.push(`Removed ${removeSafeChannel.toString()} as a safe channel`);
|
||||||
else response += `Error removing safe channel: ${removeSafeChannel.toString()} isn't a safe channel.`;
|
else response.push(`Error removing safe channel: ${removeSafeChannel.toString()} isn't a safe channel.`);
|
||||||
else response += `Error removing safe channel: ${removeSafeChannel.toString()} isn't a text channel.`;
|
else response.push(`Error removing safe channel: ${removeSafeChannel.toString()} isn't a text channel.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const addLinkSkipChannel = interaction.options.getChannel('add-link-skip-channel');
|
const addLinkSkipChannel = interaction.options.getChannel('add-link-skip-channel');
|
||||||
if (addLinkSkipChannel) {
|
if (addLinkSkipChannel) {
|
||||||
if (addLinkSkipChannel.type == ChannelType.GuildText) {
|
if (addLinkSkipChannel.type == ChannelType.GuildText) {
|
||||||
await Database.putGuildArraySetting('link_skip_channels', interaction.guildId, addLinkSkipChannel.id);
|
await Database.putGuildArraySetting('link_skip_channels', interaction.guildId, addLinkSkipChannel.id);
|
||||||
response += `Added ${addLinkSkipChannel.toString()} as a link skip channel.\n`;
|
response.push(`Added ${addLinkSkipChannel.toString()} as a link skip channel.`);
|
||||||
} else response += `Error adding link skip channel: ${addLinkSkipChannel.toString()} isn't a text 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');
|
const removeLinkSkipChannel = interaction.options.getChannel('remove-link-skip-channel');
|
||||||
if (removeLinkSkipChannel) {
|
if (removeLinkSkipChannel) {
|
||||||
if (removeLinkSkipChannel.type == ChannelType.GuildText)
|
if (removeLinkSkipChannel.type == ChannelType.GuildText)
|
||||||
if (await Database.removeGuildArraySetting('link_skip_channels', interaction.guildId, removeLinkSkipChannel.id))
|
if (await Database.removeGuildArraySetting('link_skip_channels', interaction.guildId, removeLinkSkipChannel.id))
|
||||||
response += `Removed ${removeLinkSkipChannel.toString()} as a staff category\n`;
|
response.push(`Removed ${removeLinkSkipChannel.toString()} as a staff category`);
|
||||||
else response += `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 link skip channel.`);
|
||||||
else response += `Error removing link skip channel: ${removeLinkSkipChannel.toString()} isn't a text channel.`;
|
else response.push(`Error removing link skip channel: ${removeLinkSkipChannel.toString()} isn't a text channel.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const githubReleaseChannel = interaction.options.getChannel('github-release-channel');
|
const githubReleaseChannel = interaction.options.getChannel('github-release-channel');
|
||||||
if (githubReleaseChannel) {
|
if (githubReleaseChannel) {
|
||||||
await Database.updateGuildSettings(interaction.guildId, 'github_release_channel', githubReleaseChannel.id);
|
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.' });
|
if (response.length == 0) return interaction.editReply({
|
||||||
interaction.editReply({ content: response });
|
embeds: [{
|
||||||
|
...CreateDefaultEmbed(client),
|
||||||
|
...SetSeverity('warning'),
|
||||||
|
|
||||||
|
description: 'No settings were modified.'
|
||||||
|
}]
|
||||||
|
});
|
||||||
|
|
||||||
|
interaction.editReply({
|
||||||
|
embeds: [{
|
||||||
|
...CreateDefaultEmbed(client),
|
||||||
|
...SetSeverity('success'),
|
||||||
|
|
||||||
|
description: response.join('\n')
|
||||||
|
}]
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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 }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@ export * from './channel-utils';
|
|||||||
export * from './commands';
|
export * from './commands';
|
||||||
export * from './debug-utils';
|
export * from './debug-utils';
|
||||||
export * from './discord-user-utils';
|
export * from './discord-user-utils';
|
||||||
|
export * from './embed-utils';
|
||||||
export * from './e621-utils';
|
export * from './e621-utils';
|
||||||
export * from './event-log-utils';
|
export * from './event-log-utils';
|
||||||
export * from './file-utils';
|
export * from './file-utils';
|
||||||
|
|||||||
Reference in New Issue
Block a user