From 1bb204883c2d7dbddadf3aa2a0f3672bdb0a0732 Mon Sep 17 00:00:00 2001 From: Cesium Date: Tue, 11 Nov 2025 13:34:35 -0500 Subject: [PATCH] task command work --- commands/bot/task.js | 26 ++++++++++++++++++++++++-- commands/bot/tasks.js | 18 +++++++++++++++--- index.js | 5 ++--- 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/commands/bot/task.js b/commands/bot/task.js index fd3433b..9f0dad8 100644 --- a/commands/bot/task.js +++ b/commands/bot/task.js @@ -1,10 +1,32 @@ const { SlashCommandBuilder } = require('discord.js'); +const torn = require('../../torn.js'); +const config = require('../../config.json'); +const state = require('../../state.json'); module.exports = { data: new SlashCommandBuilder() .setName('task') - .setDescription('Execute a task.'), + .setDescription('Execute a task.') + .addStringOption(option => + option.setName('name') + .setDescription('The name of the task to execute.') + .setRequired(true)), async execute(interaction) { - await interaction.reply('todo'); + const taskName = interaction.options.getString('name'); + const task = interaction.client.tasks[taskName]; + + if (!task) { + await interaction.reply({ content: `Task "${taskName}" not found.`, ephemeral: true }); + return; + } + + try { + await interaction.reply({ content: `Executing task "${taskName}"...`, ephemeral: true }); + await task(interaction.client, torn, config, state); + await interaction.followUp({ content: `Task "${taskName}" executed successfully.`, ephemeral: true }); + } catch (error) { + console.error(error); + await interaction.followUp({ content: `There was an error while executing task "${taskName}"!`, ephemeral: true }); + } }, }; \ No newline at end of file diff --git a/commands/bot/tasks.js b/commands/bot/tasks.js index 2fe0e9c..9170c00 100644 --- a/commands/bot/tasks.js +++ b/commands/bot/tasks.js @@ -1,10 +1,22 @@ -const { SlashCommandBuilder } = require('discord.js'); +const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); module.exports = { data: new SlashCommandBuilder() .setName('tasks') - .setDescription('List tasks'), + .setDescription('Lists all available tasks.'), async execute(interaction) { - await interaction.reply('todo'); + const taskNames = Object.keys(interaction.client.tasks); + + if (taskNames.length === 0) { + await interaction.reply({ content: 'No tasks found.', ephemeral: true }); + return; + } + + const embed = new EmbedBuilder() + .setColor(0xBB99FF) + .setTitle('Available Tasks') + .setDescription(taskNames.map(name => `- ${name}`).join('\n')); + + await interaction.reply({ embeds: [embed], ephemeral: true }); }, }; \ No newline at end of file diff --git a/index.js b/index.js index 8ddcf30..b3525c2 100644 --- a/index.js +++ b/index.js @@ -32,15 +32,14 @@ client.once(Events.ClientReady, readyClient => { }); client.login(config.token); client.commands = new Collection(); +client.tasks = {}; - -let task = {}; fs.readdir('./tasks/', (err, files) => { if (err) return console.log(err); files.forEach(file => { const taskFile = require(`./tasks/${file}`); const taskName = file.split('.')[0]; - task[taskName] = taskFile; + client.tasks[taskName] = taskFile; if (taskFile.schedule) { console.debug(`Tasks: Scheduling "${taskName}" for ${taskFile.schedule}`); cron.schedule(taskFile.schedule, () => { taskFile(client, torn, config, state); });