Skip to content

Commit

Permalink
feat(dev): announce command to send messages to the network!
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-737 committed Dec 22, 2022
1 parent ac671f5 commit 7c2de32
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/Commands/Developer/announce.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { SlashCommandBuilder, ChatInputCommandInteraction, ModalBuilder, TextInputBuilder, ActionRowBuilder, TextInputStyle } from 'discord.js';
import { stripIndents } from 'common-tags';
import logger from '../../Utils/logger';

export default {
developer: true,
data: new SlashCommandBuilder()
.setName('announce')
.setDescription('Announce something to the network!')
.setDefaultMemberPermissions('0'),
async execute(interaction: ChatInputCommandInteraction) {
const modal = new ModalBuilder().setCustomId(`submit_${interaction.user.id}`).setTitle('Enter JSON value').addComponents(
new ActionRowBuilder<TextInputBuilder>().addComponents(
new TextInputBuilder()
.setCustomId('input')
.setLabel('Input')
.setStyle(TextInputStyle.Paragraph)
.setRequired(true)
.setValue(stripIndents`
{
"content": "Hello World!"
}
`)
.setPlaceholder('Any valid messageCreateOption is allowed. Make sure it is in valid JSON format.'),
),
);

await interaction.showModal(modal);

interaction.awaitModalSubmit({
time: 60_000,
}).then(async (i) => {
const rawInput = i.fields.getTextInputValue('input');
let parsedInput;

try {
const preview = await i.channel?.send('This is the preview.');
parsedInput = JSON.parse(rawInput);
await preview?.edit(parsedInput);
}
catch (e) {
return i.reply({ content: `Invalid JSON provided.\n\`\`\`${e}\`\`\``, ephemeral: true });
}
await interaction.client.sendInNetwork(parsedInput);
i.reply('Message announced to the network!');
}).catch((err) => !err.message.includes('reason: time') ? logger.error('[announce_err]:', err) : null);
},
};

0 comments on commit 7c2de32

Please sign in to comment.