🎨 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.activeForeground": "#e7e7e7",
|
||||||
"titleBar.inactiveBackground": "#33669999",
|
"titleBar.inactiveBackground": "#33669999",
|
||||||
"titleBar.inactiveForeground": "#e7e7e799"
|
"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"
|
"email": "vermium@zyner.org"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@discordjs/builders": "^0.12.0",
|
||||||
"@discordjs/rest": "^0.3.0",
|
"@discordjs/rest": "^0.3.0",
|
||||||
"axios": "^0.26.0",
|
"axios": "^0.26.0",
|
||||||
"better-sqlite3": "^7.5.0",
|
"better-sqlite3": "^7.5.0",
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
const credits = require(`${__basedir}/helpers/database/models/creditSchema`);
|
const config = require('../../../../config.json');
|
||||||
const logger = require(`${__basedir}/handlers/logger`);
|
const logger = require('../../../handlers/logger');
|
||||||
const creditNoun = require(`${__basedir}/helpers/creditNoun`);
|
|
||||||
|
const credits = require('../../../helpers/database/models/creditSchema');
|
||||||
|
const creditNoun = require('../../../helpers/creditNoun');
|
||||||
|
|
||||||
module.exports = async (interaction) => {
|
module.exports = async (interaction) => {
|
||||||
try {
|
try {
|
||||||
|
@ -13,27 +15,26 @@ module.exports = async (interaction) => {
|
||||||
const embed = {
|
const embed = {
|
||||||
title: 'Balance',
|
title: 'Balance',
|
||||||
description: `${user} has no credits.`,
|
description: `${user} has no credits.`,
|
||||||
color: __config.colors.success,
|
color: config.colors.success,
|
||||||
timestamp: new Date(),
|
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 });
|
||||||
} 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 });
|
|
||||||
}
|
}
|
||||||
|
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));
|
||||||
} catch {
|
} catch {
|
||||||
async (err) => logger.error(err);
|
await logger.error();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
const credits = require(`${__basedir}/helpers/database/models/creditSchema`);
|
const config = require('../../../../config.json');
|
||||||
const logger = require(`${__basedir}/handlers/logger`);
|
const logger = require('../../../handlers/logger');
|
||||||
const saveUser = require(`${__basedir}/helpers/saveUser`);
|
|
||||||
const creditNoun = require(`${__basedir}/helpers/creditNoun`);
|
const credits = require('../../../helpers/database/models/creditSchema');
|
||||||
|
const saveUser = require('../../../helpers/saveUser');
|
||||||
|
const creditNoun = require('../../../helpers/creditNoun');
|
||||||
|
|
||||||
module.exports = async (interaction) => {
|
module.exports = async (interaction) => {
|
||||||
try {
|
try {
|
||||||
|
@ -15,51 +17,51 @@ module.exports = async (interaction) => {
|
||||||
description: "You can't pay yourself.",
|
description: "You can't pay yourself.",
|
||||||
color: 0xbb2124,
|
color: 0xbb2124,
|
||||||
timestamp: new Date(),
|
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 await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||||
} else if (amount <= 0) {
|
}
|
||||||
|
if (amount <= 0) {
|
||||||
const embed = {
|
const embed = {
|
||||||
title: 'Gift failed',
|
title: 'Gift failed',
|
||||||
description: "You can't pay zero or below.",
|
description: "You can't pay zero or below.",
|
||||||
color: 0xbb2124,
|
color: 0xbb2124,
|
||||||
timestamp: new Date(),
|
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 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 {
|
} catch {
|
||||||
async (err) => await logger.error(err);
|
await logger.error();
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
const { Permissions } = require('discord.js');
|
const { Permissions } = require('discord.js');
|
||||||
|
|
||||||
const credits = require(`${__basedir}/helpers/database/models/creditSchema`);
|
const config = require('../../../../config.json');
|
||||||
const logger = require(`${__basedir}/handlers/logger`);
|
const logger = require('../../../handlers/logger');
|
||||||
const creditNoun = require(`${__basedir}/helpers/creditNoun`);
|
|
||||||
|
const credits = require('../../../helpers/database/models/creditSchema');
|
||||||
|
const creditNoun = require('../../../helpers/creditNoun');
|
||||||
|
|
||||||
module.exports = async (interaction) => {
|
module.exports = async (interaction) => {
|
||||||
try {
|
try {
|
||||||
|
@ -22,28 +24,28 @@ module.exports = async (interaction) => {
|
||||||
description: "You can't give zero or below.",
|
description: "You can't give zero or below.",
|
||||||
color: 0xbb2124,
|
color: 0xbb2124,
|
||||||
timestamp: new Date(),
|
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 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 {
|
} 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 { 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) => {
|
module.exports = async (interaction) => {
|
||||||
try {
|
try {
|
||||||
if (__config.disable.redeem) {
|
if (config.disable.redeem) {
|
||||||
const embed = {
|
const embed = {
|
||||||
title: 'Redeem failed',
|
title: 'Redeem failed',
|
||||||
description: `Redeem is disabled until further.`,
|
description: 'Redeem is disabled until further.',
|
||||||
color: __config.colors.error,
|
color: config.colors.error,
|
||||||
timestamp: new Date(),
|
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 await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||||
}
|
}
|
||||||
|
@ -26,83 +28,85 @@ module.exports = async (interaction) => {
|
||||||
const embed = {
|
const embed = {
|
||||||
title: 'Redeem',
|
title: 'Redeem',
|
||||||
description: `You can't redeem below 100. Your balance is ${user.balance}.`,
|
description: `You can't redeem below 100. Your balance is ${user.balance}.`,
|
||||||
color: __config.colors.error,
|
color: config.colors.error,
|
||||||
timestamp: new Date(),
|
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 await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||||
} else if ((amount || user.balance) > 1000000) {
|
}
|
||||||
|
if ((amount || user.balance) > 1000000) {
|
||||||
const embed = {
|
const embed = {
|
||||||
title: 'Redeem',
|
title: 'Redeem',
|
||||||
description: `You can't redeem over 1,000,000. Your balance is ${user.balance}.`,
|
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(),
|
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 await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||||
} else if (user.balance < amount) {
|
}
|
||||||
|
if (user.balance < amount) {
|
||||||
const embed = {
|
const embed = {
|
||||||
title: 'Redeem',
|
title: 'Redeem',
|
||||||
description: `You have insufficient credits. Your balance is ${user.balance}.`,
|
description: `You have insufficient credits. Your balance is ${user.balance}.`,
|
||||||
color: __config.colors.error,
|
color: config.colors.error,
|
||||||
timestamp: new Date(),
|
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 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 {
|
} catch {
|
||||||
async (err) => await logger.error(err);
|
await logger.error();
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
const { Permissions } = require('discord.js');
|
const { Permissions } = require('discord.js');
|
||||||
|
|
||||||
const credits = require(`${__basedir}/helpers/database/models/creditSchema`);
|
const config = require('../../../../config.json');
|
||||||
const logger = require(`${__basedir}/handlers/logger`);
|
const logger = require('../../../handlers/logger');
|
||||||
const creditNoun = require(`${__basedir}/helpers/creditNoun`);
|
|
||||||
|
const credits = require('../../../helpers/database/models/creditSchema');
|
||||||
|
const creditNoun = require('../../../helpers/creditNoun');
|
||||||
|
|
||||||
module.exports = async (interaction) => {
|
module.exports = async (interaction) => {
|
||||||
if (!interaction.member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
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)',
|
description: 'You need to have permission to manage this guild (MANAGE_GUILD)',
|
||||||
color: 0xbb2124,
|
color: 0xbb2124,
|
||||||
timestamp: new Date(),
|
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 user = await interaction.options.getUser('user');
|
||||||
const amount = await interaction.options.getInteger('amount');
|
const amount = await interaction.options.getInteger('amount');
|
||||||
|
@ -27,12 +29,12 @@ module.exports = async (interaction) => {
|
||||||
description: `You set ${creditNoun(amount)} on ${user}.`,
|
description: `You set ${creditNoun(amount)} on ${user}.`,
|
||||||
color: 0x22bb33,
|
color: 0x22bb33,
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
footer: { iconURL: __config.footer.icon, text: __config.footer.text },
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
};
|
};
|
||||||
await logger.debug(
|
await logger.debug(
|
||||||
`Administrator: ${interaction.user.username} set ${
|
`Administrator: ${interaction.user.username} set ${
|
||||||
amount <= 1 ? `${amount} credit` : `${amount} credits`
|
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 { Permissions } = require('discord.js');
|
||||||
|
const config = require('../../../../config.json');
|
||||||
|
|
||||||
const credits = require(`${__basedir}/helpers/database/models/creditSchema`);
|
const credits = require('../../../helpers/database/models/creditSchema');
|
||||||
const logger = require(`${__basedir}/handlers/logger`);
|
const logger = require('../../../handlers/logger');
|
||||||
const creditNoun = require(`${__basedir}/helpers/creditNoun`);
|
const creditNoun = require('../../../helpers/creditNoun');
|
||||||
|
|
||||||
module.exports = async (interaction) => {
|
module.exports = async (interaction) => {
|
||||||
if (!interaction.member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
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)',
|
description: 'You need to have permission to manage this guild (MANAGE_GUILD)',
|
||||||
color: 0xbb2124,
|
color: 0xbb2124,
|
||||||
timestamp: new Date(),
|
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 user = await interaction.options.getUser('user');
|
||||||
const amount = await interaction.options.getInteger('amount');
|
const amount = await interaction.options.getInteger('amount');
|
||||||
|
@ -24,9 +25,9 @@ module.exports = async (interaction) => {
|
||||||
description: "You can't take zero or below.",
|
description: "You can't take zero or below.",
|
||||||
color: 0xbb2124,
|
color: 0xbb2124,
|
||||||
timestamp: new Date(),
|
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 });
|
const toUser = await credits.findOne({ userId: user.id });
|
||||||
toUser.balance -= amount;
|
toUser.balance -= amount;
|
||||||
|
@ -37,12 +38,12 @@ module.exports = async (interaction) => {
|
||||||
description: `You took ${creditNoun(amount)} to ${user}.`,
|
description: `You took ${creditNoun(amount)} to ${user}.`,
|
||||||
color: 0x22bb33,
|
color: 0x22bb33,
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
footer: { iconURL: __config.footer.icon, text: __config.footer.text },
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
};
|
};
|
||||||
await logger.debug(
|
await logger.debug(
|
||||||
`Administrator: ${interaction.user.username} took ${
|
`Administrator: ${interaction.user.username} took ${
|
||||||
amount <= 1 ? `${amount} credit` : `${amount} credits`
|
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 config = require('../../../../config.json');
|
||||||
const creditNoun = require(`${__basedir}/helpers/creditNoun`);
|
const credits = require('../../../helpers/database/models/creditSchema');
|
||||||
|
const creditNoun = require('../../../helpers/creditNoun');
|
||||||
|
|
||||||
module.exports = async (interaction) => {
|
module.exports = async (interaction) => {
|
||||||
await credits.find().then(async (data) => {
|
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')}`,
|
description: `Below are the top ten.\n${topTen.map((x, index) => item(x, index)).join('\n')}`,
|
||||||
color: 0x22bb33,
|
color: 0x22bb33,
|
||||||
timestamp: new Date(),
|
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 { Permissions } = require('discord.js');
|
||||||
|
|
||||||
const credits = require(`${__basedir}/helpers/database/models/creditSchema`);
|
const config = require('../../../../config.json');
|
||||||
const logger = require(`${__basedir}/handlers/logger`);
|
const logger = require('../../../handlers/logger');
|
||||||
const saveUser = require(`${__basedir}/helpers/saveUser`);
|
|
||||||
const creditNoun = require(`${__basedir}/helpers/creditNoun`);
|
const credits = require('../../../helpers/database/models/creditSchema');
|
||||||
|
const saveUser = require('../../../helpers/saveUser');
|
||||||
|
const creditNoun = require('../../../helpers/creditNoun');
|
||||||
|
|
||||||
module.exports = async (interaction) => {
|
module.exports = async (interaction) => {
|
||||||
try {
|
try {
|
||||||
|
@ -26,47 +28,44 @@ module.exports = async (interaction) => {
|
||||||
description: "You can't transfer zero or below.",
|
description: "You can't transfer zero or below.",
|
||||||
color: 0xbb2124,
|
color: 0xbb2124,
|
||||||
timestamp: new Date(),
|
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 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 {
|
} catch {
|
||||||
async (err) => await logger.error(err);
|
await logger.error();
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
const { SlashCommandBuilder } = require('@discordjs/builders');
|
const { SlashCommandBuilder } = require('@discordjs/builders');
|
||||||
const { MessageEmbed, Permissions } = require('discord.js');
|
const { Permissions } = require('discord.js');
|
||||||
|
|
||||||
const balance = require('./addons/balance.js');
|
const balance = require('./addons/balance');
|
||||||
const gift = require('./addons/gift.js');
|
const gift = require('./addons/gift');
|
||||||
const give = require('./addons/give.js');
|
const give = require('./addons/give');
|
||||||
const redeem = require('./addons/redeem.js');
|
const redeem = require('./addons/redeem');
|
||||||
const take = require('./addons/take.js');
|
const take = require('./addons/take');
|
||||||
const top = require('./addons/top.js');
|
const top = require('./addons/top');
|
||||||
const transfer = require('./addons/transfer.js');
|
const transfer = require('./addons/transfer');
|
||||||
const set = require('./addons/set.js');
|
const set = require('./addons/set');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
permissions: new Permissions([
|
permissions: new Permissions([
|
||||||
|
@ -20,121 +20,72 @@ module.exports = {
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
.setName('credits')
|
.setName('credits')
|
||||||
.setDescription('Manage your credits.')
|
.setDescription('Manage your credits.')
|
||||||
.addSubcommand((subcommand) =>
|
.addSubcommand((subcommand) => subcommand
|
||||||
subcommand
|
.setName('give')
|
||||||
.setName('give')
|
.setDescription('Give credits to a user. (ADMIN)')
|
||||||
.setDescription('Give credits to a user. (ADMIN)')
|
.addUserOption((option) => option.setName('user').setDescription('The user you want to pay.').setRequired(true))
|
||||||
.addUserOption((option) =>
|
.addIntegerOption((option) => option.setName('amount').setDescription('The amount you will pay.').setRequired(true)))
|
||||||
option.setName('user').setDescription('The user you want to pay.').setRequired(true)
|
.addSubcommand((subcommand) => subcommand
|
||||||
)
|
.setName('take')
|
||||||
.addIntegerOption((option) =>
|
.setDescription('Take credits from a user. (ADMIN)')
|
||||||
option.setName('amount').setDescription('The amount you will pay.').setRequired(true)
|
.addUserOption((option) => option
|
||||||
)
|
.setName('user')
|
||||||
)
|
.setDescription('The user you want to take credits from.')
|
||||||
.addSubcommand((subcommand) =>
|
.setRequired(true))
|
||||||
subcommand
|
.addIntegerOption((option) => option.setName('amount').setDescription('The amount you will take.').setRequired(true)))
|
||||||
.setName('take')
|
.addSubcommand((subcommand) => subcommand
|
||||||
.setDescription('Take credits from a user. (ADMIN)')
|
.setName('balance')
|
||||||
.addUserOption((option) =>
|
.setDescription("Check a user's balance.")
|
||||||
option
|
.addUserOption((option) => option
|
||||||
.setName('user')
|
.setName('user')
|
||||||
.setDescription('The user you want to take credits from.')
|
.setDescription('The user whose balance you want to check.')
|
||||||
.setRequired(true)
|
.setRequired(false)))
|
||||||
)
|
.addSubcommand((subcommand) => subcommand
|
||||||
.addIntegerOption((option) =>
|
.setName('redeem')
|
||||||
option.setName('amount').setDescription('The amount you will take.').setRequired(true)
|
.setDescription('Redeem your credits.')
|
||||||
)
|
.addIntegerOption((option) => option.setName('amount').setDescription('How much credit you want to withdraw.')))
|
||||||
)
|
.addSubcommand((subcommand) => subcommand
|
||||||
.addSubcommand((subcommand) =>
|
.setName('gift')
|
||||||
subcommand
|
.setDescription('Gift someone credits from your credits.')
|
||||||
.setName('balance')
|
.addUserOption((option) => option.setName('user').setDescription('The user you want to pay.').setRequired(true))
|
||||||
.setDescription("Check a user's balance.")
|
.addIntegerOption((option) => option.setName('amount').setDescription('The amount you will pay.').setRequired(true)))
|
||||||
.addUserOption((option) =>
|
.addSubcommand((subcommand) => subcommand.setName('top').setDescription('Check the top balance.'))
|
||||||
option
|
.addSubcommand((subcommand) => subcommand
|
||||||
.setName('user')
|
.setName('transfer')
|
||||||
.setDescription('The user whose balance you want to check.')
|
.setDescription('Transfer credits from a user to another user. (ADMIN)')
|
||||||
.setRequired(false)
|
.addUserOption((option) => option
|
||||||
)
|
.setName('from')
|
||||||
)
|
.setDescription('The user you want to take credits from.')
|
||||||
.addSubcommand((subcommand) =>
|
.setRequired(true))
|
||||||
subcommand
|
.addUserOption((option) => option
|
||||||
.setName('redeem')
|
.setName('to')
|
||||||
.setDescription('Redeem your credits.')
|
.setDescription('The user you want to give credits to.')
|
||||||
.addIntegerOption((option) =>
|
.setRequired(true))
|
||||||
option.setName('amount').setDescription('How much credit you want to withdraw.')
|
.addIntegerOption((option) => option.setName('amount').setDescription('The amount you will transfer.').setRequired(true)))
|
||||||
)
|
.addSubcommand((subcommand) => subcommand
|
||||||
)
|
.setName('set')
|
||||||
.addSubcommand((subcommand) =>
|
.setDescription('Set credits on a user. (ADMIN)')
|
||||||
subcommand
|
.addUserOption((option) => option
|
||||||
.setName('gift')
|
.setName('user')
|
||||||
.setDescription('Gift someone credits from your credits.')
|
.setDescription('The user you want to set credits on.')
|
||||||
.addUserOption((option) =>
|
.setRequired(true))
|
||||||
option.setName('user').setDescription('The user you want to pay.').setRequired(true)
|
.addIntegerOption((option) => option.setName('amount').setDescription('The amount you will set.').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) {
|
async execute(interaction) {
|
||||||
if (interaction.options.getSubcommand() === 'balance') {
|
if (interaction.options.getSubcommand() === 'balance') {
|
||||||
await balance(interaction);
|
await balance(interaction);
|
||||||
}
|
} else if (interaction.options.getSubcommand() === 'gift') {
|
||||||
else if (interaction.options.getSubcommand() === 'gift') {
|
|
||||||
await gift(interaction);
|
await gift(interaction);
|
||||||
}
|
} else if (interaction.options.getSubcommand() === 'give') {
|
||||||
else if (interaction.options.getSubcommand() === 'give') {
|
|
||||||
await give(interaction);
|
await give(interaction);
|
||||||
}
|
} else if (interaction.options.getSubcommand() === 'redeem') {
|
||||||
else if (interaction.options.getSubcommand() === 'redeem') {
|
|
||||||
await redeem(interaction);
|
await redeem(interaction);
|
||||||
}
|
} else if (interaction.options.getSubcommand() === 'take') {
|
||||||
else if (interaction.options.getSubcommand() === 'take') {
|
|
||||||
await take(interaction);
|
await take(interaction);
|
||||||
}
|
} else if (interaction.options.getSubcommand() === 'top') {
|
||||||
else if (interaction.options.getSubcommand() === 'top') {
|
|
||||||
await top(interaction);
|
await top(interaction);
|
||||||
}
|
} else if (interaction.options.getSubcommand() === 'transfer') {
|
||||||
else if (interaction.options.getSubcommand() === 'transfer') {
|
|
||||||
await transfer(interaction);
|
await transfer(interaction);
|
||||||
}
|
} else if (interaction.options.getSubcommand() === 'set') {
|
||||||
else if (interaction.options.getSubcommand() === 'set') {
|
|
||||||
await set(interaction);
|
await set(interaction);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
const logger = require(`${__basedir}/handlers/logger`);
|
|
||||||
|
|
||||||
const axios = require('axios');
|
const axios = require('axios');
|
||||||
|
|
||||||
|
const config = require('../../../../config.json');
|
||||||
|
const logger = require('../../../handlers/logger');
|
||||||
|
|
||||||
module.exports = async (interaction) => {
|
module.exports = async (interaction) => {
|
||||||
try {
|
try {
|
||||||
const target = await interaction.options.getString('target');
|
const target = await interaction.options.getString('target');
|
||||||
|
@ -13,9 +14,9 @@ module.exports = async (interaction) => {
|
||||||
const embed = {
|
const embed = {
|
||||||
title: 'Lookup',
|
title: 'Lookup',
|
||||||
description: `${res.data.message}: ${res.data.query}`,
|
description: `${res.data.message}: ${res.data.query}`,
|
||||||
color: __config.colors.error,
|
color: config.colors.error,
|
||||||
timestamp: new Date(),
|
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] });
|
await interaction.editReply({ embeds: [embed] });
|
||||||
} else if (res.data.status === 'success') {
|
} else if (res.data.status === 'success') {
|
||||||
|
@ -35,9 +36,9 @@ module.exports = async (interaction) => {
|
||||||
{ name: 'ISP', value: `${res.data.isp || 'Not available'}` },
|
{ name: 'ISP', value: `${res.data.isp || 'Not available'}` },
|
||||||
{ name: 'Organization', value: `${res.data.org || 'Not available'}` },
|
{ name: 'Organization', value: `${res.data.org || 'Not available'}` },
|
||||||
],
|
],
|
||||||
color: __config.colors.success,
|
color: config.colors.success,
|
||||||
timestamp: new Date(),
|
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] });
|
await interaction.editReply({ embeds: [embed] });
|
||||||
}
|
}
|
||||||
|
@ -46,6 +47,6 @@ module.exports = async (interaction) => {
|
||||||
await logger.error(err);
|
await logger.error(err);
|
||||||
});
|
});
|
||||||
} catch {
|
} catch {
|
||||||
async (err) => await logger.error(err);
|
await logger.error();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
const { SlashCommandBuilder } = require('@discordjs/builders');
|
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 = {
|
module.exports = {
|
||||||
permissions: new Permissions([
|
permissions: new Permissions([
|
||||||
|
@ -13,17 +13,13 @@ module.exports = {
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
.setName('utilities')
|
.setName('utilities')
|
||||||
.setDescription('Common utilities.')
|
.setDescription('Common utilities.')
|
||||||
.addSubcommand((subcommand) =>
|
.addSubcommand((subcommand) => subcommand
|
||||||
subcommand
|
.setName('lookup')
|
||||||
.setName('lookup')
|
.setDescription('Lookup a domain or ip. (Request sent over HTTP, proceed with caution!)')
|
||||||
.setDescription('Lookup a domain or ip. (Request sent over HTTP, proceed with caution!)')
|
.addStringOption((option) => option
|
||||||
.addStringOption((option) =>
|
.setName('target')
|
||||||
option
|
.setDescription('The target you want to look up.')
|
||||||
.setName('target')
|
.setRequired(true))),
|
||||||
.setDescription('The target you want to look up.')
|
|
||||||
.setRequired(true)
|
|
||||||
)
|
|
||||||
),
|
|
||||||
async execute(interaction) {
|
async execute(interaction) {
|
||||||
if (interaction.options.getSubcommand() === 'lookup') {
|
if (interaction.options.getSubcommand() === 'lookup') {
|
||||||
await lookup(interaction);
|
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 = {
|
module.exports = {
|
||||||
name: 'interactionCreate',
|
name: 'interactionCreate',
|
||||||
|
@ -20,7 +21,7 @@ module.exports = {
|
||||||
},
|
},
|
||||||
title: 'Check',
|
title: 'Check',
|
||||||
description: 'Please wait...',
|
description: 'Please wait...',
|
||||||
color: __config.colors.wait,
|
color: config.colors.wait,
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -28,8 +29,7 @@ module.exports = {
|
||||||
});
|
});
|
||||||
await command.execute(interaction);
|
await command.execute(interaction);
|
||||||
await logger.debug(`Executing command: ${interaction.commandName}`);
|
await logger.debug(`Executing command: ${interaction.commandName}`);
|
||||||
}
|
} catch (err) {
|
||||||
catch (err) {
|
|
||||||
await logger.error(err);
|
await logger.error(err);
|
||||||
await interaction.reply({
|
await interaction.reply({
|
||||||
embeds: [
|
embeds: [
|
||||||
|
@ -41,7 +41,7 @@ module.exports = {
|
||||||
},
|
},
|
||||||
title: 'Error',
|
title: 'Error',
|
||||||
description: 'There was an error while executing this command!',
|
description: 'There was an error while executing this command!',
|
||||||
color: __config.colors.error,
|
color: config.colors.error,
|
||||||
timestamp: new Date(),
|
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();
|
const talkedRecently = new Set();
|
||||||
|
|
||||||
|
@ -8,16 +9,16 @@ module.exports = {
|
||||||
name: 'messageCreate',
|
name: 'messageCreate',
|
||||||
async execute(message) {
|
async execute(message) {
|
||||||
if (message.author.bot) return;
|
if (message.author.bot) return;
|
||||||
if (message.content.length < __config.credits.minimumLength) return;
|
if (message.content.length < config.credits.minimumLength) return;
|
||||||
if (__config.credits.excludedChannels.includes(message.channel.id)) return;
|
if (config.credits.excludedChannels.includes(message.channel.id)) return;
|
||||||
if (!talkedRecently.has(message.author.id)) {
|
if (!talkedRecently.has(message.author.id)) {
|
||||||
await credits
|
await credits
|
||||||
.findOneAndUpdate(
|
.findOneAndUpdate(
|
||||||
{ userId: message.author.id },
|
{ userId: message.author.id },
|
||||||
{ $inc: { balance: __config.credits.rate } },
|
{ $inc: { balance: config.credits.rate } },
|
||||||
{ new: true, upsert: true }
|
{ 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) => {
|
.catch(async (err) => {
|
||||||
await logger.error(err);
|
await logger.error(err);
|
||||||
});
|
});
|
||||||
|
@ -25,17 +26,16 @@ module.exports = {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`User: ${message.author.id} has not talked within last ${
|
`User: ${message.author.id} has not talked within last ${
|
||||||
__config.credits.timeout / 1000
|
config.credits.timeout / 1000
|
||||||
} seconds, credits can be given`
|
} seconds, credits can be given`,
|
||||||
);
|
);
|
||||||
talkedRecently.delete(message.author.id);
|
talkedRecently.delete(message.author.id);
|
||||||
}, __config.credits.timeout);
|
}, config.credits.timeout);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`User: ${message.author.id} has talked within last ${
|
`User: ${message.author.id} has talked within last ${
|
||||||
__config.credits.timeout / 1000
|
config.credits.timeout / 1000
|
||||||
} seconds, no credits given`
|
} seconds, no credits given`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
const logger = require(`${__basedir}/handlers/logger`);
|
const logger = require('../handlers/logger');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'ready',
|
name: 'ready',
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
const axios = require('axios');
|
const axios = require('axios');
|
||||||
|
|
||||||
|
const config = require('../../config.json');
|
||||||
|
|
||||||
module.exports = axios.create({
|
module.exports = axios.create({
|
||||||
baseURL: __config.credits.url,
|
baseURL: config.credits.url,
|
||||||
headers: { Authorization: `Bearer ${__config.credits.token}` },
|
headers: { Authorization: `Bearer ${config.credits.token}` },
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
const pino = require('pino');
|
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;
|
module.exports = logger;
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
const logger = require(`${__basedir}/handlers/logger`);
|
|
||||||
|
|
||||||
const mongoose = require('mongoose');
|
const mongoose = require('mongoose');
|
||||||
|
|
||||||
|
const config = require('../../../config.json');
|
||||||
|
const logger = require('../../handlers/logger');
|
||||||
|
|
||||||
module.exports = async () => {
|
module.exports = async () => {
|
||||||
try {
|
try {
|
||||||
await mongoose.connect(__config.mongodb.url);
|
await mongoose.connect(config.mongodb.url);
|
||||||
await logger.info('Connected to the database');
|
await logger.info('Connected to the database');
|
||||||
}
|
} catch (err) {
|
||||||
catch (err) {
|
|
||||||
await logger.error(err);
|
await logger.error(err);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -16,7 +16,7 @@ const creditSchema = new mongoose.Schema(
|
||||||
index: false,
|
index: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{ timestamps: true }
|
{ timestamps: true },
|
||||||
);
|
);
|
||||||
|
|
||||||
module.exports = mongoose.model('credit', creditSchema);
|
module.exports = mongoose.model('credit', creditSchema);
|
||||||
|
|
|
@ -1,30 +1,29 @@
|
||||||
const sleep = require('./sleep');
|
const sleep = require('./sleep');
|
||||||
|
|
||||||
|
const logger = require('../handlers/logger');
|
||||||
|
|
||||||
module.exports = async function saveUser(data, data2) {
|
module.exports = async function saveUser(data, data2) {
|
||||||
process.nextTick(
|
process.nextTick(
|
||||||
async () => {
|
async () => {
|
||||||
await sleep(Math.floor(Math.random() * 10 + 1) * 100); // 100 - 1000 random Number generator
|
await sleep(Math.floor(Math.random() * 10 + 1) * 100); // 100 - 1000 random Number generator
|
||||||
data.save((_) =>
|
data.save((_) => (_
|
||||||
_
|
? logger.error(
|
||||||
? console.log(
|
`ERROR Occurred while saving data (saveUser) \n${'='.repeat(50)}\n${
|
||||||
`ERROR Occured while saving data (saveUser) \n${'='.repeat(50)}\n${
|
`${_}\n${'='.repeat(50)}`
|
||||||
`${_ }\n${ '='.repeat(50)}`
|
}`,
|
||||||
}`
|
)
|
||||||
)
|
: 'No Error'));
|
||||||
: 'No Error'
|
|
||||||
);
|
|
||||||
if (data2) {
|
if (data2) {
|
||||||
data2.save((_) =>
|
data2.save((_) => (_
|
||||||
_
|
? logger.error(
|
||||||
? console.error(
|
`ERROR Occurred while saving data (saveUser) \n${'='.repeat(50)}\n${
|
||||||
`ERROR Occured while saving data (saveUser) \n${'='.repeat(50)}\n${
|
`${_}\n${'='.repeat(50)}`
|
||||||
`${_ }\n${ '='.repeat(50)}`
|
}`,
|
||||||
}`
|
)
|
||||||
)
|
: 'No Error'));
|
||||||
: 'No Error'
|
}
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
data,
|
data,
|
||||||
data2
|
data2,
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
16
src/index.js
16
src/index.js
|
@ -1,11 +1,12 @@
|
||||||
__basedir = __dirname;
|
/* eslint-disable no-restricted-syntax */
|
||||||
__config = require(`${__basedir}/../config.json`);
|
require('./deploy-commands')();
|
||||||
require('../deploy-commands')();
|
|
||||||
require('./helpers/database')();
|
require('./helpers/database')();
|
||||||
|
|
||||||
const fs = require('node:fs');
|
const fs = require('fs');
|
||||||
const { Client, Collection, Intents } = require('discord.js');
|
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'));
|
||||||
|
@ -14,18 +15,19 @@ client.commands = new Collection();
|
||||||
const commandFiles = fs.readdirSync('./src/commands');
|
const commandFiles = fs.readdirSync('./src/commands');
|
||||||
|
|
||||||
for (const file of commandFiles) {
|
for (const file of commandFiles) {
|
||||||
|
// eslint-disable-next-line import/no-dynamic-require, global-require
|
||||||
const command = require(`./commands/${file}`);
|
const command = require(`./commands/${file}`);
|
||||||
client.commands.set(command.data.name, command);
|
client.commands.set(command.data.name, command);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const file of eventFiles) {
|
for (const file of eventFiles) {
|
||||||
|
// eslint-disable-next-line import/no-dynamic-require, global-require
|
||||||
const event = require(`./events/${file}`);
|
const event = require(`./events/${file}`);
|
||||||
if (event.once) {
|
if (event.once) {
|
||||||
client.once(event.name, (...args) => event.execute(...args));
|
client.once(event.name, (...args) => event.execute(...args));
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
client.on(event.name, (...args) => event.execute(...args));
|
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