🎨 formatted files
This commit is contained in:
parent
8a48c44a80
commit
8f081f3863
20 changed files with 433 additions and 339 deletions
|
@ -1,7 +1,6 @@
|
|||
{
|
||||
"trailingComma": "es5",
|
||||
"tabWidth": 2,
|
||||
"printWidth": 100,
|
||||
"semi": true,
|
||||
"singleQuote": true
|
||||
}
|
||||
|
|
|
@ -4,17 +4,6 @@
|
|||
"clientId": "required",
|
||||
"guildId": "required"
|
||||
},
|
||||
"credits": {
|
||||
"url": "scheme://domain/api/",
|
||||
"token": "required",
|
||||
"timeout": "5000",
|
||||
"rate": "1",
|
||||
"minimumLength": "5",
|
||||
"excludedChannels": [
|
||||
"channel_id",
|
||||
"channel_id"
|
||||
]
|
||||
},
|
||||
"colors": {
|
||||
"success": "0x22bb33",
|
||||
"error": "0xbb2124",
|
||||
|
|
0
log.json
0
log.json
|
@ -45,14 +45,18 @@ module.exports = async (interaction) => {
|
|||
|
||||
// Get toUser object
|
||||
|
||||
const toUser = await credits.findOne({ userId: user.id, guildId: interaction.member.guild.id });
|
||||
const toUser = await credits.findOne({
|
||||
userId: user.id,
|
||||
guildId: interaction.member.guild.id,
|
||||
});
|
||||
|
||||
// Stop if user has zero or below credits
|
||||
|
||||
if (!toUser) {
|
||||
const embed = {
|
||||
title: 'Give',
|
||||
description: 'That user has no credits, I can not give credits to the user',
|
||||
description:
|
||||
'That user has no credits, I can not give credits to the user',
|
||||
color: config.colors.error,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
|
@ -86,7 +90,9 @@ module.exports = async (interaction) => {
|
|||
// Send debug message
|
||||
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} gave ${user.id} ${creditNoun(amount)}.`
|
||||
`Guild: ${member.guild.id} User: ${member.id} gave ${
|
||||
user.id
|
||||
} ${creditNoun(amount)}.`
|
||||
);
|
||||
});
|
||||
};
|
||||
|
|
|
@ -45,14 +45,18 @@ module.exports = async (interaction) => {
|
|||
|
||||
// Get toUser object
|
||||
|
||||
const toUser = await credits.findOne({ userId: user.id, guildId: interaction.member.guild.id });
|
||||
const toUser = await credits.findOne({
|
||||
userId: user.id,
|
||||
guildId: interaction.member.guild.id,
|
||||
});
|
||||
|
||||
// Stop if user has zero or below credits
|
||||
|
||||
if (!toUser) {
|
||||
const embed = {
|
||||
title: 'Set',
|
||||
description: 'That user has no credits, I can not set credits to the user',
|
||||
description:
|
||||
'That user has no credits, I can not set credits to the user',
|
||||
color: config.colors.error,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
|
@ -86,7 +90,9 @@ module.exports = async (interaction) => {
|
|||
// Send debug message
|
||||
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} set ${user.id} to ${creditNoun(amount)}.`
|
||||
`Guild: ${member.guild.id} User: ${member.id} set ${
|
||||
user.id
|
||||
} to ${creditNoun(amount)}.`
|
||||
);
|
||||
});
|
||||
};
|
||||
|
|
|
@ -45,14 +45,18 @@ module.exports = async (interaction) => {
|
|||
|
||||
// Get toUser object
|
||||
|
||||
const toUser = await credits.findOne({ userId: user.id, guildId: interaction.member.guild.id });
|
||||
const toUser = await credits.findOne({
|
||||
userId: user.id,
|
||||
guildId: interaction.member.guild.id,
|
||||
});
|
||||
|
||||
// Stop if user has zero or below credits
|
||||
|
||||
if (!toUser) {
|
||||
const embed = {
|
||||
title: 'Take',
|
||||
description: 'That user has no credits, I can not take credits from the user',
|
||||
description:
|
||||
'That user has no credits, I can not take credits from the user',
|
||||
color: config.colors.error,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
|
@ -86,7 +90,9 @@ module.exports = async (interaction) => {
|
|||
// Send debug message
|
||||
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} took ${creditNoun(amount)} from ${user.id}.`
|
||||
`Guild: ${member.guild.id} User: ${member.id} took ${creditNoun(
|
||||
amount
|
||||
)} from ${user.id}.`
|
||||
);
|
||||
});
|
||||
};
|
||||
|
|
|
@ -34,18 +34,25 @@ module.exports = async (interaction) => {
|
|||
|
||||
// Get fromUser object
|
||||
|
||||
const fromUser = await credits.findOne({ userId: from.id, guildId: interaction.member.guild.id });
|
||||
const fromUser = await credits.findOne({
|
||||
userId: from.id,
|
||||
guildId: interaction.member.guild.id,
|
||||
});
|
||||
|
||||
// Get toUser object
|
||||
|
||||
const toUser = await credits.findOne({ userId: to.id, guildId: interaction.member.guild.id });
|
||||
const toUser = await credits.findOne({
|
||||
userId: to.id,
|
||||
guildId: interaction.member.guild.id,
|
||||
});
|
||||
|
||||
// Stop if fromUser has zero credits or below
|
||||
|
||||
if (!fromUser) {
|
||||
const embed = {
|
||||
title: 'Transfer',
|
||||
description: 'That user has no credits, I can not transfer credits from the user',
|
||||
description:
|
||||
'That user has no credits, I can not transfer credits from the user',
|
||||
color: config.colors.error,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
|
@ -58,7 +65,8 @@ module.exports = async (interaction) => {
|
|||
if (!toUser) {
|
||||
const embed = {
|
||||
title: 'Transfer',
|
||||
description: 'That user has no credits, I can not transfer credits to the user',
|
||||
description:
|
||||
'That user has no credits, I can not transfer credits to the user',
|
||||
color: config.colors.error,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
|
@ -115,9 +123,9 @@ module.exports = async (interaction) => {
|
|||
// Send debug message
|
||||
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} transferred ${creditNoun(amount)} from ${
|
||||
from.id
|
||||
} to ${to.id}.`
|
||||
`Guild: ${member.guild.id} User: ${member.id} transferred ${creditNoun(
|
||||
amount
|
||||
)} from ${from.id} to ${to.id}.`
|
||||
);
|
||||
});
|
||||
};
|
||||
|
|
|
@ -16,10 +16,16 @@ module.exports = {
|
|||
.setName('give')
|
||||
.setDescription('Give credits to a user')
|
||||
.addUserOption((option) =>
|
||||
option.setName('user').setDescription('The user you want to pay.').setRequired(true)
|
||||
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)
|
||||
option
|
||||
.setName('amount')
|
||||
.setDescription('The amount you will pay.')
|
||||
.setRequired(true)
|
||||
)
|
||||
)
|
||||
.addSubcommand((command) =>
|
||||
|
@ -33,7 +39,10 @@ module.exports = {
|
|||
.setRequired(true)
|
||||
)
|
||||
.addIntegerOption((option) =>
|
||||
option.setName('amount').setDescription('The amount you will set.').setRequired(true)
|
||||
option
|
||||
.setName('amount')
|
||||
.setDescription('The amount you will set.')
|
||||
.setRequired(true)
|
||||
)
|
||||
)
|
||||
.addSubcommand((command) =>
|
||||
|
@ -47,7 +56,10 @@ module.exports = {
|
|||
.setRequired(true)
|
||||
)
|
||||
.addIntegerOption((option) =>
|
||||
option.setName('amount').setDescription('The amount you will take.').setRequired(true)
|
||||
option
|
||||
.setName('amount')
|
||||
.setDescription('The amount you will take.')
|
||||
.setRequired(true)
|
||||
)
|
||||
)
|
||||
.addSubcommand((command) =>
|
||||
|
|
|
@ -30,7 +30,9 @@ module.exports = async (interaction) => {
|
|||
|
||||
const embed = {
|
||||
title: 'Balance',
|
||||
description: `${user ? `${user} has` : 'You have'} ${creditNoun(balance)}.`,
|
||||
description: `${user ? `${user} has` : 'You have'} ${creditNoun(
|
||||
balance
|
||||
)}.`,
|
||||
color: config.colors.success,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
|
|
|
@ -52,12 +52,16 @@ module.exports = async (interaction) => {
|
|||
userId: interaction.user.id,
|
||||
guildId: interaction.member.guild.id,
|
||||
});
|
||||
const toUser = await credits.findOne({ userId: user.id, guildId: interaction.member.guild.id });
|
||||
const toUser = await credits.findOne({
|
||||
userId: user.id,
|
||||
guildId: interaction.member.guild.id,
|
||||
});
|
||||
|
||||
if (!toUser) {
|
||||
const embed = {
|
||||
title: 'Gift',
|
||||
description: 'That user has no credits, I can not gift credits to the user',
|
||||
description:
|
||||
'That user has no credits, I can not gift credits to the user',
|
||||
color: config.colors.error,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
|
@ -80,7 +84,9 @@ module.exports = async (interaction) => {
|
|||
};
|
||||
const dmEmbed = {
|
||||
title: 'Gift',
|
||||
description: `You received ${creditNoun(amount)} from ${interaction.user}${
|
||||
description: `You received ${creditNoun(amount)} from ${
|
||||
interaction.user
|
||||
}${
|
||||
reason ? ` with reason: ${reason}` : ''
|
||||
}. Your new balance is ${creditNoun(toUser.balance)}.`,
|
||||
color: 0x22bb33,
|
||||
|
@ -89,8 +95,13 @@ module.exports = async (interaction) => {
|
|||
};
|
||||
const dmUser = await interaction.client.users.cache.get(user.id);
|
||||
await dmUser.send({ embeds: [dmEmbed] });
|
||||
await logger.debug(`Gift sent from: ${interaction.user.username} to: ${user.username}`);
|
||||
return await interaction.editReply({ embeds: [interactionEmbed], ephemeral: true });
|
||||
await logger.debug(
|
||||
`Gift sent from: ${interaction.user.username} to: ${user.username}`
|
||||
);
|
||||
return await interaction.editReply({
|
||||
embeds: [interactionEmbed],
|
||||
ephemeral: true,
|
||||
});
|
||||
} catch (e) {
|
||||
await logger.error(e);
|
||||
}
|
||||
|
|
|
@ -27,7 +27,9 @@ module.exports = async (interaction) => {
|
|||
userId: interaction.user.id,
|
||||
guildId: interaction.member.guild.id,
|
||||
});
|
||||
const dmUser = interaction.client.users.cache.get(interaction.member.user.id);
|
||||
const dmUser = interaction.client.users.cache.get(
|
||||
interaction.member.user.id
|
||||
);
|
||||
|
||||
if ((amount || user.balance) < 100) {
|
||||
const embed = {
|
||||
|
@ -61,7 +63,9 @@ module.exports = async (interaction) => {
|
|||
}
|
||||
const code = uuidv4();
|
||||
|
||||
const apiCredentials = await apis.findOne({ guildId: interaction.member.guild.id });
|
||||
const apiCredentials = await apis.findOne({
|
||||
guildId: interaction.member.guild.id,
|
||||
});
|
||||
|
||||
const api = axios.create({
|
||||
baseURL: apiCredentials.url,
|
||||
|
@ -78,7 +82,9 @@ module.exports = async (interaction) => {
|
|||
.then(async () => {
|
||||
const dmEmbed = {
|
||||
title: 'Redeem',
|
||||
description: `Your new balance is ${user.balance - (amount || user.balance)}.`,
|
||||
description: `Your new balance is ${
|
||||
user.balance - (amount || user.balance)
|
||||
}.`,
|
||||
fields: [
|
||||
{ name: 'Code', value: `${code}`, inline: true },
|
||||
{
|
||||
|
@ -102,9 +108,14 @@ module.exports = async (interaction) => {
|
|||
|
||||
await user.save();
|
||||
|
||||
await logger.debug(`User: ${user.username} redeemed: ${creditNoun(amount)}`);
|
||||
await logger.debug(
|
||||
`User: ${user.username} redeemed: ${creditNoun(amount)}`
|
||||
);
|
||||
await dmUser.send({ embeds: [dmEmbed] });
|
||||
await interaction.editReply({ embeds: [interactionEmbed], ephemeral: true });
|
||||
await interaction.editReply({
|
||||
embeds: [interactionEmbed],
|
||||
ephemeral: true,
|
||||
});
|
||||
})
|
||||
.catch(async (e) => {
|
||||
await logger.error(e);
|
||||
|
|
|
@ -3,18 +3,25 @@ const credits = require('../../../helpers/database/models/creditSchema');
|
|||
const creditNoun = require('../../../helpers/creditNoun');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
await credits.find({ guildId: interaction.member.guild.id }).then(async (data) => {
|
||||
const topTen = data.sort((a, b) => (a.balance > b.balance ? -1 : 1)).slice(0, 10);
|
||||
await credits
|
||||
.find({ guildId: interaction.member.guild.id })
|
||||
.then(async (data) => {
|
||||
const topTen = data
|
||||
.sort((a, b) => (a.balance > b.balance ? -1 : 1))
|
||||
.slice(0, 10);
|
||||
|
||||
const item = (x, index) => `**Top ${index + 1}** - <@${x.userId}> ${creditNoun(x.balance)}`;
|
||||
const item = (x, index) =>
|
||||
`**Top ${index + 1}** - <@${x.userId}> ${creditNoun(x.balance)}`;
|
||||
|
||||
const embed = {
|
||||
title: 'Balance Top',
|
||||
description: `Below are the top ten.\n${topTen.map((x, index) => item(x, index)).join('\n')}`,
|
||||
color: 0x22bb33,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
});
|
||||
const embed = {
|
||||
title: 'Balance Top',
|
||||
description: `Below are the top ten.\n${topTen
|
||||
.map((x, index) => item(x, index))
|
||||
.join('\n')}`,
|
||||
color: 0x22bb33,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
});
|
||||
};
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
const config = require('../../../../config.json');
|
||||
const logger = require('../../../handlers/logger');
|
||||
const { guilds, credits, timeouts } = require('../../../helpers/database/models');
|
||||
const {
|
||||
guilds,
|
||||
credits,
|
||||
timeouts,
|
||||
} = require('../../../helpers/database/models');
|
||||
const creditNoun = require('../../../helpers/creditNoun');
|
||||
|
||||
const workedRecently = new Set();
|
||||
|
@ -20,7 +24,9 @@ module.exports = async (interaction) => {
|
|||
// If user is not on timeout
|
||||
|
||||
if (!isTimeout) {
|
||||
const guild = await guilds.findOne({ guildId: interaction.member.guild.id });
|
||||
const guild = await guilds.findOne({
|
||||
guildId: interaction.member.guild.id,
|
||||
});
|
||||
|
||||
const creditsEarned = Math.floor(Math.random() * guild.credits.workRate);
|
||||
await credits
|
||||
|
@ -55,7 +61,9 @@ module.exports = async (interaction) => {
|
|||
|
||||
setTimeout(async () => {
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} has not worked within the last ${
|
||||
`Guild: ${member.guild.id} User: ${
|
||||
member.id
|
||||
} has not worked within the last ${
|
||||
guild.work.timeout / 1000
|
||||
} seconds, work can be done`
|
||||
);
|
||||
|
|
|
@ -30,7 +30,9 @@ module.exports = {
|
|||
.setName('redeem')
|
||||
.setDescription('Redeem your credits.')
|
||||
.addIntegerOption((option) =>
|
||||
option.setName('amount').setDescription('How much credit you want to withdraw.')
|
||||
option
|
||||
.setName('amount')
|
||||
.setDescription('How much credit you want to withdraw.')
|
||||
)
|
||||
)
|
||||
.addSubcommand((subcommand) =>
|
||||
|
@ -38,21 +40,36 @@ module.exports = {
|
|||
.setName('gift')
|
||||
.setDescription('Gift someone credits from your credits.')
|
||||
.addUserOption((option) =>
|
||||
option.setName('user').setDescription('The user you want to pay.').setRequired(true)
|
||||
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)
|
||||
option
|
||||
.setName('amount')
|
||||
.setDescription('The amount you will pay.')
|
||||
.setRequired(true)
|
||||
)
|
||||
.addStringOption((option) =>
|
||||
option.setName('reason').setDescription('Your reason.')
|
||||
)
|
||||
.addStringOption((option) => option.setName('reason').setDescription('Your reason.'))
|
||||
)
|
||||
.addSubcommand((subcommand) =>
|
||||
subcommand.setName('top').setDescription('Check the top balance.')
|
||||
)
|
||||
.addSubcommand((subcommand) => subcommand.setName('work').setDescription('Work for credits.')),
|
||||
.addSubcommand((subcommand) =>
|
||||
subcommand.setName('work').setDescription('Work for credits.')
|
||||
),
|
||||
async execute(interaction) {
|
||||
const guild = await guilds.findOne({ guildId: interaction.member.guild.id });
|
||||
const guild = await guilds.findOne({
|
||||
guildId: interaction.member.guild.id,
|
||||
});
|
||||
|
||||
if (guild.credits.status === false && interaction.options.getSubcommand() !== 'settings') {
|
||||
if (
|
||||
guild.credits.status === false &&
|
||||
interaction.options.getSubcommand() !== 'settings'
|
||||
) {
|
||||
const embed = {
|
||||
title: 'Credits',
|
||||
description: 'Please enable credits by ``/credits settings``',
|
||||
|
|
27
src/helpers/database/models/profileSchema.js
Normal file
27
src/helpers/database/models/profileSchema.js
Normal file
|
@ -0,0 +1,27 @@
|
|||
const mongoose = require('mongoose');
|
||||
|
||||
const profileSchema = new mongoose.Schema(
|
||||
{
|
||||
userId: {
|
||||
type: mongoose.SchemaTypes.Decimal128,
|
||||
required: true,
|
||||
unique: false,
|
||||
index: true,
|
||||
},
|
||||
url: {
|
||||
type: mongoose.SchemaTypes.String,
|
||||
required: true,
|
||||
unique: false,
|
||||
index: true,
|
||||
},
|
||||
token: {
|
||||
type: mongoose.SchemaTypes.String,
|
||||
required: true,
|
||||
unique: false,
|
||||
index: true,
|
||||
},
|
||||
},
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
module.exports = mongoose.model('profile', profileSchema);
|
33
src/index.js
33
src/index.js
|
@ -1,16 +1,19 @@
|
|||
/* eslint-disable no-restricted-syntax */
|
||||
const fs = require('fs');
|
||||
const { Client, Collection, Intents } = require('discord.js');
|
||||
|
||||
require('./deploy-commands')();
|
||||
require('./helpers/database')();
|
||||
require('./handlers/locale')();
|
||||
|
||||
const fs = require('fs');
|
||||
const { Client, Collection, Intents } = require('discord.js');
|
||||
|
||||
const config = require('../config.json');
|
||||
|
||||
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
|
||||
const client = new Client({
|
||||
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES],
|
||||
});
|
||||
|
||||
const eventFiles = fs.readdirSync('./src/events').filter((file) => file.endsWith('.js'));
|
||||
const eventFiles = fs
|
||||
.readdirSync('./src/events')
|
||||
.filter((file) => file.endsWith('.js'));
|
||||
|
||||
client.commands = new Collection();
|
||||
const commandFiles = fs.readdirSync('./src/commands');
|
||||
|
@ -21,24 +24,6 @@ for (const file of commandFiles) {
|
|||
client.commands.set(command.data.name, command);
|
||||
}
|
||||
|
||||
// client.buttons = new Collection();
|
||||
// const buttonFiles = fs.readdirSync('./src/buttons');
|
||||
|
||||
// for (const file of buttonFiles) {
|
||||
// // eslint-disable-next-line import/no-dynamic-require, global-require
|
||||
// const button = require(`./buttons/${file}`);
|
||||
// client.buttons.set(button.customId, button);
|
||||
// }
|
||||
|
||||
// client.menus = new Collection();
|
||||
// const menuFiles = fs.readdirSync('./src/menus');
|
||||
|
||||
// for (const file of menuFiles) {
|
||||
// // eslint-disable-next-line import/no-dynamic-require, global-require
|
||||
// const menu = require(`./menus/${file}`);
|
||||
// client.menus.set(menu.customId, menu);
|
||||
// }
|
||||
|
||||
for (const file of eventFiles) {
|
||||
// eslint-disable-next-line import/no-dynamic-require, global-require
|
||||
const event = require(`./events/${file}`);
|
||||
|
|
Loading…
Add table
Reference in a new issue