🎨 Fix eslint enforce
This commit is contained in:
parent
6a9d9d1be2
commit
02ad79ab69
24 changed files with 407 additions and 432 deletions
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
|
@ -45,5 +45,6 @@
|
|||
"titleBar.activeForeground": "#e7e7e7",
|
||||
"titleBar.inactiveBackground": "#33669999",
|
||||
"titleBar.inactiveForeground": "#e7e7e799"
|
||||
}
|
||||
},
|
||||
"cSpell.words": ["discordjs", "pino", "upsert", "uuidv"]
|
||||
}
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
const logger = require(`${__basedir}/handlers/logger`);
|
||||
|
||||
module.exports = async () => {
|
||||
const fs = require('node:fs');
|
||||
const { REST } = require('@discordjs/rest');
|
||||
const { Routes } = require('discord-api-types/v9');
|
||||
|
||||
const commands = [];
|
||||
const commandFiles = fs.readdirSync(`${__basedir}/commands`);
|
||||
|
||||
for (const file of commandFiles) {
|
||||
const command = require(`${__basedir}/commands/${file}`);
|
||||
commands.push(command.data.toJSON());
|
||||
}
|
||||
|
||||
const rest = new REST({ version: '9' }).setToken(__config.bot.token);
|
||||
|
||||
rest
|
||||
.put(Routes.applicationGuildCommands(__config.bot.clientId, __config.bot.guildId), {
|
||||
body: commands,
|
||||
})
|
||||
.then(async () => await logger.info('Successfully registered application commands.'))
|
||||
.catch(async (err) => {
|
||||
await logger.error(err);
|
||||
});
|
||||
};
|
|
@ -24,6 +24,7 @@
|
|||
"email": "vermium@zyner.org"
|
||||
},
|
||||
"dependencies": {
|
||||
"@discordjs/builders": "^0.12.0",
|
||||
"@discordjs/rest": "^0.3.0",
|
||||
"axios": "^0.26.0",
|
||||
"better-sqlite3": "^7.5.0",
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
const credits = require(`${__basedir}/helpers/database/models/creditSchema`);
|
||||
const logger = require(`${__basedir}/handlers/logger`);
|
||||
const creditNoun = require(`${__basedir}/helpers/creditNoun`);
|
||||
const config = require('../../../../config.json');
|
||||
const logger = require('../../../handlers/logger');
|
||||
|
||||
const credits = require('../../../helpers/database/models/creditSchema');
|
||||
const creditNoun = require('../../../helpers/creditNoun');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
try {
|
||||
|
@ -13,27 +15,26 @@ module.exports = async (interaction) => {
|
|||
const embed = {
|
||||
title: 'Balance',
|
||||
description: `${user} has no credits.`,
|
||||
color: __config.colors.success,
|
||||
color: config.colors.success,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: __config.footer.icon, text: __config.footer.text },
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
} else {
|
||||
const { balance } = data;
|
||||
|
||||
const embed = {
|
||||
title: '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 },
|
||||
};
|
||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
const { balance } = data;
|
||||
|
||||
const embed = {
|
||||
title: '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 },
|
||||
};
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
})
|
||||
.catch(async (err) => logger.error(err));
|
||||
} catch {
|
||||
async (err) => logger.error(err);
|
||||
await logger.error();
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
const credits = require(`${__basedir}/helpers/database/models/creditSchema`);
|
||||
const logger = require(`${__basedir}/handlers/logger`);
|
||||
const saveUser = require(`${__basedir}/helpers/saveUser`);
|
||||
const creditNoun = require(`${__basedir}/helpers/creditNoun`);
|
||||
const config = require('../../../../config.json');
|
||||
const logger = require('../../../handlers/logger');
|
||||
|
||||
const credits = require('../../../helpers/database/models/creditSchema');
|
||||
const saveUser = require('../../../helpers/saveUser');
|
||||
const creditNoun = require('../../../helpers/creditNoun');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
try {
|
||||
|
@ -15,51 +17,51 @@ module.exports = async (interaction) => {
|
|||
description: "You can't pay yourself.",
|
||||
color: 0xbb2124,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: __config.footer.icon, text: __config.footer.text },
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
} else if (amount <= 0) {
|
||||
}
|
||||
if (amount <= 0) {
|
||||
const embed = {
|
||||
title: 'Gift failed',
|
||||
description: "You can't pay zero or below.",
|
||||
color: 0xbb2124,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: __config.footer.icon, text: __config.footer.text },
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
} else {
|
||||
if (data.balance < amount) {
|
||||
const embed = {
|
||||
title: 'Gift',
|
||||
description: `You have insufficient credits. Your balance is ${data.balance}`,
|
||||
color: 0xbb2124,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: __config.footer.icon, text: __config.footer.text },
|
||||
};
|
||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
} else {
|
||||
const fromUser = await credits.findOne({ userId: interaction.user.id });
|
||||
const toUser = await credits.findOne({ userId: user.id });
|
||||
|
||||
fromUser.balance -= amount;
|
||||
toUser.balance += amount;
|
||||
|
||||
await saveUser(fromUser, toUser);
|
||||
|
||||
const embed = {
|
||||
title: 'Gift',
|
||||
description: `You sent ${creditNoun(amount)} to ${user}. Your new balance is ${creditNoun(
|
||||
fromUser.balance
|
||||
)}.`,
|
||||
color: 0x22bb33,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: __config.footer.icon, text: __config.footer.text },
|
||||
};
|
||||
await logger.debug(`Gift sent from: ${interaction.user.username} to: ${user.username}`);
|
||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
}
|
||||
if (data.balance < amount) {
|
||||
const embed = {
|
||||
title: 'Gift',
|
||||
description: `You have insufficient credits. Your balance is ${data.balance}`,
|
||||
color: 0xbb2124,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
const fromUser = await credits.findOne({ userId: interaction.user.id });
|
||||
const toUser = await credits.findOne({ userId: user.id });
|
||||
|
||||
fromUser.balance -= amount;
|
||||
toUser.balance += amount;
|
||||
|
||||
await saveUser(fromUser, toUser);
|
||||
|
||||
const embed = {
|
||||
title: 'Gift',
|
||||
description: `You sent ${creditNoun(amount)} to ${user}. Your new balance is ${creditNoun(
|
||||
fromUser.balance,
|
||||
)}.`,
|
||||
color: 0x22bb33,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
await logger.debug(`Gift sent from: ${interaction.user.username} to: ${user.username}`);
|
||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
} catch {
|
||||
async (err) => await logger.error(err);
|
||||
await logger.error();
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
const { Permissions } = require('discord.js');
|
||||
|
||||
const credits = require(`${__basedir}/helpers/database/models/creditSchema`);
|
||||
const logger = require(`${__basedir}/handlers/logger`);
|
||||
const creditNoun = require(`${__basedir}/helpers/creditNoun`);
|
||||
const config = require('../../../../config.json');
|
||||
const logger = require('../../../handlers/logger');
|
||||
|
||||
const credits = require('../../../helpers/database/models/creditSchema');
|
||||
const creditNoun = require('../../../helpers/creditNoun');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
try {
|
||||
|
@ -22,28 +24,28 @@ module.exports = async (interaction) => {
|
|||
description: "You can't give zero or below.",
|
||||
color: 0xbb2124,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: __config.footer.icon, text: __config.footer.text },
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
} else {
|
||||
const toUser = await credits.findOne({ userId: user.id });
|
||||
toUser.balance += amount;
|
||||
await toUser.save();
|
||||
const embed = {
|
||||
title: 'Give',
|
||||
description: `Gave ${creditNoun(amount)} to ${user}.`,
|
||||
color: 0x22bb33,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: __config.footer.icon, text: __config.footer.text },
|
||||
};
|
||||
await logger.debug(
|
||||
`Administrator: ${interaction.user.username} gave ${
|
||||
amount <= 1 ? `${amount} credit` : `${amount} credits`
|
||||
} to ${user.username}`
|
||||
);
|
||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
const toUser = await credits.findOne({ userId: user.id });
|
||||
toUser.balance += amount;
|
||||
await toUser.save();
|
||||
const embed = {
|
||||
title: 'Give',
|
||||
description: `Gave ${creditNoun(amount)} to ${user}.`,
|
||||
color: 0x22bb33,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
await logger.debug(
|
||||
`Administrator: ${interaction.user.username} gave ${
|
||||
amount <= 1 ? `${amount} credit` : `${amount} credits`
|
||||
} to ${user.username}`,
|
||||
);
|
||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
} catch {
|
||||
async (err) => await logger.error(err);
|
||||
await logger.error();
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
|
|
@ -1,19 +1,21 @@
|
|||
const credits = require(`${__basedir}/helpers/database/models/creditSchema`);
|
||||
const logger = require(`${__basedir}/handlers/logger`);
|
||||
const creditNoun = require(`${__basedir}/helpers/creditNoun`);
|
||||
|
||||
const api = require(`${__basedir}/handlers/api.js`);
|
||||
|
||||
const { v4: uuidv4 } = require('uuid');
|
||||
const config = require('../../../../config.json');
|
||||
const logger = require('../../../handlers/logger');
|
||||
|
||||
const credits = require('../../../helpers/database/models/creditSchema');
|
||||
const creditNoun = require('../../../helpers/creditNoun');
|
||||
|
||||
const api = require('../../../handlers/api');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
try {
|
||||
if (__config.disable.redeem) {
|
||||
if (config.disable.redeem) {
|
||||
const embed = {
|
||||
title: 'Redeem failed',
|
||||
description: `Redeem is disabled until further.`,
|
||||
color: __config.colors.error,
|
||||
description: 'Redeem is disabled until further.',
|
||||
color: config.colors.error,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: __config.footer.icon, text: __config.footer.text },
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
@ -26,83 +28,85 @@ module.exports = async (interaction) => {
|
|||
const embed = {
|
||||
title: 'Redeem',
|
||||
description: `You can't redeem below 100. Your balance is ${user.balance}.`,
|
||||
color: __config.colors.error,
|
||||
color: config.colors.error,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: __config.footer.icon, text: __config.footer.text },
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
} else if ((amount || user.balance) > 1000000) {
|
||||
}
|
||||
if ((amount || user.balance) > 1000000) {
|
||||
const embed = {
|
||||
title: 'Redeem',
|
||||
description: `You can't redeem over 1,000,000. Your balance is ${user.balance}.`,
|
||||
color: __config.colors.error,
|
||||
color: config.colors.error,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: __config.footer.icon, text: __config.footer.text },
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
} else if (user.balance < amount) {
|
||||
}
|
||||
if (user.balance < amount) {
|
||||
const embed = {
|
||||
title: 'Redeem',
|
||||
description: `You have insufficient credits. Your balance is ${user.balance}.`,
|
||||
color: __config.colors.error,
|
||||
color: config.colors.error,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: __config.footer.icon, text: __config.footer.text },
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
} else {
|
||||
const code = await uuidv4();
|
||||
|
||||
await api
|
||||
.post('vouchers', {
|
||||
uses: 1,
|
||||
code,
|
||||
credits: amount || user.balance,
|
||||
memo: `${interaction.createdTimestamp} - ${interaction.user.id}`,
|
||||
})
|
||||
.then(async (res) => {
|
||||
const dmEmbed = {
|
||||
title: 'Redeem',
|
||||
description: `Your new balance is ${user.balance - (amount || user.balance)}.`,
|
||||
fields: [
|
||||
{ name: 'Code', value: `${code}`, inline: true },
|
||||
{
|
||||
name: 'Credits',
|
||||
value: `${amount || user.balance}`,
|
||||
inline: true,
|
||||
},
|
||||
],
|
||||
color: __config.colors.success,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: __config.footer.icon, text: __config.footer.text },
|
||||
};
|
||||
const interactionEmbed = {
|
||||
title: 'Redeem',
|
||||
description: `Code is sent in DM!`,
|
||||
color: __config.colors.success,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: __config.footer.icon, text: __config.footer.text },
|
||||
};
|
||||
user.balance -= amount || user.balance;
|
||||
|
||||
await user.save();
|
||||
|
||||
await logger.debug(`User: ${user.username} redeemed: ${creditNoun(amount)}`);
|
||||
await dmUser.send({ embeds: [dmEmbed] });
|
||||
await interaction.editReply({ embeds: [interactionEmbed], ephemeral: true });
|
||||
})
|
||||
.catch(async (err) => {
|
||||
await logger.error(err);
|
||||
const embed = {
|
||||
title: 'Redeem',
|
||||
description: 'Something went wrong.',
|
||||
color: __config.colors.error,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: __config.footer.icon, text: __config.footer.text },
|
||||
};
|
||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
});
|
||||
}
|
||||
const code = uuidv4();
|
||||
|
||||
await api
|
||||
.post('vouchers', {
|
||||
uses: 1,
|
||||
code,
|
||||
credits: amount || user.balance,
|
||||
memo: `${interaction.createdTimestamp} - ${interaction.user.id}`,
|
||||
})
|
||||
.then(async () => {
|
||||
const dmEmbed = {
|
||||
title: 'Redeem',
|
||||
description: `Your new balance is ${user.balance - (amount || user.balance)}.`,
|
||||
fields: [
|
||||
{ name: 'Code', value: `${code}`, inline: true },
|
||||
{
|
||||
name: 'Credits',
|
||||
value: `${amount || user.balance}`,
|
||||
inline: true,
|
||||
},
|
||||
],
|
||||
color: config.colors.success,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
const interactionEmbed = {
|
||||
title: 'Redeem',
|
||||
description: 'Code is sent in DM!',
|
||||
color: config.colors.success,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
user.balance -= amount || user.balance;
|
||||
|
||||
await user.save();
|
||||
|
||||
await logger.debug(`User: ${user.username} redeemed: ${creditNoun(amount)}`);
|
||||
await dmUser.send({ embeds: [dmEmbed] });
|
||||
await interaction.editReply({ embeds: [interactionEmbed], ephemeral: true });
|
||||
})
|
||||
.catch(async (err) => {
|
||||
await logger.error(err);
|
||||
const embed = {
|
||||
title: 'Redeem',
|
||||
description: 'Something went wrong.',
|
||||
color: config.colors.error,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
});
|
||||
} catch {
|
||||
async (err) => await logger.error(err);
|
||||
await logger.error();
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
const { Permissions } = require('discord.js');
|
||||
|
||||
const credits = require(`${__basedir}/helpers/database/models/creditSchema`);
|
||||
const logger = require(`${__basedir}/handlers/logger`);
|
||||
const creditNoun = require(`${__basedir}/helpers/creditNoun`);
|
||||
const config = require('../../../../config.json');
|
||||
const logger = require('../../../handlers/logger');
|
||||
|
||||
const credits = require('../../../helpers/database/models/creditSchema');
|
||||
const creditNoun = require('../../../helpers/creditNoun');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
if (!interaction.member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
|
@ -11,9 +13,9 @@ module.exports = async (interaction) => {
|
|||
description: 'You need to have permission to manage this guild (MANAGE_GUILD)',
|
||||
color: 0xbb2124,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: __config.footer.icon, text: __config.footer.text },
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
const user = await interaction.options.getUser('user');
|
||||
const amount = await interaction.options.getInteger('amount');
|
||||
|
@ -27,12 +29,12 @@ module.exports = async (interaction) => {
|
|||
description: `You set ${creditNoun(amount)} on ${user}.`,
|
||||
color: 0x22bb33,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: __config.footer.icon, text: __config.footer.text },
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
await logger.debug(
|
||||
`Administrator: ${interaction.user.username} set ${
|
||||
amount <= 1 ? `${amount} credit` : `${amount} credits`
|
||||
} on ${user.username}`
|
||||
} on ${user.username}`,
|
||||
);
|
||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
};
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
const { Permissions } = require('discord.js');
|
||||
const config = require('../../../../config.json');
|
||||
|
||||
const credits = require(`${__basedir}/helpers/database/models/creditSchema`);
|
||||
const logger = require(`${__basedir}/handlers/logger`);
|
||||
const creditNoun = require(`${__basedir}/helpers/creditNoun`);
|
||||
const credits = require('../../../helpers/database/models/creditSchema');
|
||||
const logger = require('../../../handlers/logger');
|
||||
const creditNoun = require('../../../helpers/creditNoun');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
if (!interaction.member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
|
@ -11,9 +12,9 @@ module.exports = async (interaction) => {
|
|||
description: 'You need to have permission to manage this guild (MANAGE_GUILD)',
|
||||
color: 0xbb2124,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: __config.footer.icon, text: __config.footer.text },
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
const user = await interaction.options.getUser('user');
|
||||
const amount = await interaction.options.getInteger('amount');
|
||||
|
@ -24,9 +25,9 @@ module.exports = async (interaction) => {
|
|||
description: "You can't take zero or below.",
|
||||
color: 0xbb2124,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: __config.footer.icon, text: __config.footer.text },
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
const toUser = await credits.findOne({ userId: user.id });
|
||||
toUser.balance -= amount;
|
||||
|
@ -37,12 +38,12 @@ module.exports = async (interaction) => {
|
|||
description: `You took ${creditNoun(amount)} to ${user}.`,
|
||||
color: 0x22bb33,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: __config.footer.icon, text: __config.footer.text },
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
await logger.debug(
|
||||
`Administrator: ${interaction.user.username} took ${
|
||||
amount <= 1 ? `${amount} credit` : `${amount} credits`
|
||||
} from ${user.username}`
|
||||
} from ${user.username}`,
|
||||
);
|
||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
};
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
const credits = require(`${__basedir}/helpers/database/models/creditSchema`);
|
||||
const creditNoun = require(`${__basedir}/helpers/creditNoun`);
|
||||
const config = require('../../../../config.json');
|
||||
const credits = require('../../../helpers/database/models/creditSchema');
|
||||
const creditNoun = require('../../../helpers/creditNoun');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
await credits.find().then(async (data) => {
|
||||
|
@ -12,8 +13,8 @@ module.exports = async (interaction) => {
|
|||
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 },
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
});
|
||||
};
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
const { Permissions } = require('discord.js');
|
||||
|
||||
const credits = require(`${__basedir}/helpers/database/models/creditSchema`);
|
||||
const logger = require(`${__basedir}/handlers/logger`);
|
||||
const saveUser = require(`${__basedir}/helpers/saveUser`);
|
||||
const creditNoun = require(`${__basedir}/helpers/creditNoun`);
|
||||
const config = require('../../../../config.json');
|
||||
const logger = require('../../../handlers/logger');
|
||||
|
||||
const credits = require('../../../helpers/database/models/creditSchema');
|
||||
const saveUser = require('../../../helpers/saveUser');
|
||||
const creditNoun = require('../../../helpers/creditNoun');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
try {
|
||||
|
@ -26,47 +28,44 @@ module.exports = async (interaction) => {
|
|||
description: "You can't transfer zero or below.",
|
||||
color: 0xbb2124,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: __config.footer.icon, text: __config.footer.text },
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
} else {
|
||||
if (data.balance < amount) {
|
||||
const embed = {
|
||||
title: 'Transfer',
|
||||
description: `${from.username} has insufficient credits. ${from.username} balance is ${data.balance}`,
|
||||
color: 0xbb2124,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: __config.footer.icon, text: __config.footer.text },
|
||||
};
|
||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
} else {
|
||||
const fromUser = await credits.findOne({ userId: from.id });
|
||||
const toUser = await credits.findOne({ userId: to.id });
|
||||
|
||||
console.log(fromUser, toUser, amount);
|
||||
|
||||
fromUser.balance -= amount;
|
||||
toUser.balance += amount;
|
||||
|
||||
await saveUser(fromUser, toUser);
|
||||
|
||||
const embed = {
|
||||
title: 'Transfer',
|
||||
description: `You sent ${creditNoun(amount)} from ${from} to ${to}.`,
|
||||
color: 0x22bb33,
|
||||
fields: [
|
||||
{ name: `${from.username} Balance`, value: `${fromUser.balance}`, inline: true },
|
||||
{ name: `${to.username} Balance`, value: `${toUser.balance}`, inline: true },
|
||||
],
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: __config.footer.icon, text: __config.footer.text },
|
||||
};
|
||||
|
||||
await logger.debug(`Gift sent from: ${interaction.user.username} to: ${to.username}`);
|
||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
}
|
||||
if (data.balance < amount) {
|
||||
const embed = {
|
||||
title: 'Transfer',
|
||||
description: `${from.username} has insufficient credits. ${from.username} balance is ${data.balance}`,
|
||||
color: 0xbb2124,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
const fromUser = await credits.findOne({ userId: from.id });
|
||||
const toUser = await credits.findOne({ userId: to.id });
|
||||
|
||||
fromUser.balance -= amount;
|
||||
toUser.balance += amount;
|
||||
|
||||
await saveUser(fromUser, toUser);
|
||||
|
||||
const embed = {
|
||||
title: 'Transfer',
|
||||
description: `You sent ${creditNoun(amount)} from ${from} to ${to}.`,
|
||||
color: 0x22bb33,
|
||||
fields: [
|
||||
{ name: `${from.username} Balance`, value: `${fromUser.balance}`, inline: true },
|
||||
{ name: `${to.username} Balance`, value: `${toUser.balance}`, inline: true },
|
||||
],
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
await logger.debug(`Gift sent from: ${interaction.user.username} to: ${to.username}`);
|
||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
} catch {
|
||||
async (err) => await logger.error(err);
|
||||
await logger.error();
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
const { SlashCommandBuilder } = require('@discordjs/builders');
|
||||
const { MessageEmbed, Permissions } = require('discord.js');
|
||||
const { Permissions } = require('discord.js');
|
||||
|
||||
const balance = require('./addons/balance.js');
|
||||
const gift = require('./addons/gift.js');
|
||||
const give = require('./addons/give.js');
|
||||
const redeem = require('./addons/redeem.js');
|
||||
const take = require('./addons/take.js');
|
||||
const top = require('./addons/top.js');
|
||||
const transfer = require('./addons/transfer.js');
|
||||
const set = require('./addons/set.js');
|
||||
const balance = require('./addons/balance');
|
||||
const gift = require('./addons/gift');
|
||||
const give = require('./addons/give');
|
||||
const redeem = require('./addons/redeem');
|
||||
const take = require('./addons/take');
|
||||
const top = require('./addons/top');
|
||||
const transfer = require('./addons/transfer');
|
||||
const set = require('./addons/set');
|
||||
|
||||
module.exports = {
|
||||
permissions: new Permissions([
|
||||
|
@ -20,121 +20,72 @@ module.exports = {
|
|||
data: new SlashCommandBuilder()
|
||||
.setName('credits')
|
||||
.setDescription('Manage your credits.')
|
||||
.addSubcommand((subcommand) =>
|
||||
subcommand
|
||||
.setName('give')
|
||||
.setDescription('Give credits to a user. (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)
|
||||
)
|
||||
)
|
||||
.addSubcommand((subcommand) =>
|
||||
subcommand
|
||||
.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)
|
||||
)
|
||||
)
|
||||
.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.')
|
||||
)
|
||||
.addSubcommand((subcommand) =>
|
||||
subcommand
|
||||
.setName('transfer')
|
||||
.setDescription('Transfer credits from a user to another user. (ADMIN)')
|
||||
.addUserOption((option) =>
|
||||
option
|
||||
.setName('from')
|
||||
.setDescription('The user you want to take credits from.')
|
||||
.setRequired(true)
|
||||
)
|
||||
.addUserOption((option) =>
|
||||
option
|
||||
.setName('to')
|
||||
.setDescription('The user you want to give credits to.')
|
||||
.setRequired(true)
|
||||
)
|
||||
.addIntegerOption((option) =>
|
||||
option.setName('amount').setDescription('The amount you will transfer.').setRequired(true)
|
||||
)
|
||||
)
|
||||
.addSubcommand((subcommand) =>
|
||||
subcommand
|
||||
.setName('set')
|
||||
.setDescription('Set credits on a user. (ADMIN)')
|
||||
.addUserOption((option) =>
|
||||
option
|
||||
.setName('user')
|
||||
.setDescription('The user you want to set credits on.')
|
||||
.setRequired(true)
|
||||
)
|
||||
.addIntegerOption((option) =>
|
||||
option.setName('amount').setDescription('The amount you will set.').setRequired(true)
|
||||
)
|
||||
),
|
||||
.addSubcommand((subcommand) => subcommand
|
||||
.setName('give')
|
||||
.setDescription('Give credits to a user. (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)))
|
||||
.addSubcommand((subcommand) => subcommand
|
||||
.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)))
|
||||
.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.'))
|
||||
.addSubcommand((subcommand) => subcommand
|
||||
.setName('transfer')
|
||||
.setDescription('Transfer credits from a user to another user. (ADMIN)')
|
||||
.addUserOption((option) => option
|
||||
.setName('from')
|
||||
.setDescription('The user you want to take credits from.')
|
||||
.setRequired(true))
|
||||
.addUserOption((option) => option
|
||||
.setName('to')
|
||||
.setDescription('The user you want to give credits to.')
|
||||
.setRequired(true))
|
||||
.addIntegerOption((option) => option.setName('amount').setDescription('The amount you will transfer.').setRequired(true)))
|
||||
.addSubcommand((subcommand) => subcommand
|
||||
.setName('set')
|
||||
.setDescription('Set credits on a user. (ADMIN)')
|
||||
.addUserOption((option) => option
|
||||
.setName('user')
|
||||
.setDescription('The user you want to set credits on.')
|
||||
.setRequired(true))
|
||||
.addIntegerOption((option) => option.setName('amount').setDescription('The amount you will set.').setRequired(true))),
|
||||
async execute(interaction) {
|
||||
if (interaction.options.getSubcommand() === 'balance') {
|
||||
await balance(interaction);
|
||||
}
|
||||
else if (interaction.options.getSubcommand() === 'gift') {
|
||||
} else if (interaction.options.getSubcommand() === 'gift') {
|
||||
await gift(interaction);
|
||||
}
|
||||
else if (interaction.options.getSubcommand() === 'give') {
|
||||
} else if (interaction.options.getSubcommand() === 'give') {
|
||||
await give(interaction);
|
||||
}
|
||||
else if (interaction.options.getSubcommand() === 'redeem') {
|
||||
} else if (interaction.options.getSubcommand() === 'redeem') {
|
||||
await redeem(interaction);
|
||||
}
|
||||
else if (interaction.options.getSubcommand() === 'take') {
|
||||
} else if (interaction.options.getSubcommand() === 'take') {
|
||||
await take(interaction);
|
||||
}
|
||||
else if (interaction.options.getSubcommand() === 'top') {
|
||||
} else if (interaction.options.getSubcommand() === 'top') {
|
||||
await top(interaction);
|
||||
}
|
||||
else if (interaction.options.getSubcommand() === 'transfer') {
|
||||
} else if (interaction.options.getSubcommand() === 'transfer') {
|
||||
await transfer(interaction);
|
||||
}
|
||||
else if (interaction.options.getSubcommand() === 'set') {
|
||||
} else if (interaction.options.getSubcommand() === 'set') {
|
||||
await set(interaction);
|
||||
}
|
||||
},
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
const logger = require(`${__basedir}/handlers/logger`);
|
||||
|
||||
const axios = require('axios');
|
||||
|
||||
const config = require('../../../../config.json');
|
||||
const logger = require('../../../handlers/logger');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
try {
|
||||
const target = await interaction.options.getString('target');
|
||||
|
@ -13,9 +14,9 @@ module.exports = async (interaction) => {
|
|||
const embed = {
|
||||
title: 'Lookup',
|
||||
description: `${res.data.message}: ${res.data.query}`,
|
||||
color: __config.colors.error,
|
||||
color: config.colors.error,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: __config.footer.icon, text: __config.footer.text },
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
await interaction.editReply({ embeds: [embed] });
|
||||
} else if (res.data.status === 'success') {
|
||||
|
@ -35,9 +36,9 @@ module.exports = async (interaction) => {
|
|||
{ name: 'ISP', value: `${res.data.isp || 'Not available'}` },
|
||||
{ name: 'Organization', value: `${res.data.org || 'Not available'}` },
|
||||
],
|
||||
color: __config.colors.success,
|
||||
color: config.colors.success,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: __config.footer.icon, text: __config.footer.text },
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
await interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
|
@ -46,6 +47,6 @@ module.exports = async (interaction) => {
|
|||
await logger.error(err);
|
||||
});
|
||||
} catch {
|
||||
async (err) => await logger.error(err);
|
||||
await logger.error();
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
const { SlashCommandBuilder } = require('@discordjs/builders');
|
||||
const { MessageEmbed, Permissions } = require('discord.js');
|
||||
const { Permissions } = require('discord.js');
|
||||
|
||||
const lookup = require('./addons/lookup.js');
|
||||
const lookup = require('./addons/lookup');
|
||||
|
||||
module.exports = {
|
||||
permissions: new Permissions([
|
||||
|
@ -13,17 +13,13 @@ module.exports = {
|
|||
data: new SlashCommandBuilder()
|
||||
.setName('utilities')
|
||||
.setDescription('Common utilities.')
|
||||
.addSubcommand((subcommand) =>
|
||||
subcommand
|
||||
.setName('lookup')
|
||||
.setDescription('Lookup a domain or ip. (Request sent over HTTP, proceed with caution!)')
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName('target')
|
||||
.setDescription('The target you want to look up.')
|
||||
.setRequired(true)
|
||||
)
|
||||
),
|
||||
.addSubcommand((subcommand) => subcommand
|
||||
.setName('lookup')
|
||||
.setDescription('Lookup a domain or ip. (Request sent over HTTP, proceed with caution!)')
|
||||
.addStringOption((option) => option
|
||||
.setName('target')
|
||||
.setDescription('The target you want to look up.')
|
||||
.setRequired(true))),
|
||||
async execute(interaction) {
|
||||
if (interaction.options.getSubcommand() === 'lookup') {
|
||||
await lookup(interaction);
|
||||
|
|
33
src/deploy-commands.js
Normal file
33
src/deploy-commands.js
Normal file
|
@ -0,0 +1,33 @@
|
|||
/* eslint-disable no-restricted-syntax */
|
||||
const config = require('../config.json');
|
||||
|
||||
const logger = require('./handlers/logger');
|
||||
|
||||
module.exports = async () => {
|
||||
// eslint-disable-next-line global-require
|
||||
const fs = require('fs');
|
||||
// eslint-disable-next-line global-require
|
||||
const { REST } = require('@discordjs/rest');
|
||||
// eslint-disable-next-line global-require
|
||||
const { Routes } = require('discord-api-types/v9');
|
||||
|
||||
const commands = [];
|
||||
const commandFiles = fs.readdirSync('./commands');
|
||||
|
||||
for (const file of commandFiles) {
|
||||
// eslint-disable-next-line import/no-dynamic-require, global-require
|
||||
const command = require(`./commands/${file}`);
|
||||
commands.push(command.data.toJSON());
|
||||
}
|
||||
|
||||
const rest = new REST({ version: '9' }).setToken(config.bot.token);
|
||||
|
||||
rest
|
||||
.put(Routes.applicationGuildCommands(config.bot.clientId, config.bot.guildId), {
|
||||
body: commands,
|
||||
})
|
||||
.then(async () => logger.info('Successfully registered application commands.'))
|
||||
.catch(async (err) => {
|
||||
await logger.error(err);
|
||||
});
|
||||
};
|
|
@ -1,4 +1,5 @@
|
|||
const logger = require(`${__basedir}/handlers/logger`);
|
||||
const config = require('../../config.json');
|
||||
const logger = require('../handlers/logger');
|
||||
|
||||
module.exports = {
|
||||
name: 'interactionCreate',
|
||||
|
@ -20,7 +21,7 @@ module.exports = {
|
|||
},
|
||||
title: 'Check',
|
||||
description: 'Please wait...',
|
||||
color: __config.colors.wait,
|
||||
color: config.colors.wait,
|
||||
timestamp: new Date(),
|
||||
},
|
||||
],
|
||||
|
@ -28,8 +29,7 @@ module.exports = {
|
|||
});
|
||||
await command.execute(interaction);
|
||||
await logger.debug(`Executing command: ${interaction.commandName}`);
|
||||
}
|
||||
catch (err) {
|
||||
} catch (err) {
|
||||
await logger.error(err);
|
||||
await interaction.reply({
|
||||
embeds: [
|
||||
|
@ -41,7 +41,7 @@ module.exports = {
|
|||
},
|
||||
title: 'Error',
|
||||
description: 'There was an error while executing this command!',
|
||||
color: __config.colors.error,
|
||||
color: config.colors.error,
|
||||
timestamp: new Date(),
|
||||
},
|
||||
],
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
const logger = require(`${__basedir}/handlers/logger`);
|
||||
const config = require('../../config.json');
|
||||
const logger = require('../handlers/logger');
|
||||
|
||||
const credits = require(`${__basedir}/helpers/database/models/creditSchema`);
|
||||
const credits = require('../helpers/database/models/creditSchema');
|
||||
|
||||
const talkedRecently = new Set();
|
||||
|
||||
|
@ -8,16 +9,16 @@ module.exports = {
|
|||
name: 'messageCreate',
|
||||
async execute(message) {
|
||||
if (message.author.bot) return;
|
||||
if (message.content.length < __config.credits.minimumLength) return;
|
||||
if (__config.credits.excludedChannels.includes(message.channel.id)) return;
|
||||
if (message.content.length < config.credits.minimumLength) return;
|
||||
if (config.credits.excludedChannels.includes(message.channel.id)) return;
|
||||
if (!talkedRecently.has(message.author.id)) {
|
||||
await credits
|
||||
.findOneAndUpdate(
|
||||
{ userId: message.author.id },
|
||||
{ $inc: { balance: __config.credits.rate } },
|
||||
{ new: true, upsert: true }
|
||||
{ $inc: { balance: config.credits.rate } },
|
||||
{ new: true, upsert: true },
|
||||
)
|
||||
.then(async () => await logger.debug(`Credits added to user: ${message.author.id}`))
|
||||
.then(async () => logger.debug(`Credits added to user: ${message.author.id}`))
|
||||
.catch(async (err) => {
|
||||
await logger.error(err);
|
||||
});
|
||||
|
@ -25,17 +26,16 @@ module.exports = {
|
|||
setTimeout(() => {
|
||||
logger.debug(
|
||||
`User: ${message.author.id} has not talked within last ${
|
||||
__config.credits.timeout / 1000
|
||||
} seconds, credits can be given`
|
||||
config.credits.timeout / 1000
|
||||
} seconds, credits can be given`,
|
||||
);
|
||||
talkedRecently.delete(message.author.id);
|
||||
}, __config.credits.timeout);
|
||||
}
|
||||
else {
|
||||
}, config.credits.timeout);
|
||||
} else {
|
||||
logger.debug(
|
||||
`User: ${message.author.id} has talked within last ${
|
||||
__config.credits.timeout / 1000
|
||||
} seconds, no credits given`
|
||||
config.credits.timeout / 1000
|
||||
} seconds, no credits given`,
|
||||
);
|
||||
}
|
||||
},
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
const logger = require(`${__basedir}/handlers/logger`);
|
||||
const logger = require('../handlers/logger');
|
||||
|
||||
module.exports = {
|
||||
name: 'ready',
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
const axios = require('axios');
|
||||
|
||||
const config = require('../../config.json');
|
||||
|
||||
module.exports = axios.create({
|
||||
baseURL: __config.credits.url,
|
||||
headers: { Authorization: `Bearer ${__config.credits.token}` },
|
||||
baseURL: config.credits.url,
|
||||
headers: { Authorization: `Bearer ${config.credits.token}` },
|
||||
});
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
const pino = require('pino');
|
||||
const logger = pino({ level: __config.debug ? 'debug' : 'info' });
|
||||
|
||||
const config = require('../../config.json');
|
||||
|
||||
const logger = pino({ level: config.debug ? 'debug' : 'info' });
|
||||
module.exports = logger;
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
const logger = require(`${__basedir}/handlers/logger`);
|
||||
|
||||
const mongoose = require('mongoose');
|
||||
|
||||
const config = require('../../../config.json');
|
||||
const logger = require('../../handlers/logger');
|
||||
|
||||
module.exports = async () => {
|
||||
try {
|
||||
await mongoose.connect(__config.mongodb.url);
|
||||
await mongoose.connect(config.mongodb.url);
|
||||
await logger.info('Connected to the database');
|
||||
}
|
||||
catch (err) {
|
||||
} catch (err) {
|
||||
await logger.error(err);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -16,7 +16,7 @@ const creditSchema = new mongoose.Schema(
|
|||
index: false,
|
||||
},
|
||||
},
|
||||
{ timestamps: true }
|
||||
{ timestamps: true },
|
||||
);
|
||||
|
||||
module.exports = mongoose.model('credit', creditSchema);
|
||||
|
|
|
@ -1,30 +1,29 @@
|
|||
const sleep = require('./sleep');
|
||||
|
||||
const logger = require('../handlers/logger');
|
||||
|
||||
module.exports = async function saveUser(data, data2) {
|
||||
process.nextTick(
|
||||
async () => {
|
||||
await sleep(Math.floor(Math.random() * 10 + 1) * 100); // 100 - 1000 random Number generator
|
||||
data.save((_) =>
|
||||
_
|
||||
? console.log(
|
||||
`ERROR Occured while saving data (saveUser) \n${'='.repeat(50)}\n${
|
||||
`${_ }\n${ '='.repeat(50)}`
|
||||
}`
|
||||
)
|
||||
: 'No Error'
|
||||
);
|
||||
data.save((_) => (_
|
||||
? logger.error(
|
||||
`ERROR Occurred while saving data (saveUser) \n${'='.repeat(50)}\n${
|
||||
`${_}\n${'='.repeat(50)}`
|
||||
}`,
|
||||
)
|
||||
: 'No Error'));
|
||||
if (data2) {
|
||||
data2.save((_) =>
|
||||
_
|
||||
? console.error(
|
||||
`ERROR Occured while saving data (saveUser) \n${'='.repeat(50)}\n${
|
||||
`${_ }\n${ '='.repeat(50)}`
|
||||
}`
|
||||
)
|
||||
: 'No Error'
|
||||
);
|
||||
}
|
||||
data2.save((_) => (_
|
||||
? logger.error(
|
||||
`ERROR Occurred while saving data (saveUser) \n${'='.repeat(50)}\n${
|
||||
`${_}\n${'='.repeat(50)}`
|
||||
}`,
|
||||
)
|
||||
: 'No Error'));
|
||||
}
|
||||
},
|
||||
data,
|
||||
data2
|
||||
data2,
|
||||
);
|
||||
};
|
||||
|
|
16
src/index.js
16
src/index.js
|
@ -1,11 +1,12 @@
|
|||
__basedir = __dirname;
|
||||
__config = require(`${__basedir}/../config.json`);
|
||||
require('../deploy-commands')();
|
||||
/* eslint-disable no-restricted-syntax */
|
||||
require('./deploy-commands')();
|
||||
require('./helpers/database')();
|
||||
|
||||
const fs = require('node:fs');
|
||||
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 eventFiles = fs.readdirSync('./src/events').filter((file) => file.endsWith('.js'));
|
||||
|
@ -14,18 +15,19 @@ client.commands = new Collection();
|
|||
const commandFiles = fs.readdirSync('./src/commands');
|
||||
|
||||
for (const file of commandFiles) {
|
||||
// eslint-disable-next-line import/no-dynamic-require, global-require
|
||||
const command = require(`./commands/${file}`);
|
||||
client.commands.set(command.data.name, command);
|
||||
}
|
||||
|
||||
for (const file of eventFiles) {
|
||||
// eslint-disable-next-line import/no-dynamic-require, global-require
|
||||
const event = require(`./events/${file}`);
|
||||
if (event.once) {
|
||||
client.once(event.name, (...args) => event.execute(...args));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
client.on(event.name, (...args) => event.execute(...args));
|
||||
}
|
||||
}
|
||||
|
||||
client.login(__config.bot.token);
|
||||
client.login(config.bot.token);
|
||||
|
|
Loading…
Add table
Reference in a new issue