🎨 Version v.1.1.0
This commit is contained in:
parent
4fa241ad84
commit
1d680346f6
16 changed files with 394 additions and 387 deletions
|
@ -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 });
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
|
@ -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 });
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
|
@ -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 });
|
||||
}
|
||||
},
|
||||
};
|
|
@ -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 });
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
|
@ -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 });
|
||||
}
|
||||
},
|
||||
};
|
|
@ -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);
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
|
28
src/commands/credits/addons/balance.js
Normal file
28
src/commands/credits/addons/balance.js
Normal file
|
@ -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 });
|
||||
}
|
||||
};
|
54
src/commands/credits/addons/gift.js
Normal file
54
src/commands/credits/addons/gift.js
Normal file
|
@ -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 });
|
||||
}
|
||||
}
|
||||
};
|
38
src/commands/credits/addons/give.js
Normal file
38
src/commands/credits/addons/give.js
Normal file
|
@ -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 });
|
||||
}
|
||||
};
|
94
src/commands/credits/addons/redeem.js
Normal file
94
src/commands/credits/addons/redeem.js
Normal file
|
@ -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 });
|
||||
});
|
||||
}
|
||||
};
|
41
src/commands/credits/addons/take.js
Normal file
41
src/commands/credits/addons/take.js
Normal file
|
@ -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 });
|
||||
}
|
||||
};
|
35
src/commands/credits/addons/top.js
Normal file
35
src/commands/credits/addons/top.js
Normal file
|
@ -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 });
|
||||
});
|
||||
};
|
89
src/commands/credits/index.js
Normal file
89
src/commands/credits/index.js
Normal file
|
@ -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);
|
||||
}
|
||||
},
|
||||
};
|
|
@ -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,
|
|
@ -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);
|
Loading…
Add table
Reference in a new issue