aboutsummaryrefslogtreecommitdiff
path: root/bot/src/commands/fetch.js
diff options
context:
space:
mode:
authorAndrew Lee <andrew@alee14.me>2025-03-08 17:23:34 -0500
committerAndrew Lee <andrew@alee14.me>2025-03-08 17:23:34 -0500
commit48a576ab5605ec3ec9272809668b8d7ce91c477e (patch)
tree7780c94dd6a39c5b5beae9edfc568e6669b88967 /bot/src/commands/fetch.js
parent52f8826e526f0c0aadb86c3e29975aef4dc1ab85 (diff)
downloadAleeBot-48a576ab5605ec3ec9272809668b8d7ce91c477e.tar.gz
AleeBot-48a576ab5605ec3ec9272809668b8d7ce91c477e.tar.bz2
AleeBot-48a576ab5605ec3ec9272809668b8d7ce91c477e.zip
Put LLM output on text file; Some fixes in logging; New command
Diffstat (limited to 'bot/src/commands/fetch.js')
-rw-r--r--bot/src/commands/fetch.js34
1 files changed, 34 insertions, 0 deletions
diff --git a/bot/src/commands/fetch.js b/bot/src/commands/fetch.js
new file mode 100644
index 0000000..651fb06
--- /dev/null
+++ b/bot/src/commands/fetch.js
@@ -0,0 +1,34 @@
+import { AttachmentBuilder, SlashCommandBuilder } from 'discord.js';
+
+export default {
+ data: new SlashCommandBuilder()
+ .setName('fetch')
+ .setDescription('Fetches JSON data.')
+ .addStringOption(option =>
+ option
+ .setName('url')
+ .setDescription('Enter the URL you want to fetch.')
+ .setRequired(true)),
+ execute(interaction) {
+ const url = interaction.options.getString('url');
+ fetch(url)
+ .then(response => response.json())
+ .then(async data => {
+ const dataString = JSON.stringify(data, null, 2);
+ if (dataString.length === 0) {
+ return await interaction.reply('Received an empty response.');
+ }
+
+ if (dataString.length > 2000) {
+ const attachment = new AttachmentBuilder(Buffer.from(dataString, 'utf-8'), { name: 'messages.json' });
+ return await interaction.reply({ files: [attachment] });
+ }
+
+ return await interaction.reply(`\`\`\`json\n${dataString}\n\`\`\``);
+ })
+ .catch(async error => {
+ console.error(error);
+ return await interaction.reply(`An error occurred while fetching the URL data.\n\`\`\`js\n${error.stack}\`\`\``);
+ });
+ }
+};