diff --git a/commands/balance.js b/commands/balance.js deleted file mode 100644 index 0e55a68..0000000 --- a/commands/balance.js +++ /dev/null @@ -1,83 +0,0 @@ -const { SlashCommandBuilder } = require('@discordjs/builders'); - -const db = require('quick.db'); -const credits = new db.table('credits'); - -module.exports = { - data: new SlashCommandBuilder() - .setName('balance') - .setDescription('Check your balance or view top balance.') - .addSubcommand((subcommand) => - subcommand - .setName('check') - .setDescription('Check your balance') - .addUserOption((option) => - option - .setName('user') - .setDescription('The user whose balance you want to check.') - .setRequired(false) - ) - ) - .addSubcommand((subcommand) => subcommand.setName('top').setDescription('View top balance')), - async execute(interaction) { - await interaction.deferReply({ ephemeral: true }); - if (interaction.options.getSubcommand() === 'check') { - const user = await interaction.options.getUser('user'); - - const amount = await credits.get(user ? user.id : interaction.user.id); - if (amount) { - const embed = { - title: 'Balance', - description: `${user ? `${user} has` : 'You have'} ${ - amount <= 1 ? `${amount} credit` : `${amount} credits` - }.`, - color: 0x22bb33, - timestamp: new Date(), - footer: { text: 'Zyner Bot' }, - }; - return await interaction.editReply({ embeds: [embed], ephemeral: true }); - } else { - const embed = { - title: 'Balance', - description: `${user} has no credits.`, - color: 0xbb2124, - timestamp: new Date(), - footer: { text: 'Zyner Bot' }, - }; - return await interaction.editReply({ embeds: [embed], ephemeral: true }); - } - } else if (interaction.options.getSubcommand() === 'top') { - const { client } = interaction; - const all = credits.all(); - const allSorted = all.sort((a, b) => (a.data > b.data ? -1 : 1)); - - const topTen = allSorted.slice(0, 10); - - const topTens = []; - - Promise.all( - topTen.map(async (x, i) => { - user = await client.users.fetch(`${x.ID}`, { force: true }); - topTens.push({ index: i, user: user, credits: x.data }); - }) - ).then(async () => { - const embed = { - title: 'Balance Top', - description: `Below are the top ten.\n - ${topTens - .map( - (x) => - `**Top ${x.index + 1}** - ${x.user}: ${ - x.credits <= 1 ? `${x.credits} credit` : `${x.credits} credits` - }` - ) - .join('\n')}`, - color: 0x22bb33, - timestamp: new Date(), - footer: { text: 'Zyner Bot' }, - }; - return await interaction.editReply({ embeds: [embed], ephemeral: true }); - }); - } - }, -}; diff --git a/commands/gift.js b/commands/gift.js deleted file mode 100644 index a23df4e..0000000 --- a/commands/gift.js +++ /dev/null @@ -1,70 +0,0 @@ -const { SlashCommandBuilder } = require('@discordjs/builders'); - -const db = require('quick.db'); - -const credits = new db.table('credits'); - -module.exports = { - data: new SlashCommandBuilder() - .setName('gift') - .setDescription('Gift from your credits to another user.') - .addUserOption((option) => - option.setName('user').setDescription('The user you want to pay.').setRequired(true) - ) - .addIntegerOption((option) => - option.setName('amount').setDescription('The amount you will pay.').setRequired(true) - ), - async execute(interaction) { - await interaction.deferReply({ ephemeral: true }); - - const user = await interaction.options.getUser('user'); - const amount = await interaction.options.getInteger('amount'); - - if (user.id === interaction.user.id) { - const embed = { - title: 'Gift failed', - description: "You can't pay yourself.", - color: 0xbb2124, - timestamp: new Date(), - footer: { text: 'Zyner Bot' }, - }; - return await interaction.editReply({ embeds: [embed], ephemeral: true }); - } else if (amount <= 0) { - const embed = { - title: 'Gift failed', - description: "You can't pay zero or below.", - color: 0xbb2124, - timestamp: new Date(), - footer: { text: 'Zyner Bot' }, - }; - return await interaction.editReply({ embeds: [embed], ephemeral: true }); - } else { - if ((await credits.get(interaction.user.id)) < amount) { - const embed = { - title: 'Gift', - description: `You have insufficient credits. Your balance is ${credits.get( - interaction.user.id - )}`, - color: 0xbb2124, - timestamp: new Date(), - footer: { text: 'Zyner Bot' }, - }; - return await interaction.editReply({ embeds: [embed], ephemeral: true }); - } else { - await credits.subtract(interaction.user.id, amount); - await credits.add(user.id, amount); - - const embed = { - title: 'Gift', - description: `You sent ${ - amount <= 1 ? `${amount} credit` : `${amount} credits` - } to ${user}. Your new balance is ${await credits.get(interaction.user.id)}.`, - color: 0x22bb33, - timestamp: new Date(), - footer: { text: 'Zyner Bot' }, - }; - return await interaction.editReply({ embeds: [embed], ephemeral: true }); - } - } - }, -}; diff --git a/commands/give.js b/commands/give.js deleted file mode 100644 index 2cacd69..0000000 --- a/commands/give.js +++ /dev/null @@ -1,52 +0,0 @@ -const { SlashCommandBuilder } = require('@discordjs/builders'); -const { Permissions } = require('discord.js'); - -const db = require('quick.db'); - -const credits = new db.table('credits'); - -module.exports = { - data: new SlashCommandBuilder() - .setName('give') - .setDescription('Give a user credits (ADMIN).') - .addUserOption((option) => - option.setName('user').setDescription('The user you want to pay.').setRequired(true) - ) - .addIntegerOption((option) => - option.setName('amount').setDescription('The amount you will pay.').setRequired(true) - ), - async execute(interaction) { - await interaction.deferReply({ ephemeral: true }); - if (!interaction.member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) { - const embed = { - title: 'Give failed', - description: 'You need to have permission to manage this guild (MANAGE_GUILD)', - }; - return await interaction.editReply({ embeds: [embed], ephemeral: true }); - } - const user = await interaction.options.getUser('user'); - const amount = await interaction.options.getInteger('amount'); - - if (amount <= 0) { - const embed = { - title: 'Give', - description: "You can't give zero or below.", - color: 0xbb2124, - timestamp: new Date(), - footer: { text: 'Zyner Bot' }, - }; - return await interaction.editReply({ embeds: [embed], ephemeral: true }); - } else { - await credits.add(user.id, amount); - - const embed = { - title: 'Give', - description: `Gave ${amount <= 1 ? `${amount} credit` : `${amount} credits`} to ${user}.`, - color: 0x22bb33, - timestamp: new Date(), - footer: { text: 'Zyner Bot' }, - }; - return await interaction.editReply({ embeds: [embed], ephemeral: true }); - } - }, -}; diff --git a/commands/redeem.js b/commands/redeem.js deleted file mode 100644 index 86c2b87..0000000 --- a/commands/redeem.js +++ /dev/null @@ -1,107 +0,0 @@ -const { SlashCommandBuilder } = require('@discordjs/builders'); - -const { disableRedeem } = require('../config.json'); - -const db = require('quick.db'); - -const credits = new db.table('credits'); - -const api = require('../handlers/api.js'); - -const { v4: uuidv4 } = require('uuid'); - -module.exports = { - data: new SlashCommandBuilder() - .setName('redeem') - .setDescription('Redeem your credits.') - .addIntegerOption((option) => - option.setName('amount').setDescription('How much credit you want to withdraw.') - ), - async execute(interaction) { - await interaction.deferReply({ ephemeral: true }); - - if (disableRedeem) { - const embed = { - title: 'Redeem failed', - description: `Redeem is disabled until further.`, - color: 0xbb2124, - timestamp: new Date(), - footer: { text: 'Zyner Bot' }, - }; - return await await interaction.editReply({ embeds: [embed], ephemeral: true }); - } - const amount = await interaction.options.getInteger('amount'); - - const userCredits = await credits.get(interaction.user.id); - - if ((amount || userCredits) < 100) { - const embed = { - title: 'Redeem', - description: `You can't redeem below 100. Your balance is ${userCredits}.`, - color: 0xbb2124, - timestamp: new Date(), - footer: { text: 'Zyner Bot' }, - }; - return await interaction.editReply({ embeds: [embed], ephemeral: true }); - } else if ((amount || userCredits) > 1000000) { - const embed = { - title: 'Redeem', - description: `You can't redeem over 1,000,000. Your balance is ${userCredits}.`, - color: 0xbb2124, - timestamp: new Date(), - footer: { text: 'Zyner Bot' }, - }; - return await interaction.editReply({ embeds: [embed], ephemeral: true }); - } else if (userCredits < amount) { - const embed = { - title: 'Redeem', - description: `You have insufficient credits. Your balance is ${userCredits}.`, - color: 0xbb2124, - timestamp: new Date(), - footer: { text: 'Zyner Bot' }, - }; - return await interaction.editReply({ embeds: [embed], ephemeral: true }); - } else { - const code = uuidv4(); - - api - .post('vouchers', { - uses: 1, - code, - credits: amount || userCredits, - memo: `${interaction.createdTimestamp} - ${interaction.user.id}`, - }) - .then(async (res) => { - const embed = { - title: 'Redeem', - description: `Your new balance is ${userCredits - (amount || userCredits)}.`, - fields: [ - { name: 'Code', value: `${code}`, inline: true }, - { - name: 'Credits', - value: `${amount || userCredits}`, - inline: true, - }, - ], - color: 0x22bb33, - timestamp: new Date(), - footer: { text: 'Zyner Bot' }, - }; - await credits.subtract(interaction.user.id, amount || userCredits); - - await interaction.editReply({ embeds: [embed], ephemeral: true }); - }) - .catch(async (err) => { - console.log(err); - const embed = { - title: 'Redeem', - description: 'Something went wrong.', - color: 0xbb2124, - timestamp: new Date(), - footer: { text: 'Zyner Bot' }, - }; - return await interaction.editReply({ embeds: [embed], ephemeral: true }); - }); - } - }, -}; diff --git a/commands/take.js b/commands/take.js deleted file mode 100644 index 290a6f3..0000000 --- a/commands/take.js +++ /dev/null @@ -1,59 +0,0 @@ -const { SlashCommandBuilder } = require('@discordjs/builders'); -const { Permissions } = require('discord.js'); - -const db = require('quick.db'); - -const credits = new db.table('credits'); - -module.exports = { - data: new SlashCommandBuilder() - .setName('take') - .setDescription('Take credits from a user (ADMIN).') - .addUserOption((option) => - option - .setName('user') - .setDescription('The user you want to take credits from.') - .setRequired(true) - ) - .addIntegerOption((option) => - option.setName('amount').setDescription('The amount you will take.').setRequired(true) - ), - async execute(interaction) { - if (!interaction.member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) { - const embed = { - title: 'Take', - description: 'You need to have permission to manage this guild (MANAGE_GUILD)', - color: 0xbb2124, - timestamp: new Date(), - footer: { text: 'Zyner Bot' }, - }; - return await interaction.reply({ embeds: [embed], ephemeral: true }); - } - const user = await interaction.options.getUser('user'); - const amount = await interaction.options.getInteger('amount'); - - if (amount <= 0) { - const embed = { - title: 'Take', - description: "You can't take zero or below.", - color: 0xbb2124, - timestamp: new Date(), - footer: { text: 'Zyner Bot' }, - }; - return await interaction.reply({ embeds: [embed], ephemeral: true }); - } else { - await credits.subtract(user.id, amount); - - const embed = { - title: 'Take', - description: `You took ${ - amount <= 1 ? `${amount} credit` : `${amount} credits` - } to ${user}.`, - color: 0x22bb33, - timestamp: new Date(), - footer: { text: 'Zyner Bot' }, - }; - return await interaction.reply({ embeds: [embed], ephemeral: true }); - } - }, -}; diff --git a/deploy-commands.js b/deploy-commands.js index 3b33342..a704b91 100644 --- a/deploy-commands.js +++ b/deploy-commands.js @@ -1,21 +1,19 @@ -const fs = require("node:fs"); -const { REST } = require("@discordjs/rest"); -const { Routes } = require("discord-api-types/v9"); -const { clientId, guildId, token } = require("./config.json"); +const fs = require('node:fs'); +const { REST } = require('@discordjs/rest'); +const { Routes } = require('discord-api-types/v9'); +const { clientId, guildId, token } = require('./config.json'); const commands = []; -const commandFiles = fs - .readdirSync("./commands") - .filter((file) => file.endsWith(".js")); +const commandFiles = fs.readdirSync('./src/commands'); for (const file of commandFiles) { - const command = require(`./commands/${file}`); + const command = require(`./src/commands/${file}`); commands.push(command.data.toJSON()); } -const rest = new REST({ version: "9" }).setToken(token); +const rest = new REST({ version: '9' }).setToken(token); rest .put(Routes.applicationGuildCommands(clientId, guildId), { body: commands }) - .then(() => console.log("Successfully registered application commands.")) + .then(() => console.log('Successfully registered application commands.')) .catch(console.error); diff --git a/package.json b/package.json index 4159868..169752a 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { "name": "controlpanel.gg-bot", - "version": "1.0.0", + "version": "1.1.0", "description": "Earn credits when chatting", - "main": "index.js", + "main": "src/index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, @@ -28,6 +28,7 @@ "better-sqlite3": "^7.5.0", "discord-api-types": "^0.27.3", "discord.js": "^13.6.0", + "dotenv": "^16.0.0", "quick.db": "^7.1.3", "uuid": "^8.3.2" } diff --git a/src/commands/credits/addons/balance.js b/src/commands/credits/addons/balance.js new file mode 100644 index 0000000..e7bb2b6 --- /dev/null +++ b/src/commands/credits/addons/balance.js @@ -0,0 +1,28 @@ +const db = require('quick.db'); +const credits = new db.table('credits'); +module.exports = async (interaction) => { + const user = await interaction.options.getUser('user'); + + const amount = await credits.get(user ? user.id : interaction.user.id); + if (amount) { + const embed = { + title: 'Balance', + description: `${user ? `${user} has` : 'You have'} ${ + amount <= 1 ? `${amount} credit` : `${amount} credits` + }.`, + color: 0x22bb33, + timestamp: new Date(), + footer: { text: 'Zyner Bot' }, + }; + return await interaction.editReply({ embeds: [embed], ephemeral: true }); + } else { + const embed = { + title: 'Balance', + description: `${user} has no credits.`, + color: 0xbb2124, + timestamp: new Date(), + footer: { text: 'Zyner Bot' }, + }; + return await interaction.editReply({ embeds: [embed], ephemeral: true }); + } +}; diff --git a/src/commands/credits/addons/gift.js b/src/commands/credits/addons/gift.js new file mode 100644 index 0000000..70f7fa8 --- /dev/null +++ b/src/commands/credits/addons/gift.js @@ -0,0 +1,54 @@ +const db = require('quick.db'); + +const credits = new db.table('credits'); +module.exports = async (interaction) => { + const user = await interaction.options.getUser('user'); + const amount = await interaction.options.getInteger('amount'); + + if (user.id === interaction.user.id) { + const embed = { + title: 'Gift failed', + description: "You can't pay yourself.", + color: 0xbb2124, + timestamp: new Date(), + footer: { text: 'Zyner Bot' }, + }; + return await interaction.editReply({ embeds: [embed], ephemeral: true }); + } else if (amount <= 0) { + const embed = { + title: 'Gift failed', + description: "You can't pay zero or below.", + color: 0xbb2124, + timestamp: new Date(), + footer: { text: 'Zyner Bot' }, + }; + return await interaction.editReply({ embeds: [embed], ephemeral: true }); + } else { + if ((await credits.get(interaction.user.id)) < amount) { + const embed = { + title: 'Gift', + description: `You have insufficient credits. Your balance is ${credits.get( + interaction.user.id + )}`, + color: 0xbb2124, + timestamp: new Date(), + footer: { text: 'Zyner Bot' }, + }; + return await interaction.editReply({ embeds: [embed], ephemeral: true }); + } else { + await credits.subtract(interaction.user.id, amount); + await credits.add(user.id, amount); + + const embed = { + title: 'Gift', + description: `You sent ${ + amount <= 1 ? `${amount} credit` : `${amount} credits` + } to ${user}. Your new balance is ${await credits.get(interaction.user.id)}.`, + color: 0x22bb33, + timestamp: new Date(), + footer: { text: 'Zyner Bot' }, + }; + return await interaction.editReply({ embeds: [embed], ephemeral: true }); + } + } +}; diff --git a/src/commands/credits/addons/give.js b/src/commands/credits/addons/give.js new file mode 100644 index 0000000..a8b09f8 --- /dev/null +++ b/src/commands/credits/addons/give.js @@ -0,0 +1,38 @@ +const { Permissions } = require('discord.js'); + +const db = require('quick.db'); + +const credits = new db.table('credits'); +module.exports = async (interaction) => { + if (!interaction.member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) { + const embed = { + title: 'Give failed', + description: 'You need to have permission to manage this guild (MANAGE_GUILD)', + }; + return await interaction.editReply({ embeds: [embed], ephemeral: true }); + } + const user = await interaction.options.getUser('user'); + const amount = await interaction.options.getInteger('amount'); + + if (amount <= 0) { + const embed = { + title: 'Give', + description: "You can't give zero or below.", + color: 0xbb2124, + timestamp: new Date(), + footer: { text: 'Zyner Bot' }, + }; + return await interaction.editReply({ embeds: [embed], ephemeral: true }); + } else { + await credits.add(user.id, amount); + + const embed = { + title: 'Give', + description: `Gave ${amount <= 1 ? `${amount} credit` : `${amount} credits`} to ${user}.`, + color: 0x22bb33, + timestamp: new Date(), + footer: { text: 'Zyner Bot' }, + }; + return await interaction.editReply({ embeds: [embed], ephemeral: true }); + } +}; diff --git a/src/commands/credits/addons/redeem.js b/src/commands/credits/addons/redeem.js new file mode 100644 index 0000000..92250cb --- /dev/null +++ b/src/commands/credits/addons/redeem.js @@ -0,0 +1,94 @@ +const { disableRedeem } = require('../../../../config.json'); + +const db = require('quick.db'); + +const credits = new db.table('credits'); + +const api = require('../../../handlers/api.js'); + +const { v4: uuidv4 } = require('uuid'); +module.exports = async (interaction) => { + if (disableRedeem) { + const embed = { + title: 'Redeem failed', + description: `Redeem is disabled until further.`, + color: 0xbb2124, + timestamp: new Date(), + footer: { text: 'Zyner Bot' }, + }; + return await await interaction.editReply({ embeds: [embed], ephemeral: true }); + } + const amount = await interaction.options.getInteger('amount'); + + const userCredits = await credits.get(interaction.user.id); + + if ((amount || userCredits) < 100) { + const embed = { + title: 'Redeem', + description: `You can't redeem below 100. Your balance is ${userCredits}.`, + color: 0xbb2124, + timestamp: new Date(), + footer: { text: 'Zyner Bot' }, + }; + return await interaction.editReply({ embeds: [embed], ephemeral: true }); + } else if ((amount || userCredits) > 1000000) { + const embed = { + title: 'Redeem', + description: `You can't redeem over 1,000,000. Your balance is ${userCredits}.`, + color: 0xbb2124, + timestamp: new Date(), + footer: { text: 'Zyner Bot' }, + }; + return await interaction.editReply({ embeds: [embed], ephemeral: true }); + } else if (userCredits < amount) { + const embed = { + title: 'Redeem', + description: `You have insufficient credits. Your balance is ${userCredits}.`, + color: 0xbb2124, + timestamp: new Date(), + footer: { text: 'Zyner Bot' }, + }; + return await interaction.editReply({ embeds: [embed], ephemeral: true }); + } else { + const code = uuidv4(); + + api + .post('vouchers', { + uses: 1, + code, + credits: amount || userCredits, + memo: `${interaction.createdTimestamp} - ${interaction.user.id}`, + }) + .then(async (res) => { + const embed = { + title: 'Redeem', + description: `Your new balance is ${userCredits - (amount || userCredits)}.`, + fields: [ + { name: 'Code', value: `${code}`, inline: true }, + { + name: 'Credits', + value: `${amount || userCredits}`, + inline: true, + }, + ], + color: 0x22bb33, + timestamp: new Date(), + footer: { text: 'Zyner Bot' }, + }; + await credits.subtract(interaction.user.id, amount || userCredits); + + await interaction.editReply({ embeds: [embed], ephemeral: true }); + }) + .catch(async (err) => { + console.log(err); + const embed = { + title: 'Redeem', + description: 'Something went wrong.', + color: 0xbb2124, + timestamp: new Date(), + footer: { text: 'Zyner Bot' }, + }; + return await interaction.editReply({ embeds: [embed], ephemeral: true }); + }); + } +}; diff --git a/src/commands/credits/addons/take.js b/src/commands/credits/addons/take.js new file mode 100644 index 0000000..8be2077 --- /dev/null +++ b/src/commands/credits/addons/take.js @@ -0,0 +1,41 @@ +const { Permissions } = require('discord.js'); + +const db = require('quick.db'); + +const credits = new db.table('credits'); +module.exports = async (interaction) => { + if (!interaction.member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) { + const embed = { + title: 'Take', + description: 'You need to have permission to manage this guild (MANAGE_GUILD)', + color: 0xbb2124, + timestamp: new Date(), + footer: { text: 'Zyner Bot' }, + }; + return await interaction.reply({ embeds: [embed], ephemeral: true }); + } + const user = await interaction.options.getUser('user'); + const amount = await interaction.options.getInteger('amount'); + + if (amount <= 0) { + const embed = { + title: 'Take', + description: "You can't take zero or below.", + color: 0xbb2124, + timestamp: new Date(), + footer: { text: 'Zyner Bot' }, + }; + return await interaction.reply({ embeds: [embed], ephemeral: true }); + } else { + await credits.subtract(user.id, amount); + + const embed = { + title: 'Take', + description: `You took ${amount <= 1 ? `${amount} credit` : `${amount} credits`} to ${user}.`, + color: 0x22bb33, + timestamp: new Date(), + footer: { text: 'Zyner Bot' }, + }; + return await interaction.reply({ embeds: [embed], ephemeral: true }); + } +}; diff --git a/src/commands/credits/addons/top.js b/src/commands/credits/addons/top.js new file mode 100644 index 0000000..f0c8ed7 --- /dev/null +++ b/src/commands/credits/addons/top.js @@ -0,0 +1,35 @@ +const db = require('quick.db'); +const credits = new db.table('credits'); +module.exports = async (interaction) => { + const { client } = interaction; + const all = credits.all(); + const allSorted = all.sort((a, b) => (a.data > b.data ? -1 : 1)); + + const topTen = allSorted.slice(0, 10); + + const topTens = []; + + Promise.all( + topTen.map(async (x, i) => { + user = await client.users.fetch(`${x.ID}`, { force: true }); + topTens.push({ index: i, user: user, credits: x.data }); + }) + ).then(async () => { + const embed = { + title: 'Balance Top', + description: `Below are the top ten.\n + ${topTens + .map( + (x) => + `**Top ${x.index + 1}** - ${x.user}: ${ + x.credits <= 1 ? `${x.credits} credit` : `${x.credits} credits` + }` + ) + .join('\n')}`, + color: 0x22bb33, + timestamp: new Date(), + footer: { text: 'Zyner Bot' }, + }; + return await interaction.editReply({ embeds: [embed], ephemeral: true }); + }); +}; diff --git a/src/commands/credits/index.js b/src/commands/credits/index.js new file mode 100644 index 0000000..5ca3c2f --- /dev/null +++ b/src/commands/credits/index.js @@ -0,0 +1,89 @@ +const { SlashCommandBuilder } = require('@discordjs/builders'); +const { MessageEmbed, Permissions } = require('discord.js'); + +module.exports = { + permissions: new Permissions([ + Permissions.FLAGS.MANAGE_MESSAGES, + Permissions.FLAGS.ADMINISTRATOR, + ]), + guildOnly: true, + botAdminOnly: false, + data: new SlashCommandBuilder() + .setName('credits') + .setDescription('Manage your credits.') + .addSubcommand((subcommand) => + subcommand + .setName('give') + .setDescription('Give credits to a user.') + .addUserOption((option) => + option.setName('user').setDescription('The user you want to pay.').setRequired(true) + ) + .addIntegerOption((option) => + option.setName('amount').setDescription('The amount you will pay.').setRequired(true) + ) + ) + .addSubcommand((subcommand) => + subcommand + .setName('take') + .setDescription('Take credits from a user.') + .addUserOption((option) => + option + .setName('user') + .setDescription('The user you want to take credits from.') + .setRequired(true) + ) + .addIntegerOption((option) => + option.setName('amount').setDescription('The amount you will take.').setRequired(true) + ) + ) + .addSubcommand((subcommand) => + subcommand + .setName('balance') + .setDescription("Check a user's balance.") + .addUserOption((option) => + option + .setName('user') + .setDescription('The user whose balance you want to check.') + .setRequired(false) + ) + ) + .addSubcommand((subcommand) => + subcommand + .setName('redeem') + .setDescription('Redeem your credits.') + .addIntegerOption((option) => + option.setName('amount').setDescription('How much credit you want to withdraw.') + ) + ) + .addSubcommand((subcommand) => + subcommand + .setName('gift') + .setDescription('Gift someone credits from your credits.') + .addUserOption((option) => + option.setName('user').setDescription('The user you want to pay.').setRequired(true) + ) + .addIntegerOption((option) => + option.setName('amount').setDescription('The amount you will pay.').setRequired(true) + ) + ) + .addSubcommand((subcommand) => + subcommand.setName('top').setDescription('Check the top balance.') + ), + async execute(interaction) { + await interaction.deferReply({ ephemeral: true }); + + if (interaction.options.getSubcommand() === 'balance') { + require('./addons/balance.js')(interaction); + } else if (interaction.options.getSubcommand() === 'gift') { + require('./addons/gift.js')(interaction); + } else if (interaction.options.getSubcommand() === 'give') { + require('./addons/give.js')(interaction); + } else if (interaction.options.getSubcommand() === 'redeem') { + require('./addons/redeem.js')(interaction); + } else if (interaction.options.getSubcommand() === 'take') { + require('./addons/take.js')(interaction); + } else if (interaction.options.getSubcommand() === 'top') { + require('./addons/top.js')(interaction); + } + }, +}; diff --git a/handlers/api.js b/src/handlers/api.js similarity index 75% rename from handlers/api.js rename to src/handlers/api.js index 998365d..cb56760 100644 --- a/handlers/api.js +++ b/src/handlers/api.js @@ -1,5 +1,5 @@ const axios = require('axios'); -const { api } = require('../config.json'); +const { api } = require('../../config.json'); module.exports = axios.create({ baseURL: api.url, diff --git a/index.js b/src/index.js similarity index 87% rename from index.js rename to src/index.js index 68d862c..187c429 100644 --- a/index.js +++ b/src/index.js @@ -1,6 +1,6 @@ const fs = require('node:fs'); const { Client, Collection, Intents } = require('discord.js'); -const { token } = require('./config.json'); +require('dotenv').config(); const db = require('quick.db'); @@ -9,7 +9,7 @@ const credits = new db.table('credits'); const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] }); client.commands = new Collection(); -const commandFiles = fs.readdirSync('./commands').filter((file) => file.endsWith('.js')); +const commandFiles = fs.readdirSync('./src/commands'); for (const file of commandFiles) { const command = require(`./commands/${file}`); @@ -46,4 +46,4 @@ client.on('messageCreate', async (message) => { console.log(message.author, message.content); }); -client.login(token); +client.login(process.env.BOT_TOKEN);