61 lines
		
	
	
		
			2.6 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			61 lines
		
	
	
		
			2.6 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import { ChatInputCommandInteraction, PermissionFlagsBits, SlashCommandBuilder } from "discord.js";
 | |
| import { Badword, database } from "../data";
 | |
| import { getGuildSetting, isPremiumActive } from "../tools/data";
 | |
| import getDefaultEmbed from "../tools/defaultEmbeds";
 | |
| import moment from "moment";
 | |
| import { Color, Emoji } from "../tools/design";
 | |
| import { getGuildChannel } from "../tools/discord";
 | |
| 
 | |
| const builder = new SlashCommandBuilder();
 | |
| builder.setName("showsettings");
 | |
| builder.setDescription("Show the current settings of this guild");
 | |
| builder.setDMPermission(false);
 | |
| builder.setDefaultMemberPermissions(PermissionFlagsBits.ManageGuild);
 | |
| 
 | |
| async function execute(interaction: ChatInputCommandInteraction): Promise<void> {
 | |
|     if (!interaction.inGuild()) throw new Error("Interaction was performed outside guild context");
 | |
| 
 | |
|     const settings = await getGuildSetting(interaction.guildId);
 | |
|     const isPremium = await isPremiumActive(settings.isPremiumUntil);
 | |
|     const wordCount = await database.getRepository(Badword).count({
 | |
|         where: {
 | |
|             guildID: interaction.guildId
 | |
|         }
 | |
|     });
 | |
| 
 | |
|     const logChannel = settings.notificationChannelID ? await getGuildChannel(interaction.guildId, settings.notificationChannelID) : null;
 | |
| 
 | |
|     const embed = getDefaultEmbed();
 | |
|     embed.setTitle(`Settings from guild ${interaction.guild?.name || ""} (${interaction.guildId})`);
 | |
|     embed.setDescription(isPremium ? `${Emoji.PREMIUM} your subscription ends in ${moment(settings.isPremiumUntil).fromNow(true)}` : `Consider Premium status to get an increased blocklist`);
 | |
|     embed.setColor(isPremium ? Color.PREMIUM_ORANGE : Color.INFORMING_BLUE);
 | |
|     embed.addFields({
 | |
|         name: "Premium",
 | |
|         value: isPremium ? `${Emoji.PREMIUM} active` : `${Emoji.SWITCH_OFF} inactive`,
 | |
|         inline: true
 | |
|     }, {
 | |
|         name: "Logchannel",
 | |
|         value: logChannel && logChannel.isTextBased() ? `<#${logChannel.id}>` : "Not configured",
 | |
|         inline: true
 | |
|     }, {
 | |
|         name: "Words in Blocklist",
 | |
|         value: `${wordCount}/${isPremium ? "100" : "10"}`,
 | |
|         inline: true
 | |
|     }, {
 | |
|         name: `Preserve data on server leave is ${settings.preserveDataOnGuildLeave ? "active" : "inactive"}`,
 | |
|         value: settings.preserveDataOnGuildLeave ? "Your settings will be saved even if the bot gets kicked" : "Your settings will be deleted as soon as the bot leaves this server"
 | |
|     }, {
 | |
|         name: `${Emoji.WAVING} Found a bug? Want to request a feature? Say hello?`,
 | |
|         value: "Join the support server at https://go.astrogd.eu/discord"
 | |
|     });
 | |
| 
 | |
|     interaction.reply({
 | |
|         embeds: [embed],
 | |
|         ephemeral: true
 | |
|     }).catch();
 | |
| }
 | |
| 
 | |
| export {
 | |
|     builder,
 | |
|     execute
 | |
| } |