From 4c853ae503e991d29a8fe96f8eecc0b032be04c6 Mon Sep 17 00:00:00 2001 From: Maverick Date: Fri, 7 Oct 2022 13:54:17 +0200 Subject: [PATCH] Added support for type commands --- deploy-commands.js | 26 ++++++++++++++++++++------ html-to-png.js | 15 +++++++++++++++ index.js | 12 ++++-------- 3 files changed, 39 insertions(+), 14 deletions(-) create mode 100644 html-to-png.js diff --git a/deploy-commands.js b/deploy-commands.js index e02d0e8..0e35816 100644 --- a/deploy-commands.js +++ b/deploy-commands.js @@ -5,9 +5,19 @@ const guildId = process.env.GUILD_ID; const token = process.env.TOKEN; const commands = [ - new SlashCommandBuilder().setName('ping').setDescription('Replies with pong!'), - new SlashCommandBuilder().setName('server').setDescription('Replies with server info!'), - new SlashCommandBuilder().setName('user').setDescription('Replies with user info!'), + new SlashCommandBuilder() + .setName('generate') + .setDescription('Generate something.') + .addStringOption(option => + option.setName('type') + .setDescription('The type of thing to generate.') + .setRequired(true) + .addChoices( + { name: 'Host', value: 'host' }, + { name: 'Gang', value: 'gang' }, + { name: 'Corporation', value: 'corporation' }, + ) + ) ] .map(command => command.toJSON()); @@ -17,6 +27,10 @@ rest.put(Routes.applicationGuildCommands(clientId, guildId), { body: [] }) .then((data) => console.log('Removed all commands from guilds')) .catch(console.error); -rest.put(Routes.applicationGuildCommands(clientId, guildId), { body: commands }) - .then((data) => console.log(`Successfully registered ${data.length} application commands.`)) - .catch(console.error); \ No newline at end of file +rest.put(Routes.applicationCommands(clientId), { body: [] }) + .then((data) => console.log(`Removed all global commands`)) + .catch(console.error); + +rest.put(Routes.applicationCommands(clientId), { body: commands }) + .then((data) => console.log(`Added ${data.length} commands to global`)) + .catch(console.error); \ No newline at end of file diff --git a/html-to-png.js b/html-to-png.js new file mode 100644 index 0000000..538c47c --- /dev/null +++ b/html-to-png.js @@ -0,0 +1,15 @@ +import { Puppeteer } from "puppeteer"; + +export default async function (html) { + + const browser = await Puppeteer.launch(); + const page = await browser.newPage(); + + await page.setContent(html); + const file = await page.screenshot({ type: "png" }); + + await page.close(); + await browser.close(); + + return file; +} \ No newline at end of file diff --git a/index.js b/index.js index 7f43056..c70f4b6 100644 --- a/index.js +++ b/index.js @@ -8,20 +8,16 @@ const client = new Client({ }) client.once('ready', () => { - console.log('Ready!'); + console.log('Bot is Ready!'); }); client.on('interactionCreate', async interaction => { if (!interaction.isCommand()) return; - const commandName = interaction.commandName; + let commandName = interaction.commandName; - if (commandName === 'ping') { - await interaction.reply('Pong!'); - } else if (commandName === 'server') { - await interaction.reply(`Server name: ${interaction.guild.name}\nTotal members: ${interaction.guild.memberCount}`); - } else if (commandName === 'user') { - await interaction.reply(`Your tag: ${interaction.user.tag}\nYour id: ${interaction.user.id}`); + if (commandName === "generate") { + await interaction.reply(`Generating ${interaction.options.getString('type')}`); } })