diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b3f65db --- /dev/null +++ b/Dockerfile @@ -0,0 +1,30 @@ +FROM node:23-bullseye-slim AS base +WORKDIR /usr/src/application + +# Clone source files +COPY --chown=node:node commands/ commands/ +COPY --chown=node:node src/ src/ +COPY --chown=node:node deploy-commands.js . +COPY --chown=node:node index.js . +COPY --chown=node:node package.json . +COPY --chown=node:node entrypoint.sh /entrypoint.sh +#COPY --chown=node:node .env . + +ENV OAB_TOKEN=null +ENV OAB_GUILD=null +ENV OAB_CLIENT=null + +# Setting up Yarn +RUN yarn set version stable + +FROM base AS builder +RUN yarn install +RUN yarn node ./deploy-commands.js + +FROM base AS runner +RUN yarn workspaces focus --all --production +RUN chmod +x /entrypoint.sh +RUN chown node:node /usr/src/application + +USER node +ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file diff --git a/commands/utility/addjob.js b/commands/utility/addjob.js index a23e52b..e786956 100644 --- a/commands/utility/addjob.js +++ b/commands/utility/addjob.js @@ -6,52 +6,38 @@ module.exports = { data: new SlashCommandBuilder() .setName('addjob') .setDescription('Adds job to CSV file with the chosen values.') - .addStringOption(option => - option - .setName('scene_id') - .setDescription('Scene ID') - .setRequired(true)) - .addStringOption(option => - option - .setName('description') - .setDescription('Description') - .setRequired(true)) - .addStringOption(option => - option - .setName('attachments') - .setDescription('Attached files') - .setRequired(true)) - .addStringOption(option => - option - .setName('attributes') - .setDescription('Attributes') - .setRequired(true)) - .addStringOption(option => - option - .setName('required_roles') - .setDescription('Required roles') - .setRequired(true)) - .addStringOption(option => - option - .setName('deadline') - .setDescription('Deadline') - .setRequired(true)) - .addStringOption(option => + .addStringOption((option) => option.setName('scene_id').setDescription('Scene ID').setRequired(true)) + .addStringOption((option) => + option.setName('description').setDescription('Description').setRequired(true) + ) + .addStringOption((option) => + option.setName('attachments').setDescription('Attached files').setRequired(true) + ) + .addStringOption((option) => + option.setName('attributes').setDescription('Attributes').setRequired(true) + ) + .addStringOption((option) => + option.setName('required_roles').setDescription('Required roles').setRequired(true) + ) + .addStringOption((option) => option.setName('deadline').setDescription('Deadline').setRequired(true)) + .addStringOption((option) => option .setName('status') .setDescription('Status') .setRequired(true) - .addChoices(Job.getAvailableStatuses())) - .setDefaultMemberPermissions(PermissionFlagsBits.SendMessages | - PermissionFlagsBits.AttachFiles | - PermissionFlagsBits.ReadMessageHistory | - PermissionFlagsBits.AddReactions | - PermissionFlagsBits.UseApplicationCommands | - PermissionFlagsBits.SendPolls | - PermissionFlagsBits.ViewChannel), + .addChoices(Job.getAvailableStatuses()) + ) + .setDefaultMemberPermissions( + PermissionFlagsBits.SendMessages | + PermissionFlagsBits.AttachFiles | + PermissionFlagsBits.ReadMessageHistory | + PermissionFlagsBits.AddReactions | + PermissionFlagsBits.UseApplicationCommands | + PermissionFlagsBits.SendPolls | + PermissionFlagsBits.ViewChannel + ), async execute(interaction) { - // Pipe all inputs through Job class so the setters can validate the input const pipe_job = new Job( interaction.options.getString('scene_id'), @@ -60,14 +46,16 @@ module.exports = { interaction.options.getString('attributes'), interaction.options.getString('required_roles'), interaction.options.getString('deadline'), - interaction.options.getString('status')); + interaction.options.getString('status') + ); if (fs.existsSync('jobs.v0.csv')) { fs.appendFileSync('jobs.v0.csv', pipe_job.getCSVString().concat(',N/A,N/A\n')); - } - else { - - fs.appendFileSync('jobs.v0.csv', 'SceneId,Description,Attachments,Attributes,RequiredRoles,Deadline,Status,Assignee,Work\n'); + } else { + fs.appendFileSync( + 'jobs.v0.csv', + 'SceneId,Description,Attachments,Attributes,RequiredRoles,Deadline,Status,Assignee,Work\n' + ); fs.appendFileSync('jobs.v0.csv', pipe_job.getCSVString().concat(',N/A,N/A\n')); } @@ -81,4 +69,4 @@ module.exports = { * Deadline: ${pipe_job.getDeadline()} * Status: ${pipe_job.getStatus()}`); }, -}; \ No newline at end of file +}; diff --git a/commands/utility/alljobs.js b/commands/utility/alljobs.js index 56e317c..05a2205 100644 --- a/commands/utility/alljobs.js +++ b/commands/utility/alljobs.js @@ -6,13 +6,15 @@ module.exports = { data: new SlashCommandBuilder() .setName('alljobs') .setDescription('Displays all jobs.') - .setDefaultMemberPermissions(PermissionFlagsBits.SendMessages | - PermissionFlagsBits.AttachFiles | - PermissionFlagsBits.ReadMessageHistory | - PermissionFlagsBits.AddReactions | - PermissionFlagsBits.UseApplicationCommands | - PermissionFlagsBits.SendPolls | - PermissionFlagsBits.ViewChannel), + .setDefaultMemberPermissions( + PermissionFlagsBits.SendMessages | + PermissionFlagsBits.AttachFiles | + PermissionFlagsBits.ReadMessageHistory | + PermissionFlagsBits.AddReactions | + PermissionFlagsBits.UseApplicationCommands | + PermissionFlagsBits.SendPolls | + PermissionFlagsBits.ViewChannel + ), async execute(interaction) { const jobs = parse(fs.readFileSync('jobs.v0.csv')); @@ -23,14 +25,18 @@ module.exports = { // Are we at the header? if (i[0] == 'SceneId') { // Create formatted header - table = table.concat('__Scene ID, Description, Attachments, Attributes, Required roles, Deadline, Status, Assignee, Work__\n'); + table = table.concat( + '__Scene ID, Description, Attachments, Attributes, Required roles, Deadline, Status, Assignee, Work__\n' + ); continue; } // Create row - table = table.concat(`${i[0]}, "${i[1]}", ${i[2]}, ${i[3]}, ${i[4]}, ${i[5]}, ${i[6]}, ${i[7]}, ${i[8]}\n`); + table = table.concat( + `${i[0]}, "${i[1]}", ${i[2]}, ${i[3]}, ${i[4]}, ${i[5]}, ${i[6]}, ${i[7]}, ${i[8]}\n` + ); } interaction.reply(table); }, -}; \ No newline at end of file +}; diff --git a/commands/utility/deletejob.js b/commands/utility/deletejob.js index 66824e0..525c5cc 100644 --- a/commands/utility/deletejob.js +++ b/commands/utility/deletejob.js @@ -6,18 +6,18 @@ module.exports = { data: new SlashCommandBuilder() .setName('deletejob') .setDescription('Deletes the specified job.') - .addStringOption(option => - option - .setName('scene_id') - .setDescription('Scene ID whose job to delete') - .setRequired(true)) - .setDefaultMemberPermissions(PermissionFlagsBits.SendMessages | - PermissionFlagsBits.AttachFiles | - PermissionFlagsBits.ReadMessageHistory | - PermissionFlagsBits.AddReactions | - PermissionFlagsBits.UseApplicationCommands | - PermissionFlagsBits.SendPolls | - PermissionFlagsBits.ViewChannel), + .addStringOption((option) => + option.setName('scene_id').setDescription('Scene ID whose job to delete').setRequired(true) + ) + .setDefaultMemberPermissions( + PermissionFlagsBits.SendMessages | + PermissionFlagsBits.AttachFiles | + PermissionFlagsBits.ReadMessageHistory | + PermissionFlagsBits.AddReactions | + PermissionFlagsBits.UseApplicationCommands | + PermissionFlagsBits.SendPolls | + PermissionFlagsBits.ViewChannel + ), async execute(interaction) { const scene_id = interaction.options.getString('scene_id').toUpperCase(); @@ -38,4 +38,4 @@ module.exports = { interaction.reply(`The job for scene ${scene_id} has been deleted.`); }, -}; \ No newline at end of file +}; diff --git a/commands/utility/displayjob.js b/commands/utility/displayjob.js index 0507f44..ae3f1f3 100644 --- a/commands/utility/displayjob.js +++ b/commands/utility/displayjob.js @@ -6,18 +6,16 @@ module.exports = { data: new SlashCommandBuilder() .setName('displayjob') .setDescription('Displays the specified job.') - .addStringOption(option => - option - .setName('scene_id') - .setDescription('Scene ID') - .setRequired(true)) - .setDefaultMemberPermissions(PermissionFlagsBits.SendMessages | - PermissionFlagsBits.AttachFiles | - PermissionFlagsBits.ReadMessageHistory | - PermissionFlagsBits.AddReactions | - PermissionFlagsBits.UseApplicationCommands | - PermissionFlagsBits.SendPolls | - PermissionFlagsBits.ViewChannel), + .addStringOption((option) => option.setName('scene_id').setDescription('Scene ID').setRequired(true)) + .setDefaultMemberPermissions( + PermissionFlagsBits.SendMessages | + PermissionFlagsBits.AttachFiles | + PermissionFlagsBits.ReadMessageHistory | + PermissionFlagsBits.AddReactions | + PermissionFlagsBits.UseApplicationCommands | + PermissionFlagsBits.SendPolls | + PermissionFlagsBits.ViewChannel + ), async execute(interaction) { const scene_id = interaction.options.getString('scene_id'); @@ -39,4 +37,4 @@ module.exports = { } } }, -}; \ No newline at end of file +}; diff --git a/commands/utility/editjob.js b/commands/utility/editjob.js index 9166ca4..4612bd2 100644 --- a/commands/utility/editjob.js +++ b/commands/utility/editjob.js @@ -3,48 +3,30 @@ const { parse } = require('csv/sync'); const { SlashCommandBuilder, PermissionFlagsBits } = require('discord.js'); const Job = require('../../src/jobsManager.js'); - module.exports = { data: new SlashCommandBuilder() .setName('editjob') .setDescription('Edits the specified job.') - .addStringOption(option => - option - .setName('scene_id') - .setDescription('Scene ID whose job to edit') - .setRequired(true)) - .addStringOption(option => - option - .setName('description') - .setDescription('Description')) - .addStringOption(option => - option - .setName('attachments') - .setDescription('Attached files')) - .addStringOption(option => - option - .setName('attributes') - .setDescription('Attributes')) - .addStringOption(option => - option - .setName('required_roles') - .setDescription('Required roles')) - .addStringOption(option => - option - .setName('deadline') - .setDescription('Deadline')) - .addStringOption(option => - option - .setName('status') - .setDescription('Status') - .addChoices(Job.getAvailableStatuses())) - .setDefaultMemberPermissions(PermissionFlagsBits.SendMessages | - PermissionFlagsBits.AttachFiles | - PermissionFlagsBits.ReadMessageHistory | - PermissionFlagsBits.AddReactions | - PermissionFlagsBits.UseApplicationCommands | - PermissionFlagsBits.SendPolls | - PermissionFlagsBits.ViewChannel), + .addStringOption((option) => + option.setName('scene_id').setDescription('Scene ID whose job to edit').setRequired(true) + ) + .addStringOption((option) => option.setName('description').setDescription('Description')) + .addStringOption((option) => option.setName('attachments').setDescription('Attached files')) + .addStringOption((option) => option.setName('attributes').setDescription('Attributes')) + .addStringOption((option) => option.setName('required_roles').setDescription('Required roles')) + .addStringOption((option) => option.setName('deadline').setDescription('Deadline')) + .addStringOption((option) => + option.setName('status').setDescription('Status').addChoices(Job.getAvailableStatuses()) + ) + .setDefaultMemberPermissions( + PermissionFlagsBits.SendMessages | + PermissionFlagsBits.AttachFiles | + PermissionFlagsBits.ReadMessageHistory | + PermissionFlagsBits.AddReactions | + PermissionFlagsBits.UseApplicationCommands | + PermissionFlagsBits.SendPolls | + PermissionFlagsBits.ViewChannel + ), async execute(interaction) { const scene_id = interaction.options.getString('scene_id').toUpperCase(); @@ -76,11 +58,9 @@ module.exports = { for (let i = 0; i < current_scene.length; i++) { if (new_scene[i] === null || new_scene[i] === undefined) { scene.push(current_scene[i]); - } - else if (i === 0) { + } else if (i === 0) { scene.push(scene_id); - } - else if (new_scene[i] !== current_scene[i]) { + } else if (new_scene[i] !== current_scene[i]) { scene.push(new_scene[i]); } } @@ -90,7 +70,9 @@ module.exports = { if (scene_id === jobs[i][0]) { let current_jobs = fs.readFileSync('jobs.v0.csv').toString().split('\n'); current_jobs.splice(i, 1); - current_jobs = current_jobs.concat(`${scene[0]},"${scene[1]}",${scene[2]},${scene[3]},${scene[4]},${scene[5]},${scene[6]},${scene[7]},${scene[8]}`); + current_jobs = current_jobs.concat( + `${scene[0]},"${scene[1]}",${scene[2]},${scene[3]},${scene[4]},${scene[5]},${scene[6]},${scene[7]},${scene[8]}` + ); const new_jobs = current_jobs.join('\n'); fs.writeFileSync('jobs.v0.csv', new_jobs); @@ -98,4 +80,4 @@ module.exports = { } } }, -}; \ No newline at end of file +}; diff --git a/commands/utility/getjob.js b/commands/utility/getjob.js index 27f3969..fa854a9 100644 --- a/commands/utility/getjob.js +++ b/commands/utility/getjob.js @@ -6,18 +6,16 @@ module.exports = { data: new SlashCommandBuilder() .setName('getjob') .setDescription('Gets you the specified job.') - .addStringOption(option => - option - .setName('scene_id') - .setDescription('Scene ID') - .setRequired(true)) - .setDefaultMemberPermissions(PermissionFlagsBits.SendMessages | - PermissionFlagsBits.AttachFiles | - PermissionFlagsBits.ReadMessageHistory | - PermissionFlagsBits.AddReactions | - PermissionFlagsBits.UseApplicationCommands | - PermissionFlagsBits.SendPolls | - PermissionFlagsBits.ViewChannel), + .addStringOption((option) => option.setName('scene_id').setDescription('Scene ID').setRequired(true)) + .setDefaultMemberPermissions( + PermissionFlagsBits.SendMessages | + PermissionFlagsBits.AttachFiles | + PermissionFlagsBits.ReadMessageHistory | + PermissionFlagsBits.AddReactions | + PermissionFlagsBits.UseApplicationCommands | + PermissionFlagsBits.SendPolls | + PermissionFlagsBits.ViewChannel + ), async execute(interaction) { const scene_id = interaction.options.getString('scene_id'); @@ -43,4 +41,4 @@ If you find yourself unable to meet the deadline, send the following message: "I } } }, -}; \ No newline at end of file +}; diff --git a/commands/utility/giverole.js b/commands/utility/giverole.js index bd65c25..10258a3 100644 --- a/commands/utility/giverole.js +++ b/commands/utility/giverole.js @@ -4,34 +4,31 @@ module.exports = { data: new SlashCommandBuilder() .setName('giverole') .setDescription('Gives the chosen user the chosen role.') - .addRoleOption(option => - option - .setName('role') - .setDescription('Role to give to user') - .setRequired(true)) - .addUserOption(option => - option - .setName('target') - .setDescription('User to give role to') - .setRequired(true)) - .setDefaultMemberPermissions(PermissionFlagsBits.SendMessages | - PermissionFlagsBits.AttachFiles | - PermissionFlagsBits.ReadMessageHistory | - PermissionFlagsBits.AddReactions | - PermissionFlagsBits.UseApplicationCommands | - PermissionFlagsBits.SendPolls | - PermissionFlagsBits.ViewChannel), + .addRoleOption((option) => + option.setName('role').setDescription('Role to give to user').setRequired(true) + ) + .addUserOption((option) => + option.setName('target').setDescription('User to give role to').setRequired(true) + ) + .setDefaultMemberPermissions( + PermissionFlagsBits.SendMessages | + PermissionFlagsBits.AttachFiles | + PermissionFlagsBits.ReadMessageHistory | + PermissionFlagsBits.AddReactions | + PermissionFlagsBits.UseApplicationCommands | + PermissionFlagsBits.SendPolls | + PermissionFlagsBits.ViewChannel + ), async execute(interaction) { const role = interaction.options.getRole('role'); const member = interaction.options.getMember('target'); - if (member.roles.cache.some(role_to_check => role_to_check.name === role.name)) { + if (member.roles.cache.some((role_to_check) => role_to_check.name === role.name)) { interaction.reply(`${member} already has the role ${role}.`); - } - else { + } else { member.roles.add(role); interaction.reply(`${member} has been given the role ${role}.`); } }, -}; \ No newline at end of file +}; diff --git a/commands/utility/hello.js b/commands/utility/hello.js index ced6a6c..4ab908c 100644 --- a/commands/utility/hello.js +++ b/commands/utility/hello.js @@ -1,11 +1,9 @@ const { SlashCommandBuilder } = require('discord.js'); module.exports = { - data: new SlashCommandBuilder() - .setName('hello') - .setDescription('Replies with World!'), + data: new SlashCommandBuilder().setName('hello').setDescription('Replies with World!'), async execute(interaction) { await interaction.reply('World!'); }, -}; \ No newline at end of file +}; diff --git a/commands/utility/help.js b/commands/utility/help.js index d782147..ec98a63 100644 --- a/commands/utility/help.js +++ b/commands/utility/help.js @@ -2,14 +2,11 @@ const fs = require('node:fs'); const { Collection, MessageFlags, SlashCommandBuilder } = require('discord.js'); const HORIZONTAL_SPACE = 15; - module.exports = { - data: new SlashCommandBuilder() - .setName('help') - .setDescription('Gets a list of commands and what they do.'), + data: new SlashCommandBuilder().setName('help').setDescription('Gets a list of commands and what they do.'), async execute(interaction) { - const commandFiles = fs.readdirSync(__dirname).filter(file => file.endsWith('.js')); + const commandFiles = fs.readdirSync(__dirname).filter((file) => file.endsWith('.js')); const commands = new Collection(); @@ -23,9 +20,9 @@ module.exports = { for (const command of commands) { // Make a spaces to pad the name so descriptions are aligned let tab = ''; - for (let i = 0;i < HORIZONTAL_SPACE - String(command[0]).length;i++) { + for (let i = 0; i < HORIZONTAL_SPACE - String(command[0]).length; i++) { tab = tab + ' '; - }; + } // Combine the messages msg = msg.concat(`\n \`/${command[0]}`); msg = msg.concat(tab); @@ -34,4 +31,4 @@ module.exports = { await interaction.reply({ content: msg, flags: MessageFlags.Ephemeral }); }, -}; \ No newline at end of file +}; diff --git a/commands/utility/removerole.js b/commands/utility/removerole.js index 440a94d..7131511 100644 --- a/commands/utility/removerole.js +++ b/commands/utility/removerole.js @@ -4,34 +4,31 @@ module.exports = { data: new SlashCommandBuilder() .setName('removerole') .setDescription('Removes the chosen role from the chosen user.') - .addRoleOption(option => - option - .setName('role') - .setDescription('Role to remove from user') - .setRequired(true)) - .addUserOption(option => - option - .setName('target') - .setDescription('User to remove role from') - .setRequired(true)) - .setDefaultMemberPermissions(PermissionFlagsBits.SendMessages | - PermissionFlagsBits.AttachFiles | - PermissionFlagsBits.ReadMessageHistory | - PermissionFlagsBits.AddReactions | - PermissionFlagsBits.UseApplicationCommands | - PermissionFlagsBits.SendPolls | - PermissionFlagsBits.ViewChannel), + .addRoleOption((option) => + option.setName('role').setDescription('Role to remove from user').setRequired(true) + ) + .addUserOption((option) => + option.setName('target').setDescription('User to remove role from').setRequired(true) + ) + .setDefaultMemberPermissions( + PermissionFlagsBits.SendMessages | + PermissionFlagsBits.AttachFiles | + PermissionFlagsBits.ReadMessageHistory | + PermissionFlagsBits.AddReactions | + PermissionFlagsBits.UseApplicationCommands | + PermissionFlagsBits.SendPolls | + PermissionFlagsBits.ViewChannel + ), async execute(interaction) { const role = interaction.options.getRole('role'); const member = interaction.options.getMember('target'); - if (member.roles.cache.some(role_to_check => role_to_check.name === role.name)) { + if (member.roles.cache.some((role_to_check) => role_to_check.name === role.name)) { member.roles.remove(role); interaction.reply(`${member} no longer has the role ${role}.`); - } - else { + } else { interaction.reply(`${member} already doesn't have the role ${role}.`); } }, -}; \ No newline at end of file +}; diff --git a/deploy-commands.js b/deploy-commands.js index 4817484..1316ad3 100644 --- a/deploy-commands.js +++ b/deploy-commands.js @@ -1,7 +1,10 @@ const { REST, Routes } = require('discord.js'); -const { clientId, guildId, token } = require(process.argv.slice(2).toString()); const fs = require('node:fs'); const path = require('node:path'); +const dotenv = require('dotenv'); +dotenv.config(); + +const { OAB_CLIENT, OAB_GUILD, OAB_TOKEN } = process.env; const commands = []; // Grab all the command folders from the commands directory you created earlier @@ -11,22 +14,23 @@ const commandFolders = fs.readdirSync(foldersPath); for (const folder of commandFolders) { // Grab all the command files from the commands directory you created earlier const commandsPath = path.join(foldersPath, folder); - const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js')); + const commandFiles = fs.readdirSync(commandsPath).filter((file) => file.endsWith('.js')); // Grab the SlashCommandBuilder#toJSON() output of each command's data for deployment for (const file of commandFiles) { const filePath = path.join(commandsPath, file); const command = require(filePath); if ('data' in command && 'execute' in command) { commands.push(command.data.toJSON()); - } - else { - console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`); + } else { + console.log( + `[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.` + ); } } } // Construct and prepare an instance of the REST module -const rest = new REST().setToken(token); +const rest = new REST().setToken(OAB_TOKEN); // and deploy your commands! (async () => { @@ -34,14 +38,10 @@ const rest = new REST().setToken(token); console.log(`Started refreshing ${commands.length} application (/) commands.`); // The put method is used to fully refresh all commands in the guild with the current set - const data = await rest.put( - Routes.applicationGuildCommands(clientId, guildId), - { body: commands }, - ); + const data = await rest.put(Routes.applicationGuildCommands(OAB_CLIENT, OAB_GUILD), { body: commands }); console.log(`Successfully reloaded ${data.length} application (/) commands.`); - } - catch (error) { + } catch (error) { // And of course, make sure you catch and log any errors! console.error(error); } diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..99514f7 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +# Function to check if an environment variable is not null or empty +check_env() { + VAR_NAME="$1" + VAR_VALUE=$(eval echo \$$VAR_NAME) + + if [ -z "$VAR_VALUE" ] || [ "$VAR_VALUE" = "null" ]; then + echo ":: OAB :: Error: Environment variable $VAR_NAME is either empty or set to 'null'." + exit 1 + fi +} + +# List of required environment variables to check +REQUIRED_ENV_VARS="token guildId clientId" + +for VAR in $REQUIRED_ENV_VARS; do + check_env "$VAR" +done + +echo ":: OAB :: All environment variables are set correctly." +exec "yarn node index.js" diff --git a/example.env b/example.env new file mode 100644 index 0000000..d52e0d4 --- /dev/null +++ b/example.env @@ -0,0 +1,3 @@ +token=hello-im-meant-to-be-a-bot-token +guildId=hello-im-meant-to-be-a-guild-id +clientId=hello-im-meant-to-be-a-client-id \ No newline at end of file diff --git a/index.js b/index.js index 345ace4..9136ad7 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,8 @@ const fs = require('node:fs'); const path = require('node:path'); const { Client, Collection, Events, GatewayIntentBits, MessageFlags } = require('discord.js'); -const { token } = require(process.argv.slice(2).toString()); +const dotenv = require('dotenv'); +dotenv.config(); // Create a new client instance const client = new Client({ intents: [GatewayIntentBits.Guilds] }); @@ -13,25 +14,26 @@ const commandFolders = fs.readdirSync(foldersPath); for (const folder of commandFolders) { const commandsPath = path.join(foldersPath, folder); - const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js')); + const commandFiles = fs.readdirSync(commandsPath).filter((file) => file.endsWith('.js')); for (const file of commandFiles) { const filePath = path.join(commandsPath, file); const command = require(filePath); // Set a new item in the Collection with the key as the command name and the value as the exported module if ('data' in command && 'execute' in command) { client.commands.set(command.data.name, command); - } - else { - console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`); + } else { + console.log( + `[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.` + ); } } } -client.once(Events.ClientReady, readyClient => { +client.once(Events.ClientReady, (readyClient) => { console.log(`Ready! Logged in as ${readyClient.user.tag}`); }); -client.on(Events.InteractionCreate, async interaction => { +client.on(Events.InteractionCreate, async (interaction) => { if (!interaction.isChatInputCommand()) return; const command = interaction.client.commands.get(interaction.commandName); @@ -43,17 +45,21 @@ client.on(Events.InteractionCreate, async interaction => { try { await command.execute(interaction); - } - catch (error) { + } catch (error) { console.error(error); if (interaction.replied || interaction.deferred) { - await interaction.followUp({ content: `There was an error while executing this command! \n\`${error}\``, flags: MessageFlags.Ephemeral }); - } - else { - await interaction.reply({ content: `There was an error while executing this command! \n\`${error}\``, flags: MessageFlags.Ephemeral }); + await interaction.followUp({ + content: `There was an error while executing this command! \n\`${error}\``, + flags: MessageFlags.Ephemeral, + }); + } else { + await interaction.reply({ + content: `There was an error while executing this command! \n\`${error}\``, + flags: MessageFlags.Ephemeral, + }); } } }); // Log in to Discord with your client's token -client.login(token); +client.login(process.env.OAB_TOKEN); diff --git a/package-lock.json b/package-lock.json index b40535f..002bac3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,8 @@ "license": "MIT", "dependencies": { "csv": "^6.3.11", - "discord.js": "^14.17.3" + "discord.js": "^14.17.3", + "dotenv": "^16.4.7" }, "devDependencies": { "@eslint/js": "^9.19.0", @@ -653,6 +654,18 @@ "url": "https://github.com/discordjs/discord.js?sponsor" } }, + "node_modules/dotenv": { + "version": "16.4.7", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.7.tgz", + "integrity": "sha512-47qPchRCykZC03FhkYAhrvwU4xDBFIj1QPqaarj6mdM/hgUzfPHcpkHJOn3mJAufFeeAxAzeGsr5X0M4k6fLZQ==", + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, "node_modules/escape-string-regexp": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", diff --git a/package.json b/package.json index 9a9d2cf..56f8a5d 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,8 @@ }, "dependencies": { "csv": "^6.3.11", - "discord.js": "^14.17.3" + "discord.js": "^14.17.3", + "dotenv": "^16.4.7" }, "devDependencies": { "@eslint/js": "^9.19.0", diff --git a/src/jobsManager.js b/src/jobsManager.js index de2bf71..f9deffc 100644 --- a/src/jobsManager.js +++ b/src/jobsManager.js @@ -14,12 +14,11 @@ class Job { this.setStatus(status); } - static available_statuses = [ { name: 'Completed', value: 'COMPLETED' }, { name: 'In Progress', value: 'IN_PROGRESS' }, - { name: 'Unassigned', value: 'UNASSIGNED' }]; - + { name: 'Unassigned', value: 'UNASSIGNED' }, + ]; getJobArray() { return [ @@ -29,14 +28,14 @@ class Job { this.attributes, this.required_roles, this.deadline, - this.status]; + this.status, + ]; } getCSVString() { return stringify([this.getJobArray()]).trimEnd(); } - getSceneId() { return this.scene_id; } @@ -46,28 +45,28 @@ class Job { getAttachments() { return this.attachments; - }; + } getAttributes() { return this.attributes; - }; + } getRequiredRoles() { return this.required_roles; - }; + } getDeadline() { return this.deadline; - }; + } getStatus() { return this.status; - }; + } // Returns an array of Objects with name: and value: pair static getAvailableStatuses() { return this.available_statuses; - }; + } setSceneId(scene_id) { this.scene_id = scene_id.toString().toUpperCase(); @@ -78,34 +77,37 @@ class Job { setAttachments(attachments) { this.attachments = attachments; - }; + } setAttributes(attributes) { this.attributes = attributes; - }; + } setRequiredRoles(required_roles) { this.required_roles = required_roles; - }; + } setDeadline(deadline) { this.deadline = deadline; - }; + } // For correct values use Job.getAvailableStatuses() setStatus(status) { + // try { for (const x of Job.available_statuses) { if (x.value == status) { this.status = status; } } if (this.status === undefined || this.status === null || this.status !== status) { - throw new TypeError(`"${status}" is an invalid status`); + throw new TypeError(`"${status}\" is an invalid status`); } - }; - - -}; + // } + // catch (error) { + // console.log(error + ': Error setting "' + status + '" as a status'); + // } + } +} module.exports = Job; @@ -116,4 +118,3 @@ module.exports = Job; // console.log(anime.getCSVString()); // const audio = new Job(1, 1, 1, 1, 1, 1, 'bad stuff'); -