💡 Added comments to all commands
This commit is contained in:
parent
83501cf35e
commit
531e127b2e
34 changed files with 693 additions and 611 deletions
|
@ -3,18 +3,17 @@ const config = require('../../../../../config.json');
|
||||||
const logger = require('../../../../handlers/logger');
|
const logger = require('../../../../handlers/logger');
|
||||||
|
|
||||||
// Database models
|
// Database models
|
||||||
|
|
||||||
const { credits } = require('../../../../helpers/database/models');
|
const { credits } = require('../../../../helpers/database/models');
|
||||||
|
|
||||||
const creditNoun = require('../../../../helpers/creditNoun');
|
const creditNoun = require('../../../../helpers/creditNoun');
|
||||||
|
|
||||||
module.exports = async (interaction) => {
|
module.exports = async (interaction) => {
|
||||||
// Destructure member
|
// Destructure member
|
||||||
|
|
||||||
const { member } = interaction;
|
const { member } = interaction;
|
||||||
|
|
||||||
// Check permission
|
// Check permission
|
||||||
|
|
||||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||||
|
// Create embed object
|
||||||
const embed = {
|
const embed = {
|
||||||
title: 'Admin',
|
title: 'Admin',
|
||||||
color: config.colors.error,
|
color: config.colors.error,
|
||||||
|
@ -22,17 +21,18 @@ module.exports = async (interaction) => {
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Send interaction reply
|
||||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get options
|
// Get options
|
||||||
|
|
||||||
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');
|
||||||
|
|
||||||
// Stop if given amount is zero or below
|
// If amount is zero or below
|
||||||
|
|
||||||
if (amount <= 0) {
|
if (amount <= 0) {
|
||||||
|
// Create embed object
|
||||||
const embed = {
|
const embed = {
|
||||||
title: 'Give',
|
title: 'Give',
|
||||||
description: "You can't give zero or below.",
|
description: "You can't give zero or below.",
|
||||||
|
@ -40,19 +40,20 @@ module.exports = async (interaction) => {
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Send interaction reply
|
||||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get toUser object
|
// Get toUser object
|
||||||
|
|
||||||
const toUser = await credits.findOne({
|
const toUser = await credits.findOne({
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
guildId: interaction.member.guild.id,
|
guildId: interaction.member.guild.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Stop if user has zero or below credits
|
// If toUser has no credits
|
||||||
|
|
||||||
if (!toUser) {
|
if (!toUser) {
|
||||||
|
// Create embed object
|
||||||
const embed = {
|
const embed = {
|
||||||
title: 'Give',
|
title: 'Give',
|
||||||
description:
|
description:
|
||||||
|
@ -61,38 +62,44 @@ module.exports = async (interaction) => {
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Send interaction reply
|
||||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Increase toUser with amount
|
// Deposit amount to toUser
|
||||||
|
|
||||||
toUser.balance += amount;
|
toUser.balance += amount;
|
||||||
|
|
||||||
// Save toUser
|
// Save toUser
|
||||||
|
await toUser
|
||||||
|
.save()
|
||||||
|
|
||||||
await toUser.save().then(async () => {
|
// If successful
|
||||||
const embed = {
|
.then(async () => {
|
||||||
title: 'Give',
|
// Create embed object
|
||||||
description: `Gave ${creditNoun(amount)} to ${user}.`,
|
const embed = {
|
||||||
color: 0x22bb33,
|
title: 'Give',
|
||||||
timestamp: new Date(),
|
description: `Gave ${creditNoun(amount)} to ${user}.`,
|
||||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
color: 0x22bb33,
|
||||||
};
|
timestamp: new Date(),
|
||||||
await logger.debug(
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
`Administrator: ${interaction.user.username} gave ${
|
};
|
||||||
amount <= 1 ? `${amount} credit` : `${amount} credits`
|
|
||||||
} to ${user.username}`
|
|
||||||
);
|
|
||||||
// Send reply
|
|
||||||
|
|
||||||
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
// Send debug message
|
||||||
|
await logger.debug(
|
||||||
|
`Administrator: ${interaction.user.username} gave ${
|
||||||
|
amount <= 1 ? `${amount} credit` : `${amount} credits`
|
||||||
|
} to ${user.username}`
|
||||||
|
);
|
||||||
|
|
||||||
// Send debug message
|
// Send interaction reply
|
||||||
|
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||||
|
|
||||||
await logger.debug(
|
// Send debug message
|
||||||
`Guild: ${member.guild.id} User: ${member.id} gave ${
|
await logger.debug(
|
||||||
user.id
|
`Guild: ${member.guild.id} User: ${member.id} gave ${
|
||||||
} ${creditNoun(amount)}.`
|
user.id
|
||||||
);
|
} ${creditNoun(amount)}.`
|
||||||
});
|
);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,12 +9,11 @@ const creditNoun = require('../../../../helpers/creditNoun');
|
||||||
|
|
||||||
module.exports = async (interaction) => {
|
module.exports = async (interaction) => {
|
||||||
// Destructure member
|
// Destructure member
|
||||||
|
|
||||||
const { member } = interaction;
|
const { member } = interaction;
|
||||||
|
|
||||||
// Check permission
|
// Check permission
|
||||||
|
|
||||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||||
|
// Create embed object
|
||||||
const embed = {
|
const embed = {
|
||||||
title: 'Admin',
|
title: 'Admin',
|
||||||
color: config.colors.error,
|
color: config.colors.error,
|
||||||
|
@ -22,17 +21,18 @@ module.exports = async (interaction) => {
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Send interaction reply
|
||||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get options
|
// Get options
|
||||||
|
|
||||||
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');
|
||||||
|
|
||||||
// Stop if given amount is zero or below
|
// If amount is zero or below
|
||||||
|
|
||||||
if (amount <= 0) {
|
if (amount <= 0) {
|
||||||
|
// Create embed object
|
||||||
const embed = {
|
const embed = {
|
||||||
title: 'Give',
|
title: 'Give',
|
||||||
description: "You can't give zero or below.",
|
description: "You can't give zero or below.",
|
||||||
|
@ -40,19 +40,20 @@ module.exports = async (interaction) => {
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Send interaction reply
|
||||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get toUser object
|
// Get toUser object
|
||||||
|
|
||||||
const toUser = await credits.findOne({
|
const toUser = await credits.findOne({
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
guildId: interaction.member.guild.id,
|
guildId: interaction.member.guild.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Stop if user has zero or below credits
|
// If toUser has no credits
|
||||||
|
|
||||||
if (!toUser) {
|
if (!toUser) {
|
||||||
|
// Create embed object
|
||||||
const embed = {
|
const embed = {
|
||||||
title: 'Set',
|
title: 'Set',
|
||||||
description:
|
description:
|
||||||
|
@ -61,38 +62,44 @@ module.exports = async (interaction) => {
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Send interaction reply
|
||||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set toUser with amount
|
// Set toUser with amount
|
||||||
|
|
||||||
toUser.balance = amount;
|
toUser.balance = amount;
|
||||||
|
|
||||||
// Save toUser
|
// Save toUser
|
||||||
|
await toUser
|
||||||
|
.save()
|
||||||
|
|
||||||
await toUser.save().then(async () => {
|
// If successful
|
||||||
const embed = {
|
.then(async () => {
|
||||||
title: 'Set',
|
// Create embed object
|
||||||
description: `You set ${creditNoun(amount)} on ${user}.`,
|
const embed = {
|
||||||
color: 0x22bb33,
|
title: 'Set',
|
||||||
timestamp: new Date(),
|
description: `You set ${creditNoun(amount)} on ${user}.`,
|
||||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
color: 0x22bb33,
|
||||||
};
|
timestamp: new Date(),
|
||||||
await logger.debug(
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
`Administrator: ${interaction.user.username} set ${
|
};
|
||||||
amount <= 1 ? `${amount} credit` : `${amount} credits`
|
|
||||||
} on ${user.username}`
|
|
||||||
);
|
|
||||||
// Send reply
|
|
||||||
|
|
||||||
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
// Send debug message
|
||||||
|
await logger.debug(
|
||||||
|
`Administrator: ${interaction.user.username} set ${
|
||||||
|
amount <= 1 ? `${amount} credit` : `${amount} credits`
|
||||||
|
} on ${user.username}`
|
||||||
|
);
|
||||||
|
|
||||||
// Send debug message
|
// Send interaction reply
|
||||||
|
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||||
|
|
||||||
await logger.debug(
|
// Send debug message
|
||||||
`Guild: ${member.guild.id} User: ${member.id} set ${
|
await logger.debug(
|
||||||
user.id
|
`Guild: ${member.guild.id} User: ${member.id} set ${
|
||||||
} to ${creditNoun(amount)}.`
|
user.id
|
||||||
);
|
} to ${creditNoun(amount)}.`
|
||||||
});
|
);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,12 +9,11 @@ const creditNoun = require('../../../../helpers/creditNoun');
|
||||||
|
|
||||||
module.exports = async (interaction) => {
|
module.exports = async (interaction) => {
|
||||||
// Destructure member
|
// Destructure member
|
||||||
|
|
||||||
const { member } = interaction;
|
const { member } = interaction;
|
||||||
|
|
||||||
// Check permission
|
// Check permission
|
||||||
|
|
||||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||||
|
// Create embed object
|
||||||
const embed = {
|
const embed = {
|
||||||
title: 'Admin',
|
title: 'Admin',
|
||||||
color: config.colors.error,
|
color: config.colors.error,
|
||||||
|
@ -22,17 +21,18 @@ module.exports = async (interaction) => {
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Send interaction reply
|
||||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get options
|
// Get options
|
||||||
|
|
||||||
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');
|
||||||
|
|
||||||
// Stop if given amount is zero or below
|
// If amount is zero or below
|
||||||
|
|
||||||
if (amount <= 0) {
|
if (amount <= 0) {
|
||||||
|
// Give embed object
|
||||||
const embed = {
|
const embed = {
|
||||||
title: 'Take',
|
title: 'Take',
|
||||||
description: "You can't take zero or below.",
|
description: "You can't take zero or below.",
|
||||||
|
@ -40,19 +40,20 @@ module.exports = async (interaction) => {
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Send interaction reply
|
||||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get toUser object
|
// Get toUser object
|
||||||
|
|
||||||
const toUser = await credits.findOne({
|
const toUser = await credits.findOne({
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
guildId: interaction.member.guild.id,
|
guildId: interaction.member.guild.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Stop if user has zero or below credits
|
// If toUser has no credits
|
||||||
|
|
||||||
if (!toUser) {
|
if (!toUser) {
|
||||||
|
// Create embed object
|
||||||
const embed = {
|
const embed = {
|
||||||
title: 'Take',
|
title: 'Take',
|
||||||
description:
|
description:
|
||||||
|
@ -61,38 +62,44 @@ module.exports = async (interaction) => {
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Send interaction reply
|
||||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decrease toUser with amount
|
// Withdraw amount from toUser
|
||||||
|
|
||||||
toUser.balance -= amount;
|
toUser.balance -= amount;
|
||||||
|
|
||||||
// Save toUser
|
// Save toUser
|
||||||
|
await toUser
|
||||||
|
.save()
|
||||||
|
|
||||||
await toUser.save().then(async () => {
|
// If successful
|
||||||
const embed = {
|
.then(async () => {
|
||||||
title: 'Take',
|
// Create embed object
|
||||||
description: `You took ${creditNoun(amount)} to ${user}.`,
|
const embed = {
|
||||||
color: 0x22bb33,
|
title: 'Take',
|
||||||
timestamp: new Date(),
|
description: `You took ${creditNoun(amount)} to ${user}.`,
|
||||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
color: 0x22bb33,
|
||||||
};
|
timestamp: new Date(),
|
||||||
await logger.debug(
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
`Administrator: ${interaction.user.username} took ${
|
};
|
||||||
amount <= 1 ? `${amount} credit` : `${amount} credits`
|
|
||||||
} from ${user.username}`
|
|
||||||
);
|
|
||||||
// Send reply
|
|
||||||
|
|
||||||
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
// Send debug message
|
||||||
|
await logger.debug(
|
||||||
|
`Administrator: ${interaction.user.username} took ${
|
||||||
|
amount <= 1 ? `${amount} credit` : `${amount} credits`
|
||||||
|
} from ${user.username}`
|
||||||
|
);
|
||||||
|
|
||||||
// Send debug message
|
// Send interaction reply
|
||||||
|
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||||
|
|
||||||
await logger.debug(
|
// Send debug message
|
||||||
`Guild: ${member.guild.id} User: ${member.id} took ${creditNoun(
|
await logger.debug(
|
||||||
amount
|
`Guild: ${member.guild.id} User: ${member.id} took ${creditNoun(
|
||||||
)} from ${user.id}.`
|
amount
|
||||||
);
|
)} from ${user.id}.`
|
||||||
});
|
);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -10,12 +10,11 @@ const saveUser = require('../../../../helpers/saveUser');
|
||||||
|
|
||||||
module.exports = async (interaction) => {
|
module.exports = async (interaction) => {
|
||||||
// Destructure member
|
// Destructure member
|
||||||
|
|
||||||
const { member } = interaction;
|
const { member } = interaction;
|
||||||
|
|
||||||
// Check permission
|
// Check permission
|
||||||
|
|
||||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||||
|
// Create embed object
|
||||||
const embed = {
|
const embed = {
|
||||||
title: 'Admin',
|
title: 'Admin',
|
||||||
color: config.colors.error,
|
color: config.colors.error,
|
||||||
|
@ -23,32 +22,31 @@ module.exports = async (interaction) => {
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Send interaction reply
|
||||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get options
|
// Get options
|
||||||
|
|
||||||
const from = await interaction.options.getUser('from');
|
const from = await interaction.options.getUser('from');
|
||||||
const to = await interaction.options.getUser('to');
|
const to = await interaction.options.getUser('to');
|
||||||
const amount = await interaction.options.getInteger('amount');
|
const amount = await interaction.options.getInteger('amount');
|
||||||
|
|
||||||
// Get fromUser object
|
// Get fromUser object
|
||||||
|
|
||||||
const fromUser = await credits.findOne({
|
const fromUser = await credits.findOne({
|
||||||
userId: from.id,
|
userId: from.id,
|
||||||
guildId: interaction.member.guild.id,
|
guildId: interaction.member.guild.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Get toUser object
|
// Get toUser object
|
||||||
|
|
||||||
const toUser = await credits.findOne({
|
const toUser = await credits.findOne({
|
||||||
userId: to.id,
|
userId: to.id,
|
||||||
guildId: interaction.member.guild.id,
|
guildId: interaction.member.guild.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Stop if fromUser has zero credits or below
|
// If fromUser has no credits
|
||||||
|
|
||||||
if (!fromUser) {
|
if (!fromUser) {
|
||||||
|
// Create embed object
|
||||||
const embed = {
|
const embed = {
|
||||||
title: 'Transfer',
|
title: 'Transfer',
|
||||||
description:
|
description:
|
||||||
|
@ -57,12 +55,14 @@ module.exports = async (interaction) => {
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Send interaction reply
|
||||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop if toUser has zero credits or below
|
// If toUser has no credits
|
||||||
|
|
||||||
if (!toUser) {
|
if (!toUser) {
|
||||||
|
// Create embed object
|
||||||
const embed = {
|
const embed = {
|
||||||
title: 'Transfer',
|
title: 'Transfer',
|
||||||
description:
|
description:
|
||||||
|
@ -71,12 +71,14 @@ module.exports = async (interaction) => {
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Send interaction reply
|
||||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop if amount is zero or below
|
// If amount is zero or below
|
||||||
|
|
||||||
if (amount <= 0) {
|
if (amount <= 0) {
|
||||||
|
// Create embed object
|
||||||
const embed = {
|
const embed = {
|
||||||
title: 'Transfer failed',
|
title: 'Transfer failed',
|
||||||
description: "You can't transfer zero or below.",
|
description: "You can't transfer zero or below.",
|
||||||
|
@ -84,48 +86,50 @@ module.exports = async (interaction) => {
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Send interaction reply
|
||||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decrease fromUser with amount
|
// Withdraw amount from fromUser
|
||||||
|
|
||||||
fromUser.balance -= amount;
|
fromUser.balance -= amount;
|
||||||
|
|
||||||
// Increase toUser with amount
|
// Deposit amount to toUser
|
||||||
|
|
||||||
toUser.balance += amount;
|
toUser.balance += amount;
|
||||||
|
|
||||||
await saveUser(fromUser, toUser).then(async () => {
|
// Save users
|
||||||
const embed = {
|
await saveUser(fromUser, toUser)
|
||||||
title: 'Transfer',
|
// If successful
|
||||||
description: `You sent ${creditNoun(amount)} from ${from} to ${to}.`,
|
.then(async () => {
|
||||||
color: 0x22bb33,
|
// Create embed object
|
||||||
fields: [
|
const embed = {
|
||||||
{
|
title: 'Transfer',
|
||||||
name: `${from.username} Balance`,
|
description: `You sent ${creditNoun(amount)} from ${from} to ${to}.`,
|
||||||
value: `${fromUser.balance}`,
|
color: 0x22bb33,
|
||||||
inline: true,
|
fields: [
|
||||||
},
|
{
|
||||||
{
|
name: `${from.username} Balance`,
|
||||||
name: `${to.username} Balance`,
|
value: `${fromUser.balance}`,
|
||||||
value: `${toUser.balance}`,
|
inline: true,
|
||||||
inline: true,
|
},
|
||||||
},
|
{
|
||||||
],
|
name: `${to.username} Balance`,
|
||||||
timestamp: new Date(),
|
value: `${toUser.balance}`,
|
||||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
inline: true,
|
||||||
};
|
},
|
||||||
|
],
|
||||||
|
timestamp: new Date(),
|
||||||
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
|
};
|
||||||
|
|
||||||
// Send reply
|
// Send interaction reply
|
||||||
|
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||||
|
|
||||||
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
// Send debug message
|
||||||
|
await logger.debug(
|
||||||
// Send debug message
|
`Guild: ${member.guild.id} User: ${member.id} transferred ${creditNoun(
|
||||||
|
amount
|
||||||
await logger.debug(
|
)} from ${from.id} to ${to.id}.`
|
||||||
`Guild: ${member.guild.id} User: ${member.id} transferred ${creditNoun(
|
);
|
||||||
amount
|
});
|
||||||
)} from ${from.id} to ${to.id}.`
|
|
||||||
);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,12 +6,11 @@ const { give, take, set, transfer } = require('./addons');
|
||||||
|
|
||||||
module.exports = async (interaction) => {
|
module.exports = async (interaction) => {
|
||||||
// Destructure member
|
// Destructure member
|
||||||
|
|
||||||
const { member } = interaction;
|
const { member } = interaction;
|
||||||
|
|
||||||
// Check permission
|
// Check permission
|
||||||
|
|
||||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||||
|
// Create embed object
|
||||||
const embed = {
|
const embed = {
|
||||||
title: 'Admin',
|
title: 'Admin',
|
||||||
color: config.colors.error,
|
color: config.colors.error,
|
||||||
|
@ -19,31 +18,36 @@ module.exports = async (interaction) => {
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Send interaction reply
|
||||||
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Command handler
|
// If subcommand is give
|
||||||
|
|
||||||
if (interaction.options.getSubcommand() === 'give') {
|
if (interaction.options.getSubcommand() === 'give') {
|
||||||
// Execute give addon
|
// Execute give addon
|
||||||
|
|
||||||
await give(interaction);
|
await give(interaction);
|
||||||
} else if (interaction.options.getSubcommand() === 'take') {
|
}
|
||||||
|
|
||||||
|
// If subcommand is take
|
||||||
|
else if (interaction.options.getSubcommand() === 'take') {
|
||||||
// Execute take addon
|
// Execute take addon
|
||||||
|
|
||||||
await take(interaction);
|
await take(interaction);
|
||||||
} else if (interaction.options.getSubcommand() === 'set') {
|
}
|
||||||
|
|
||||||
|
// If subcommand is set
|
||||||
|
else if (interaction.options.getSubcommand() === 'set') {
|
||||||
// Execute set addon
|
// Execute set addon
|
||||||
|
|
||||||
await set(interaction);
|
await set(interaction);
|
||||||
} else if (interaction.options.getSubcommand() === 'transfer') {
|
}
|
||||||
// Execute transfer addon
|
|
||||||
|
|
||||||
|
// If subcommand is transfer
|
||||||
|
else if (interaction.options.getSubcommand() === 'transfer') {
|
||||||
|
// Execute transfer addon
|
||||||
await transfer(interaction);
|
await transfer(interaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send debug message
|
// Send debug message
|
||||||
|
|
||||||
await logger.debug(
|
await logger.debug(
|
||||||
`Guild: ${member.guild.id} User: ${member.id} executed /${
|
`Guild: ${member.guild.id} User: ${member.id} executed /${
|
||||||
interaction.commandName
|
interaction.commandName
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
const { SlashCommandBuilder } = require('@discordjs/builders');
|
const { SlashCommandBuilder } = require('@discordjs/builders');
|
||||||
const { Permissions } = require('discord.js');
|
|
||||||
|
|
||||||
const credits = require('./credits');
|
const credits = require('./credits');
|
||||||
|
|
||||||
|
@ -87,9 +86,10 @@ module.exports = {
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
async execute(interaction) {
|
async execute(interaction) {
|
||||||
|
// If subcommand group is credits
|
||||||
if (interaction.options.getSubcommandGroup() === 'credits') {
|
if (interaction.options.getSubcommandGroup() === 'credits') {
|
||||||
|
// Execute credits group
|
||||||
await credits(interaction);
|
await credits(interaction);
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
const i18next = require('i18next');
|
|
||||||
const config = require('../../../../config.json');
|
const config = require('../../../../config.json');
|
||||||
const logger = require('../../../handlers/logger');
|
const logger = require('../../../handlers/logger');
|
||||||
|
|
||||||
|
@ -7,15 +6,21 @@ const creditNoun = require('../../../helpers/creditNoun');
|
||||||
|
|
||||||
module.exports = async (interaction) => {
|
module.exports = async (interaction) => {
|
||||||
try {
|
try {
|
||||||
|
// Get options
|
||||||
const user = await interaction.options.getUser('user');
|
const user = await interaction.options.getUser('user');
|
||||||
|
|
||||||
|
// Get credit object
|
||||||
await credits
|
await credits
|
||||||
.findOne({
|
.findOne({
|
||||||
userId: user ? user.id : interaction.user.id,
|
userId: user ? user.id : interaction.user.id,
|
||||||
guildId: interaction.member.guild.id,
|
guildId: interaction.member.guild.id,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// If successful
|
||||||
.then(async (data) => {
|
.then(async (data) => {
|
||||||
|
// If user has no credits
|
||||||
if (!data) {
|
if (!data) {
|
||||||
|
// Create embed object
|
||||||
const embed = {
|
const embed = {
|
||||||
title: 'Balance',
|
title: 'Balance',
|
||||||
description: `${user} has no credits.`,
|
description: `${user} has no credits.`,
|
||||||
|
@ -24,10 +29,14 @@ module.exports = async (interaction) => {
|
||||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Send interaction reply
|
||||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Destructure balance
|
||||||
const { balance } = data;
|
const { balance } = data;
|
||||||
|
|
||||||
|
// Create embed object
|
||||||
const embed = {
|
const embed = {
|
||||||
title: 'Balance',
|
title: 'Balance',
|
||||||
description: `${user ? `${user} has` : 'You have'} ${creditNoun(
|
description: `${user ? `${user} has` : 'You have'} ${creditNoun(
|
||||||
|
@ -37,10 +46,16 @@ module.exports = async (interaction) => {
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Send interaction reply
|
||||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||||
})
|
})
|
||||||
.catch(async (err) => logger.error(err));
|
.catch(async (e) => {
|
||||||
} catch {
|
// Send debug message
|
||||||
await logger.error();
|
await logger.error(e);
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
// Send debug message
|
||||||
|
await logger.error(e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
const i18next = require('i18next');
|
|
||||||
const config = require('../../../../config.json');
|
const config = require('../../../../config.json');
|
||||||
const logger = require('../../../handlers/logger');
|
const logger = require('../../../handlers/logger');
|
||||||
|
|
||||||
|
@ -8,16 +7,20 @@ const creditNoun = require('../../../helpers/creditNoun');
|
||||||
|
|
||||||
module.exports = async (interaction) => {
|
module.exports = async (interaction) => {
|
||||||
try {
|
try {
|
||||||
|
// Get options
|
||||||
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');
|
||||||
const reason = await interaction.options.getString('reason');
|
const reason = await interaction.options.getString('reason');
|
||||||
|
|
||||||
|
// Get data object
|
||||||
const data = await credits.findOne({
|
const data = await credits.findOne({
|
||||||
userId: interaction.user.id,
|
userId: interaction.user.id,
|
||||||
guildId: interaction.member.guild.id,
|
guildId: interaction.member.guild.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// If receiver is same as sender
|
||||||
if (user.id === interaction.user.id) {
|
if (user.id === interaction.user.id) {
|
||||||
|
// Create embed object
|
||||||
const embed = {
|
const embed = {
|
||||||
title: 'Gift',
|
title: 'Gift',
|
||||||
description: "You can't pay yourself.",
|
description: "You can't pay yourself.",
|
||||||
|
@ -25,9 +28,14 @@ module.exports = async (interaction) => {
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Send interaction reply
|
||||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If amount is zero or below
|
||||||
if (amount <= 0) {
|
if (amount <= 0) {
|
||||||
|
// Create embed object
|
||||||
const embed = {
|
const embed = {
|
||||||
title: 'Gift',
|
title: 'Gift',
|
||||||
description: "You can't pay zero or below.",
|
description: "You can't pay zero or below.",
|
||||||
|
@ -35,9 +43,14 @@ module.exports = async (interaction) => {
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Send interaction reply
|
||||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If user has below gifting amount
|
||||||
if (data.balance < amount) {
|
if (data.balance < amount) {
|
||||||
|
// Create embed
|
||||||
const embed = {
|
const embed = {
|
||||||
title: 'Gift',
|
title: 'Gift',
|
||||||
description: `You have insufficient credits. Your balance is ${data.balance}`,
|
description: `You have insufficient credits. Your balance is ${data.balance}`,
|
||||||
|
@ -45,19 +58,26 @@ module.exports = async (interaction) => {
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Send interaction reply
|
||||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line max-len
|
|
||||||
|
// Get fromUser object
|
||||||
const fromUser = await credits.findOne({
|
const fromUser = await credits.findOne({
|
||||||
userId: interaction.user.id,
|
userId: interaction.user.id,
|
||||||
guildId: interaction.member.guild.id,
|
guildId: interaction.member.guild.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Get toUser object
|
||||||
const toUser = await credits.findOne({
|
const toUser = await credits.findOne({
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
guildId: interaction.member.guild.id,
|
guildId: interaction.member.guild.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// If toUser has no credits
|
||||||
if (!toUser) {
|
if (!toUser) {
|
||||||
|
// Create embed object
|
||||||
const embed = {
|
const embed = {
|
||||||
title: 'Gift',
|
title: 'Gift',
|
||||||
description:
|
description:
|
||||||
|
@ -66,44 +86,62 @@ module.exports = async (interaction) => {
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Send interaction reply
|
||||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Withdraw amount from fromUser
|
||||||
fromUser.balance -= amount;
|
fromUser.balance -= amount;
|
||||||
|
|
||||||
|
// Deposit amount to toUser
|
||||||
toUser.balance += amount;
|
toUser.balance += amount;
|
||||||
|
|
||||||
await saveUser(fromUser, toUser);
|
// Save users
|
||||||
|
await saveUser(fromUser, toUser).then(async () => {
|
||||||
|
// Create interaction embed object
|
||||||
|
const interactionEmbed = {
|
||||||
|
title: 'Gift',
|
||||||
|
description: `You sent ${creditNoun(amount)} to ${user}${
|
||||||
|
reason ? ` with reason: ${reason}` : ''
|
||||||
|
}. Your new balance is ${creditNoun(fromUser.balance)}.`,
|
||||||
|
color: 0x22bb33,
|
||||||
|
timestamp: new Date(),
|
||||||
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
|
};
|
||||||
|
|
||||||
const interactionEmbed = {
|
// Create DM embed object
|
||||||
title: 'Gift',
|
const dmEmbed = {
|
||||||
description: `You sent ${creditNoun(amount)} to ${user}${
|
title: 'Gift',
|
||||||
reason ? ` with reason: ${reason}` : ''
|
description: `You received ${creditNoun(amount)} from ${
|
||||||
}. Your new balance is ${creditNoun(fromUser.balance)}.`,
|
interaction.user
|
||||||
color: 0x22bb33,
|
}${
|
||||||
timestamp: new Date(),
|
reason ? ` with reason: ${reason}` : ''
|
||||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
}. Your new balance is ${creditNoun(toUser.balance)}.`,
|
||||||
};
|
color: 0x22bb33,
|
||||||
const dmEmbed = {
|
timestamp: new Date(),
|
||||||
title: 'Gift',
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
description: `You received ${creditNoun(amount)} from ${
|
};
|
||||||
interaction.user
|
|
||||||
}${
|
// Get DM user object
|
||||||
reason ? ` with reason: ${reason}` : ''
|
const dmUser = await interaction.client.users.cache.get(user.id);
|
||||||
}. Your new balance is ${creditNoun(toUser.balance)}.`,
|
|
||||||
color: 0x22bb33,
|
// Send DM to user
|
||||||
timestamp: new Date(),
|
await dmUser.send({ embeds: [dmEmbed] });
|
||||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
|
||||||
};
|
// Send debug message
|
||||||
const dmUser = await interaction.client.users.cache.get(user.id);
|
await logger.debug(
|
||||||
await dmUser.send({ embeds: [dmEmbed] });
|
`Gift sent from: ${interaction.user.username} to: ${user.username}`
|
||||||
await logger.debug(
|
);
|
||||||
`Gift sent from: ${interaction.user.username} to: ${user.username}`
|
|
||||||
);
|
// Send interaction reply
|
||||||
return await interaction.editReply({
|
return await interaction.editReply({
|
||||||
embeds: [interactionEmbed],
|
embeds: [interactionEmbed],
|
||||||
ephemeral: true,
|
ephemeral: true,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
// Send debug message
|
||||||
await logger.error(e);
|
await logger.error(e);
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
};
|
};
|
||||||
|
|
6
src/commands/credits/addons/index.js
Normal file
6
src/commands/credits/addons/index.js
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
const balance = require('./balance');
|
||||||
|
const gift = require('./gift');
|
||||||
|
const top = require('./top');
|
||||||
|
const work = require('./work');
|
||||||
|
|
||||||
|
module.exports = { balance, gift, top, work };
|
|
@ -1,135 +0,0 @@
|
||||||
const { v4: uuidv4 } = require('uuid');
|
|
||||||
const axios = require('axios');
|
|
||||||
const config = require('../../../../config.json');
|
|
||||||
const logger = require('../../../handlers/logger');
|
|
||||||
|
|
||||||
const { guilds, credits, apis } = require('../../../helpers/database/models');
|
|
||||||
const creditNoun = require('../../../helpers/creditNoun');
|
|
||||||
|
|
||||||
// const api = require('../../../handlers/api');
|
|
||||||
|
|
||||||
module.exports = async (interaction) => {
|
|
||||||
try {
|
|
||||||
if (config.disable.redeem) {
|
|
||||||
const embed = {
|
|
||||||
title: 'Redeem failed',
|
|
||||||
description: 'Redeem is disabled until further.',
|
|
||||||
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 amount = await interaction.options.getInteger('amount');
|
|
||||||
|
|
||||||
// eslint-disable-next-line max-len
|
|
||||||
const user = await credits.findOne({
|
|
||||||
userId: interaction.user.id,
|
|
||||||
guildId: interaction.member.guild.id,
|
|
||||||
});
|
|
||||||
const dmUser = interaction.client.users.cache.get(
|
|
||||||
interaction.member.user.id
|
|
||||||
);
|
|
||||||
|
|
||||||
if ((amount || user.balance) < 100) {
|
|
||||||
const embed = {
|
|
||||||
title: 'Redeem',
|
|
||||||
description: `You can't redeem below 100. Your balance is ${user.balance}.`,
|
|
||||||
color: config.colors.error,
|
|
||||||
timestamp: new Date(),
|
|
||||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
|
||||||
};
|
|
||||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
|
||||||
}
|
|
||||||
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,
|
|
||||||
timestamp: new Date(),
|
|
||||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
|
||||||
};
|
|
||||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
|
||||||
}
|
|
||||||
if (user.balance < amount) {
|
|
||||||
const embed = {
|
|
||||||
title: 'Redeem',
|
|
||||||
description: `You have insufficient credits. Your balance is ${user.balance}.`,
|
|
||||||
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();
|
|
||||||
|
|
||||||
const apiCredentials = await apis.findOne({
|
|
||||||
guildId: interaction.member.guild.id,
|
|
||||||
});
|
|
||||||
|
|
||||||
const api = axios.create({
|
|
||||||
baseURL: apiCredentials.url,
|
|
||||||
headers: { Authorization: `Bearer ${apiCredentials.token}` },
|
|
||||||
});
|
|
||||||
|
|
||||||
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 (e) => {
|
|
||||||
await logger.error(e);
|
|
||||||
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 (e) {
|
|
||||||
await logger.error(e);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
};
|
|
|
@ -3,25 +3,37 @@ const credits = require('../../../helpers/database/models/creditSchema');
|
||||||
const creditNoun = require('../../../helpers/creditNoun');
|
const creditNoun = require('../../../helpers/creditNoun');
|
||||||
|
|
||||||
module.exports = async (interaction) => {
|
module.exports = async (interaction) => {
|
||||||
|
// Get all users in the guild
|
||||||
await credits
|
await credits
|
||||||
.find({ guildId: interaction.member.guild.id })
|
.find({ guildId: interaction.member.guild.id })
|
||||||
|
|
||||||
|
// If successful
|
||||||
.then(async (data) => {
|
.then(async (data) => {
|
||||||
|
// Get top ten
|
||||||
const topTen = data
|
const topTen = data
|
||||||
|
|
||||||
|
// Sort them after balance amount (ascending)
|
||||||
.sort((a, b) => (a.balance > b.balance ? -1 : 1))
|
.sort((a, b) => (a.balance > b.balance ? -1 : 1))
|
||||||
|
|
||||||
|
// Return the top 10
|
||||||
.slice(0, 10);
|
.slice(0, 10);
|
||||||
|
|
||||||
const item = (x, index) =>
|
// Create entry object
|
||||||
|
const entry = (x, index) =>
|
||||||
`**Top ${index + 1}** - <@${x.userId}> ${creditNoun(x.balance)}`;
|
`**Top ${index + 1}** - <@${x.userId}> ${creditNoun(x.balance)}`;
|
||||||
|
|
||||||
|
// Create embed object
|
||||||
const embed = {
|
const embed = {
|
||||||
title: 'Balance Top',
|
title: 'Balance Top',
|
||||||
description: `Below are the top ten.\n${topTen
|
description: `Below are the top ten.\n${topTen
|
||||||
.map((x, index) => item(x, index))
|
.map((x, index) => entry(x, index))
|
||||||
.join('\n')}`,
|
.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 },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Send interaction reply
|
||||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,14 +7,11 @@ const {
|
||||||
} = require('../../../helpers/database/models');
|
} = require('../../../helpers/database/models');
|
||||||
const creditNoun = require('../../../helpers/creditNoun');
|
const creditNoun = require('../../../helpers/creditNoun');
|
||||||
|
|
||||||
const workedRecently = new Set();
|
|
||||||
|
|
||||||
// eslint-disable-next-line consistent-return
|
|
||||||
module.exports = async (interaction) => {
|
module.exports = async (interaction) => {
|
||||||
|
// Destructure member
|
||||||
const { member } = interaction;
|
const { member } = interaction;
|
||||||
|
|
||||||
// Check if user has a timeout
|
// Check if user has a timeout
|
||||||
|
|
||||||
const isTimeout = await timeouts.findOne({
|
const isTimeout = await timeouts.findOne({
|
||||||
guildId: member.guild.id,
|
guildId: member.guild.id,
|
||||||
userId: member.id,
|
userId: member.id,
|
||||||
|
@ -22,13 +19,15 @@ module.exports = async (interaction) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// If user is not on timeout
|
// If user is not on timeout
|
||||||
|
|
||||||
if (!isTimeout) {
|
if (!isTimeout) {
|
||||||
const guild = await guilds.findOne({
|
const guild = await guilds.findOne({
|
||||||
guildId: interaction.member.guild.id,
|
guildId: interaction.member.guild.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Make a variable of how much credits user will earn based on random multiplied with work rate
|
||||||
const creditsEarned = Math.floor(Math.random() * guild.credits.workRate);
|
const creditsEarned = Math.floor(Math.random() * guild.credits.workRate);
|
||||||
|
|
||||||
|
// Add credits to user
|
||||||
await credits
|
await credits
|
||||||
.findOneAndUpdate(
|
.findOneAndUpdate(
|
||||||
{
|
{
|
||||||
|
@ -38,8 +37,13 @@ module.exports = async (interaction) => {
|
||||||
{ $inc: { balance: creditsEarned } },
|
{ $inc: { balance: creditsEarned } },
|
||||||
{ new: true, upsert: true }
|
{ new: true, upsert: true }
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// If successful
|
||||||
.then(async () => {
|
.then(async () => {
|
||||||
|
// Send debug message
|
||||||
logger.debug(`Credits added to user: ${interaction.member.id}`);
|
logger.debug(`Credits added to user: ${interaction.member.id}`);
|
||||||
|
|
||||||
|
// Create embed object
|
||||||
const embed = {
|
const embed = {
|
||||||
title: 'Work',
|
title: 'Work',
|
||||||
description: `You earned ${creditNoun(creditsEarned)}`,
|
description: `You earned ${creditNoun(creditsEarned)}`,
|
||||||
|
@ -48,11 +52,11 @@ module.exports = async (interaction) => {
|
||||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Send interaction reply
|
||||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||||
});
|
});
|
||||||
|
|
||||||
// Create a timeout for the user
|
// Create a timeout for the user
|
||||||
|
|
||||||
await timeouts.create({
|
await timeouts.create({
|
||||||
guildId: member.guild.id,
|
guildId: member.guild.id,
|
||||||
userId: member.id,
|
userId: member.id,
|
||||||
|
@ -60,6 +64,7 @@ module.exports = async (interaction) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
|
// Send debug message
|
||||||
await logger.debug(
|
await logger.debug(
|
||||||
`Guild: ${member.guild.id} User: ${
|
`Guild: ${member.guild.id} User: ${
|
||||||
member.id
|
member.id
|
||||||
|
@ -69,7 +74,6 @@ module.exports = async (interaction) => {
|
||||||
);
|
);
|
||||||
|
|
||||||
// When timeout is out, remove it from the database
|
// When timeout is out, remove it from the database
|
||||||
|
|
||||||
await timeouts.deleteOne({
|
await timeouts.deleteOne({
|
||||||
guildId: member.guild.id,
|
guildId: member.guild.id,
|
||||||
userId: member.id,
|
userId: member.id,
|
||||||
|
@ -77,6 +81,7 @@ module.exports = async (interaction) => {
|
||||||
});
|
});
|
||||||
}, 86400000);
|
}, 86400000);
|
||||||
} else {
|
} else {
|
||||||
|
// Create embed object
|
||||||
const embed = {
|
const embed = {
|
||||||
title: 'Work',
|
title: 'Work',
|
||||||
description: `You have worked within the last ${
|
description: `You have worked within the last ${
|
||||||
|
@ -87,8 +92,10 @@ module.exports = async (interaction) => {
|
||||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Send interaction reply
|
||||||
await interaction.editReply({ embeds: [embed] });
|
await interaction.editReply({ embeds: [embed] });
|
||||||
|
|
||||||
|
// Send debug message
|
||||||
await logger.debug(
|
await logger.debug(
|
||||||
`Guild: ${member.guild.id} User: ${member.id} has worked within last day, no work can be done`
|
`Guild: ${member.guild.id} User: ${member.id} has worked within last day, no work can be done`
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,14 +1,6 @@
|
||||||
const { SlashCommandBuilder } = require('@discordjs/builders');
|
const { SlashCommandBuilder } = require('@discordjs/builders');
|
||||||
const { Permissions } = require('discord.js');
|
|
||||||
|
|
||||||
const config = require('../../../config.json');
|
const { balance, gift, top, work } = require('./addons');
|
||||||
const guilds = require('../../helpers/database/models/guildSchema');
|
|
||||||
|
|
||||||
const balance = require('./addons/balance');
|
|
||||||
const gift = require('./addons/gift');
|
|
||||||
const redeem = require('./addons/redeem');
|
|
||||||
const top = require('./addons/top');
|
|
||||||
const work = require('./addons/work');
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
|
@ -25,16 +17,6 @@ module.exports = {
|
||||||
.setRequired(false)
|
.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) =>
|
.addSubcommand((subcommand) =>
|
||||||
subcommand
|
subcommand
|
||||||
.setName('gift')
|
.setName('gift')
|
||||||
|
@ -62,35 +44,28 @@ module.exports = {
|
||||||
subcommand.setName('work').setDescription('Work for credits.')
|
subcommand.setName('work').setDescription('Work for credits.')
|
||||||
),
|
),
|
||||||
async execute(interaction) {
|
async execute(interaction) {
|
||||||
const guild = await guilds.findOne({
|
// If subcommand is balance
|
||||||
guildId: interaction.member.guild.id,
|
if (interaction.options.getSubcommand() === 'balance') {
|
||||||
});
|
// Execute balance addon
|
||||||
|
await balance(interaction);
|
||||||
if (
|
|
||||||
guild.credits.status === false &&
|
|
||||||
interaction.options.getSubcommand() !== 'settings'
|
|
||||||
) {
|
|
||||||
const embed = {
|
|
||||||
title: 'Credits',
|
|
||||||
description: 'Please enable credits by ``/credits settings``',
|
|
||||||
color: config.colors.error,
|
|
||||||
timestamp: new Date(),
|
|
||||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
|
||||||
};
|
|
||||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (interaction.options.getSubcommand() === 'balance') {
|
// If subcommand is gift
|
||||||
await balance(interaction);
|
else if (interaction.options.getSubcommand() === 'gift') {
|
||||||
} else if (interaction.options.getSubcommand() === 'gift') {
|
// Execute gift addon
|
||||||
await gift(interaction);
|
await gift(interaction);
|
||||||
} else if (interaction.options.getSubcommand() === 'redeem') {
|
}
|
||||||
await redeem(interaction);
|
|
||||||
} else if (interaction.options.getSubcommand() === 'top') {
|
// If subcommand is top
|
||||||
|
else if (interaction.options.getSubcommand() === 'top') {
|
||||||
|
// Execute top addon
|
||||||
await top(interaction);
|
await top(interaction);
|
||||||
} else if (interaction.options.getSubcommand() === 'work') {
|
}
|
||||||
|
|
||||||
|
// If subcommand is work
|
||||||
|
else if (interaction.options.getSubcommand() === 'work') {
|
||||||
|
// Execute work addon
|
||||||
await work(interaction);
|
await work(interaction);
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -10,32 +10,35 @@ const {
|
||||||
|
|
||||||
module.exports = async (interaction) => {
|
module.exports = async (interaction) => {
|
||||||
try {
|
try {
|
||||||
|
// Destructure member
|
||||||
const { member } = await interaction;
|
const { member } = await interaction;
|
||||||
|
|
||||||
// Options
|
// Get options
|
||||||
const target = await interaction.options.getUser('target');
|
const target = await interaction.options.getUser('target');
|
||||||
|
|
||||||
|
// Get discord user object
|
||||||
const discordUser = await interaction.client.users.fetch(
|
const discordUser = await interaction.client.users.fetch(
|
||||||
`${target ? target.id : member.id}`
|
`${target ? target.id : member.id}`
|
||||||
);
|
);
|
||||||
|
|
||||||
// Databases
|
// Get user object
|
||||||
// Fetch user from user
|
|
||||||
const user = await users.findOne({ userId: await discordUser.id });
|
const user = await users.findOne({ userId: await discordUser.id });
|
||||||
|
|
||||||
// Fetch credit from user and guild
|
// Get experience object
|
||||||
const experience = await experiences.findOne({
|
const experience = await experiences.findOne({
|
||||||
userId: await discordUser.id,
|
userId: await discordUser.id,
|
||||||
guildId: await member.guild.id,
|
guildId: await member.guild.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Fetch credit from user and guild
|
// Get credit object
|
||||||
const credit = await credits.findOne({
|
const credit = await credits.findOne({
|
||||||
userId: await discordUser.id,
|
userId: await discordUser.id,
|
||||||
guildId: await member.guild.id,
|
guildId: await member.guild.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// If any of the objects return is null
|
||||||
if (user === null || experience === null || credit === null) {
|
if (user === null || experience === null || credit === null) {
|
||||||
|
// Create embed object
|
||||||
const embed = {
|
const embed = {
|
||||||
title: 'Profile',
|
title: 'Profile',
|
||||||
description: `${
|
description: `${
|
||||||
|
@ -48,6 +51,7 @@ module.exports = async (interaction) => {
|
||||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Send interaction reply
|
||||||
return await interaction.editReply({ embeds: [embed] });
|
return await interaction.editReply({ embeds: [embed] });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,7 +84,7 @@ module.exports = async (interaction) => {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create embed
|
// Create embed object
|
||||||
const embed = {
|
const embed = {
|
||||||
author: {
|
author: {
|
||||||
name: `${await discordUser.username}#${await discordUser.discriminator}`,
|
name: `${await discordUser.username}#${await discordUser.discriminator}`,
|
||||||
|
@ -118,10 +122,10 @@ module.exports = async (interaction) => {
|
||||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
};
|
};
|
||||||
|
|
||||||
// Send reply
|
// Send interaction reply
|
||||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
// Send debug message
|
||||||
await logger.error(e);
|
await logger.error(e);
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -17,9 +17,10 @@ module.exports = {
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
async execute(interaction) {
|
async execute(interaction) {
|
||||||
|
// If subcommand is view
|
||||||
if (interaction.options.getSubcommand() === 'view') {
|
if (interaction.options.getSubcommand() === 'view') {
|
||||||
|
// Execute view addon
|
||||||
await view(interaction);
|
await view(interaction);
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,20 +6,16 @@ const { users, timeouts } = require('../../../helpers/database/models');
|
||||||
|
|
||||||
module.exports = async (interaction) => {
|
module.exports = async (interaction) => {
|
||||||
// Destructure member
|
// Destructure member
|
||||||
|
|
||||||
const { member } = interaction;
|
const { member } = interaction;
|
||||||
|
|
||||||
// Get options
|
// Get options
|
||||||
|
|
||||||
const target = await interaction.options.getUser('target');
|
const target = await interaction.options.getUser('target');
|
||||||
const type = await interaction.options.getString('type');
|
const type = await interaction.options.getString('type');
|
||||||
|
|
||||||
// Get user object
|
// Get user object
|
||||||
|
|
||||||
const user = await users.findOne({ userId: interaction.member.id });
|
const user = await users.findOne({ userId: interaction.member.id });
|
||||||
|
|
||||||
// Check if user has a timeout
|
// Check if user has a timeout
|
||||||
|
|
||||||
const isTimeout = await timeouts.findOne({
|
const isTimeout = await timeouts.findOne({
|
||||||
guildId: member.guild.id,
|
guildId: member.guild.id,
|
||||||
userId: member.id,
|
userId: member.id,
|
||||||
|
@ -27,13 +23,10 @@ module.exports = async (interaction) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// If user is not on timeout
|
// If user is not on timeout
|
||||||
|
|
||||||
if (!isTimeout) {
|
if (!isTimeout) {
|
||||||
// Do not allow self reputation
|
// Do not allow self reputation
|
||||||
|
|
||||||
if (target.id === interaction.member.id) {
|
if (target.id === interaction.member.id) {
|
||||||
// Build embed
|
// Create embed object
|
||||||
|
|
||||||
const embed = {
|
const embed = {
|
||||||
title: i18next.t(
|
title: i18next.t(
|
||||||
'commands:reputation:addons:give:version03:embed:title',
|
'commands:reputation:addons:give:version03:embed:title',
|
||||||
|
@ -49,71 +42,66 @@ module.exports = async (interaction) => {
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Send reply
|
// Send interaction reply
|
||||||
|
|
||||||
return interaction.editReply({ embeds: [embed] });
|
return interaction.editReply({ embeds: [embed] });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Math operators depending on type of reputation
|
// If type is positive
|
||||||
|
|
||||||
if (type === 'positive') {
|
if (type === 'positive') {
|
||||||
user.reputation += 1;
|
user.reputation += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If type is negative
|
||||||
if (type === 'negative') {
|
if (type === 'negative') {
|
||||||
user.reputation -= 1;
|
user.reputation -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save user
|
// Save user
|
||||||
|
await user.save().then(async () => {
|
||||||
|
// Create embed object
|
||||||
|
const embed = {
|
||||||
|
title: i18next.t(
|
||||||
|
'commands:reputation:addons:give:version02:embed:title',
|
||||||
|
{
|
||||||
|
lng: await user.language,
|
||||||
|
}
|
||||||
|
),
|
||||||
|
description: i18next.t(
|
||||||
|
'commands:reputation:addons:give:version02:embed:description',
|
||||||
|
{
|
||||||
|
lng: await user.language,
|
||||||
|
user: target,
|
||||||
|
type,
|
||||||
|
}
|
||||||
|
),
|
||||||
|
timestamp: new Date(),
|
||||||
|
color: config.colors.success,
|
||||||
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
|
};
|
||||||
|
|
||||||
await user.save();
|
// Send interaction reply
|
||||||
|
await interaction.editReply({ embeds: [embed] });
|
||||||
|
|
||||||
// Build embed
|
// Send debug message
|
||||||
|
await logger.debug(
|
||||||
|
`Guild: ${member.guild.id} User: ${member.id} has given ${target.id} a ${type} reputation.`
|
||||||
|
);
|
||||||
|
|
||||||
const embed = {
|
// Create a timeout for the user
|
||||||
title: i18next.t(
|
await timeouts.create({
|
||||||
'commands:reputation:addons:give:version02:embed:title',
|
guildId: member.guild.id,
|
||||||
{
|
userId: member.id,
|
||||||
lng: await user.language,
|
timeoutId: 2,
|
||||||
}
|
});
|
||||||
),
|
|
||||||
description: i18next.t(
|
|
||||||
'commands:reputation:addons:give:version02:embed:description',
|
|
||||||
{
|
|
||||||
lng: await user.language,
|
|
||||||
user: target,
|
|
||||||
type,
|
|
||||||
}
|
|
||||||
),
|
|
||||||
timestamp: new Date(),
|
|
||||||
color: config.colors.success,
|
|
||||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
|
||||||
};
|
|
||||||
|
|
||||||
// Send reply
|
|
||||||
|
|
||||||
await interaction.editReply({ embeds: [embed] });
|
|
||||||
|
|
||||||
// Send debug message
|
|
||||||
|
|
||||||
await logger.debug(
|
|
||||||
`Guild: ${member.guild.id} User: ${member.id} has given ${target.id} a ${type} reputation.`
|
|
||||||
);
|
|
||||||
|
|
||||||
// Create a timeout for the user
|
|
||||||
|
|
||||||
await timeouts.create({
|
|
||||||
guildId: member.guild.id,
|
|
||||||
userId: member.id,
|
|
||||||
timeoutId: 2,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
|
// send debug message
|
||||||
await logger.debug(
|
await logger.debug(
|
||||||
`Guild: ${member.guild.id} User: ${member.id} has not repute within last day, reputation can be given`
|
`Guild: ${member.guild.id} User: ${member.id} has not repute within last day, reputation can be given`
|
||||||
);
|
);
|
||||||
|
|
||||||
// When timeout is out, remove it from the database
|
// When timeout is out, remove it from the database
|
||||||
|
|
||||||
await timeouts.deleteOne({
|
await timeouts.deleteOne({
|
||||||
guildId: member.guild.id,
|
guildId: member.guild.id,
|
||||||
userId: member.id,
|
userId: member.id,
|
||||||
|
@ -121,6 +109,7 @@ module.exports = async (interaction) => {
|
||||||
});
|
});
|
||||||
}, 86400000);
|
}, 86400000);
|
||||||
} else {
|
} else {
|
||||||
|
// Create embed object
|
||||||
const embed = {
|
const embed = {
|
||||||
title: i18next.t(
|
title: i18next.t(
|
||||||
'commands:reputation:addons:give:version01:embed:title',
|
'commands:reputation:addons:give:version01:embed:title',
|
||||||
|
@ -139,8 +128,10 @@ module.exports = async (interaction) => {
|
||||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Send interaction reply
|
||||||
await interaction.editReply({ embeds: [embed] });
|
await interaction.editReply({ embeds: [embed] });
|
||||||
|
|
||||||
|
// Send debug message
|
||||||
await logger.debug(
|
await logger.debug(
|
||||||
`Guild: ${member.guild.id} User: ${member.id} has repute within last day, no reputation can be given`
|
`Guild: ${member.guild.id} User: ${member.id} has repute within last day, no reputation can be given`
|
||||||
);
|
);
|
||||||
|
|
|
@ -29,18 +29,15 @@ module.exports = {
|
||||||
),
|
),
|
||||||
async execute(interaction) {
|
async execute(interaction) {
|
||||||
// Destructure member
|
// Destructure member
|
||||||
|
|
||||||
const { member } = interaction;
|
const { member } = interaction;
|
||||||
|
|
||||||
// Command handler
|
// If subcommand is give
|
||||||
|
|
||||||
if (interaction.options.getSubcommand() === 'give') {
|
if (interaction.options.getSubcommand() === 'give') {
|
||||||
// Execute give addon
|
// Execute give addon
|
||||||
|
|
||||||
await give(interaction);
|
await give(interaction);
|
||||||
}
|
}
|
||||||
// Send debug message
|
|
||||||
|
|
||||||
|
// Send debug message
|
||||||
await logger.debug(
|
await logger.debug(
|
||||||
`Guild: ${member.guild.id} User: ${member.id} executed /${
|
`Guild: ${member.guild.id} User: ${member.id} executed /${
|
||||||
interaction.commandName
|
interaction.commandName
|
||||||
|
|
|
@ -3,29 +3,28 @@ const config = require('../../../../../config.json');
|
||||||
const logger = require('../../../../handlers/logger');
|
const logger = require('../../../../handlers/logger');
|
||||||
|
|
||||||
// Database models
|
// Database models
|
||||||
|
|
||||||
const { guilds } = require('../../../../helpers/database/models');
|
const { guilds } = require('../../../../helpers/database/models');
|
||||||
|
|
||||||
module.exports = async (interaction) => {
|
module.exports = async (interaction) => {
|
||||||
// Destructure member
|
// Destructure member
|
||||||
|
|
||||||
const { member } = interaction;
|
const { member } = interaction;
|
||||||
|
|
||||||
// Check permission
|
// Check permission
|
||||||
|
|
||||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||||
|
// Create embed object
|
||||||
const embed = {
|
const embed = {
|
||||||
title: 'Settings',
|
title: 'Settings',
|
||||||
color: config.colors.error,
|
color: config.colors.error,
|
||||||
description: 'You do not have permission to manage this!',
|
description: `You don't have permission to manage this!`,
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Send interaction reply
|
||||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get options
|
// Get options
|
||||||
|
|
||||||
const status = await interaction.options.getBoolean('status');
|
const status = await interaction.options.getBoolean('status');
|
||||||
const rate = await interaction.options.getNumber('rate');
|
const rate = await interaction.options.getNumber('rate');
|
||||||
const timeout = await interaction.options.getNumber('timeout');
|
const timeout = await interaction.options.getNumber('timeout');
|
||||||
|
@ -34,11 +33,9 @@ module.exports = async (interaction) => {
|
||||||
const workTimeout = await interaction.options.getNumber('work-timeout');
|
const workTimeout = await interaction.options.getNumber('work-timeout');
|
||||||
|
|
||||||
// Get guild object
|
// Get guild object
|
||||||
|
|
||||||
const guild = await guilds.findOne({ guildId: interaction.member.guild.id });
|
const guild = await guilds.findOne({ guildId: interaction.member.guild.id });
|
||||||
|
|
||||||
// Modify values
|
// Modify values
|
||||||
|
|
||||||
guild.credits.status = status !== null ? status : guild.credits.status;
|
guild.credits.status = status !== null ? status : guild.credits.status;
|
||||||
guild.credits.rate = rate !== null ? rate : guild.credits.rate;
|
guild.credits.rate = rate !== null ? rate : guild.credits.rate;
|
||||||
guild.credits.timeout = timeout !== null ? timeout : guild.credits.timeout;
|
guild.credits.timeout = timeout !== null ? timeout : guild.credits.timeout;
|
||||||
|
@ -50,10 +47,8 @@ module.exports = async (interaction) => {
|
||||||
minimumLength !== null ? minimumLength : guild.credits.minimumLength;
|
minimumLength !== null ? minimumLength : guild.credits.minimumLength;
|
||||||
|
|
||||||
// Save guild
|
// Save guild
|
||||||
|
|
||||||
await guild.save().then(async () => {
|
await guild.save().then(async () => {
|
||||||
// Build embed
|
// Create embed object
|
||||||
|
|
||||||
const embed = {
|
const embed = {
|
||||||
title: 'Credits',
|
title: 'Credits',
|
||||||
description: 'Following settings is set!',
|
description: 'Following settings is set!',
|
||||||
|
@ -82,12 +77,10 @@ module.exports = async (interaction) => {
|
||||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
};
|
};
|
||||||
|
|
||||||
// Send reply
|
// Send interaction reply
|
||||||
|
|
||||||
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||||
|
|
||||||
// Send debug message
|
// Send debug message
|
||||||
|
|
||||||
await logger.debug(
|
await logger.debug(
|
||||||
`Guild: ${member.guild.id} User: ${member.id} has changed credit details.`
|
`Guild: ${member.guild.id} User: ${member.id} has changed credit details.`
|
||||||
);
|
);
|
||||||
|
|
|
@ -8,12 +8,11 @@ const { apis } = require('../../../../helpers/database/models');
|
||||||
|
|
||||||
module.exports = async (interaction) => {
|
module.exports = async (interaction) => {
|
||||||
// Destructure member
|
// Destructure member
|
||||||
|
|
||||||
const { member } = interaction;
|
const { member } = interaction;
|
||||||
|
|
||||||
// Check permission
|
// Check permission
|
||||||
|
|
||||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||||
|
// Create embed object
|
||||||
const embed = {
|
const embed = {
|
||||||
title: 'Settings',
|
title: 'Settings',
|
||||||
color: config.colors.error,
|
color: config.colors.error,
|
||||||
|
@ -21,6 +20,8 @@ module.exports = async (interaction) => {
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Send interaction reply
|
||||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,12 +6,11 @@ const { pterodactyl, credits } = require('./addons');
|
||||||
|
|
||||||
module.exports = async (interaction) => {
|
module.exports = async (interaction) => {
|
||||||
// Destructure member
|
// Destructure member
|
||||||
|
|
||||||
const { member } = interaction;
|
const { member } = interaction;
|
||||||
|
|
||||||
// Check permission
|
// Check permission
|
||||||
|
|
||||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||||
|
// Create embed object
|
||||||
const embed = {
|
const embed = {
|
||||||
title: 'Settings',
|
title: 'Settings',
|
||||||
color: config.colors.error,
|
color: config.colors.error,
|
||||||
|
@ -19,23 +18,24 @@ module.exports = async (interaction) => {
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Send interaction reply
|
||||||
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Command handler
|
// If subcommand is pterodactyl
|
||||||
|
|
||||||
if (interaction.options.getSubcommand() === 'pterodactyl') {
|
if (interaction.options.getSubcommand() === 'pterodactyl') {
|
||||||
// Execute pterodactyl addon
|
// Execute pterodactyl addon
|
||||||
|
|
||||||
await pterodactyl(interaction);
|
await pterodactyl(interaction);
|
||||||
} else if (interaction.options.getSubcommand() === 'credits') {
|
}
|
||||||
// Execute credits addon
|
|
||||||
|
|
||||||
|
// If subcommand is credits
|
||||||
|
else if (interaction.options.getSubcommand() === 'credits') {
|
||||||
|
// Execute credits addon
|
||||||
await credits(interaction);
|
await credits(interaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send debug message
|
// Send debug message
|
||||||
|
|
||||||
await logger.debug(
|
await logger.debug(
|
||||||
`Guild: ${member.guild.id} User: ${member.id} executed /${
|
`Guild: ${member.guild.id} User: ${member.id} executed /${
|
||||||
interaction.commandName
|
interaction.commandName
|
||||||
|
|
|
@ -87,11 +87,15 @@ module.exports = {
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
async execute(interaction) {
|
async execute(interaction) {
|
||||||
|
// If subcommand group is guild
|
||||||
if (interaction.options.getSubcommandGroup() === 'guild') {
|
if (interaction.options.getSubcommandGroup() === 'guild') {
|
||||||
|
// Execute guild group
|
||||||
await guild(interaction);
|
await guild(interaction);
|
||||||
} else if (interaction.options.getSubcommandGroup() === 'user') {
|
}
|
||||||
|
// If subcommand group is user
|
||||||
|
else if (interaction.options.getSubcommandGroup() === 'user') {
|
||||||
|
// Execute user group
|
||||||
await user(interaction);
|
await user(interaction);
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,33 +1,25 @@
|
||||||
const { Permissions } = require('discord.js');
|
|
||||||
const config = require('../../../../../config.json');
|
const config = require('../../../../../config.json');
|
||||||
const logger = require('../../../../handlers/logger');
|
const logger = require('../../../../handlers/logger');
|
||||||
|
|
||||||
// Database models
|
// Database models
|
||||||
|
|
||||||
const { users } = require('../../../../helpers/database/models');
|
const { users } = require('../../../../helpers/database/models');
|
||||||
|
|
||||||
module.exports = async (interaction) => {
|
module.exports = async (interaction) => {
|
||||||
// Destructure member
|
// Destructure member
|
||||||
|
|
||||||
const { member } = interaction;
|
const { member } = interaction;
|
||||||
|
|
||||||
// Get options
|
// Get options
|
||||||
|
|
||||||
const language = await interaction.options.getString('language');
|
const language = await interaction.options.getString('language');
|
||||||
|
|
||||||
// Get user object
|
// Get user object
|
||||||
|
|
||||||
const user = await users.findOne({ userId: interaction.member.id });
|
const user = await users.findOne({ userId: interaction.member.id });
|
||||||
|
|
||||||
// Modify values
|
// Modify values
|
||||||
|
|
||||||
user.language = language !== null ? language : user.language;
|
user.language = language !== null ? language : user.language;
|
||||||
|
|
||||||
// Save guild
|
// Save guild
|
||||||
|
|
||||||
await user.save().then(async () => {
|
await user.save().then(async () => {
|
||||||
// Build embed
|
// Create embed object
|
||||||
|
|
||||||
const embed = {
|
const embed = {
|
||||||
title: 'Appearance',
|
title: 'Appearance',
|
||||||
description: 'Following settings is set!',
|
description: 'Following settings is set!',
|
||||||
|
@ -43,12 +35,10 @@ module.exports = async (interaction) => {
|
||||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
};
|
};
|
||||||
|
|
||||||
// Send reply
|
// Send interaction reply
|
||||||
|
|
||||||
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||||
|
|
||||||
// Send debug message
|
// Send debug message
|
||||||
|
|
||||||
await logger.debug(
|
await logger.debug(
|
||||||
`Guild: ${member.guild.id} User: ${member.id} has changed appearance settings.`
|
`Guild: ${member.guild.id} User: ${member.id} has changed appearance settings.`
|
||||||
);
|
);
|
||||||
|
|
|
@ -6,32 +6,30 @@ const { appearance } = require('./addons');
|
||||||
|
|
||||||
module.exports = async (interaction) => {
|
module.exports = async (interaction) => {
|
||||||
// Destructure member
|
// Destructure member
|
||||||
|
|
||||||
const { member } = interaction;
|
const { member } = interaction;
|
||||||
|
|
||||||
// Check permission
|
// Check permission
|
||||||
|
|
||||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||||
|
// Create embed object
|
||||||
const embed = {
|
const embed = {
|
||||||
title: 'Settings',
|
title: 'Settings',
|
||||||
color: config.colors.error,
|
color: config.colors.error,
|
||||||
description: 'You do not have permission to manage this!',
|
description: `You don't have permission to manage this!`,
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Send interaction reply
|
||||||
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Command handler
|
// If subcommand is appearance
|
||||||
|
|
||||||
if (interaction.options.getSubcommand() === 'appearance') {
|
if (interaction.options.getSubcommand() === 'appearance') {
|
||||||
// Execute appearance addon
|
// Execute appearance addon
|
||||||
|
|
||||||
await appearance(interaction);
|
await appearance(interaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send debug message
|
// Send debug message
|
||||||
|
|
||||||
await logger.debug(
|
await logger.debug(
|
||||||
`Guild: ${member.guild.id} User: ${member.id} executed /${
|
`Guild: ${member.guild.id} User: ${member.id} executed /${
|
||||||
interaction.commandName
|
interaction.commandName
|
||||||
|
|
181
src/commands/shop/addons/pterodactyl.js
Normal file
181
src/commands/shop/addons/pterodactyl.js
Normal file
|
@ -0,0 +1,181 @@
|
||||||
|
const { v4: uuidv4 } = require('uuid');
|
||||||
|
const axios = require('axios');
|
||||||
|
const config = require('../../../../config.json');
|
||||||
|
const logger = require('../../../handlers/logger');
|
||||||
|
|
||||||
|
const { credits, apis } = require('../../../helpers/database/models');
|
||||||
|
const creditNoun = require('../../../helpers/creditNoun');
|
||||||
|
|
||||||
|
module.exports = async (interaction) => {
|
||||||
|
// Needs to be made multi-guild
|
||||||
|
if (config.disable.redeem) {
|
||||||
|
// Create embed object
|
||||||
|
const embed = {
|
||||||
|
title: ':shopping_cart: Shop - Pterodactyl failed',
|
||||||
|
description: 'This item in the shop is currently disabled.',
|
||||||
|
color: config.colors.error,
|
||||||
|
timestamp: new Date(),
|
||||||
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
|
};
|
||||||
|
|
||||||
|
// Send interaction reply
|
||||||
|
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get options
|
||||||
|
const amount = await interaction.options.getInteger('amount');
|
||||||
|
|
||||||
|
// Get user object
|
||||||
|
const user = await credits.findOne({
|
||||||
|
userId: interaction.user.id,
|
||||||
|
guildId: interaction.member.guild.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Get DM user object
|
||||||
|
const dmUser = interaction.client.users.cache.get(interaction.member.user.id);
|
||||||
|
|
||||||
|
// Stop if amount or user balance is below 100
|
||||||
|
if ((amount || user.balance) < 100) {
|
||||||
|
const embed = {
|
||||||
|
title: ':shopping_cart: Shop - Pterodactyl',
|
||||||
|
description: `You **can't** withdraw for __Pterodactyl__ below **100**.`,
|
||||||
|
color: config.colors.error,
|
||||||
|
fields: [{ name: 'Your balance', value: `${creditNoun(user.balance)}` }],
|
||||||
|
timestamp: new Date(),
|
||||||
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
|
};
|
||||||
|
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stop if amount or user balance is above 1.000.000
|
||||||
|
if ((amount || user.balance) > 1000000) {
|
||||||
|
const embed = {
|
||||||
|
title: ':shopping_cart: Shop - Pterodactyl',
|
||||||
|
description: `You **can't** withdraw for __Pterodactyl__ above **1.000.000**.`,
|
||||||
|
color: config.colors.error,
|
||||||
|
fields: [{ name: 'Your balance', value: `${creditNoun(user.balance)}` }],
|
||||||
|
timestamp: new Date(),
|
||||||
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
|
};
|
||||||
|
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stop if user balance is below amount
|
||||||
|
if (user.balance < amount) {
|
||||||
|
const embed = {
|
||||||
|
title: ':shopping_cart: Shop - Pterodactyl',
|
||||||
|
description: `You have **insufficient** credits.`,
|
||||||
|
color: config.colors.error,
|
||||||
|
fields: [{ name: 'Your balance', value: `${creditNoun(user.balance)}` }],
|
||||||
|
timestamp: new Date(),
|
||||||
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
|
};
|
||||||
|
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate a unique voucher for the user
|
||||||
|
const code = uuidv4();
|
||||||
|
|
||||||
|
// Get api object
|
||||||
|
const apiCredentials = await apis.findOne({
|
||||||
|
guildId: interaction.member.guild.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Create a api instance
|
||||||
|
const api = axios.create({
|
||||||
|
baseURL: apiCredentials.url,
|
||||||
|
headers: { Authorization: `Bearer ${apiCredentials.token}` },
|
||||||
|
});
|
||||||
|
|
||||||
|
// Get shop URL
|
||||||
|
const shopUrl = apiCredentials.url.replace('/api', '/store');
|
||||||
|
|
||||||
|
// Make API request
|
||||||
|
await api
|
||||||
|
|
||||||
|
// Make a post request to the API
|
||||||
|
.post('vouchers', {
|
||||||
|
uses: 1,
|
||||||
|
code,
|
||||||
|
credits: amount || user.balance,
|
||||||
|
memo: `${interaction.createdTimestamp} - ${interaction.user.id}`,
|
||||||
|
})
|
||||||
|
|
||||||
|
// If successful
|
||||||
|
.then(async () => {
|
||||||
|
// Create DM embed object
|
||||||
|
const dmEmbed = {
|
||||||
|
title: ':shopping_cart: Shop - Pterodactyl',
|
||||||
|
description: `Redeem this voucher [here](${shopUrl})!`,
|
||||||
|
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 },
|
||||||
|
};
|
||||||
|
|
||||||
|
// Create interaction embed object
|
||||||
|
const interactionEmbed = {
|
||||||
|
title: ':shopping_cart: Shop - Pterodactyl',
|
||||||
|
description: 'I have sent you the code in DM!',
|
||||||
|
color: config.colors.success,
|
||||||
|
timestamp: new Date(),
|
||||||
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
|
};
|
||||||
|
|
||||||
|
// Withdraw amount from user balance
|
||||||
|
user.balance -= amount || user.balance;
|
||||||
|
|
||||||
|
// Save new balance
|
||||||
|
await user
|
||||||
|
.save()
|
||||||
|
// If successful
|
||||||
|
.then(async () => {
|
||||||
|
// Send debug message
|
||||||
|
await logger.debug(
|
||||||
|
`User: ${user.username} redeemed: ${creditNoun(amount)}`
|
||||||
|
);
|
||||||
|
|
||||||
|
// Send DM message
|
||||||
|
await dmUser.send({ embeds: [dmEmbed] });
|
||||||
|
|
||||||
|
// Send interaction reply
|
||||||
|
await interaction.editReply({
|
||||||
|
embeds: [interactionEmbed],
|
||||||
|
ephemeral: true,
|
||||||
|
});
|
||||||
|
})
|
||||||
|
|
||||||
|
// If error occurs
|
||||||
|
.catch(async (e) => {
|
||||||
|
await logger.error(e);
|
||||||
|
const embed = {
|
||||||
|
title: ':shopping_cart: Shop - Pterodactyl',
|
||||||
|
description: 'Something went wrong, please try again later.',
|
||||||
|
color: config.colors.error,
|
||||||
|
timestamp: new Date(),
|
||||||
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
|
};
|
||||||
|
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||||
|
});
|
||||||
|
})
|
||||||
|
|
||||||
|
// If error occurs
|
||||||
|
.catch(async (e) => {
|
||||||
|
await logger.error(e);
|
||||||
|
const embed = {
|
||||||
|
title: ':shopping_cart: Shop - Pterodactyl',
|
||||||
|
description: 'Something went wrong, please try again later.',
|
||||||
|
color: config.colors.error,
|
||||||
|
timestamp: new Date(),
|
||||||
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
|
};
|
||||||
|
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||||
|
});
|
||||||
|
};
|
29
src/commands/shop/index.js
Normal file
29
src/commands/shop/index.js
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
const { SlashCommandBuilder } = require('@discordjs/builders');
|
||||||
|
const { Permissions } = require('discord.js');
|
||||||
|
|
||||||
|
const guilds = require('../../helpers/database/models/guildSchema');
|
||||||
|
|
||||||
|
const pterodactyl = require('./addons/pterodactyl');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
data: new SlashCommandBuilder()
|
||||||
|
.setName('shop')
|
||||||
|
.setDescription('Open our shop.')
|
||||||
|
.addSubcommand((subcommand) =>
|
||||||
|
subcommand
|
||||||
|
.setName('pterodactyl')
|
||||||
|
.setDescription('Buy pterodactyl power.')
|
||||||
|
.addIntegerOption((option) =>
|
||||||
|
option
|
||||||
|
.setName('amount')
|
||||||
|
.setDescription('How much credits you want to withdraw.')
|
||||||
|
)
|
||||||
|
),
|
||||||
|
async execute(interaction) {
|
||||||
|
// If subcommand is pterodactyl
|
||||||
|
if (interaction.options.getSubcommand() === 'pterodactyl') {
|
||||||
|
// Execute pterodactyl addon
|
||||||
|
await pterodactyl(interaction);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
|
@ -5,12 +5,19 @@ const logger = require('../../../handlers/logger');
|
||||||
|
|
||||||
module.exports = async (interaction) => {
|
module.exports = async (interaction) => {
|
||||||
try {
|
try {
|
||||||
const target = await interaction.options.getString('target');
|
// Get lookup query
|
||||||
|
const query = await interaction.options.getString('query');
|
||||||
|
|
||||||
|
// Make API request
|
||||||
await axios
|
await axios
|
||||||
.get(`http://ip-api.com/json/${target}`)
|
// Make a get request
|
||||||
|
.get(`http://ip-api.com/json/${query}`)
|
||||||
|
|
||||||
|
// If successful
|
||||||
.then(async (res) => {
|
.then(async (res) => {
|
||||||
|
// If query failed
|
||||||
if (res.data.status === 'fail') {
|
if (res.data.status === 'fail') {
|
||||||
|
// Create embed object
|
||||||
const embed = {
|
const embed = {
|
||||||
title: 'Lookup',
|
title: 'Lookup',
|
||||||
description: `${res.data.message}: ${res.data.query}`,
|
description: `${res.data.message}: ${res.data.query}`,
|
||||||
|
@ -18,8 +25,14 @@ module.exports = async (interaction) => {
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Send interaction reply
|
||||||
await interaction.editReply({ embeds: [embed] });
|
await interaction.editReply({ embeds: [embed] });
|
||||||
} else if (res.data.status === 'success') {
|
}
|
||||||
|
|
||||||
|
// If query is successful
|
||||||
|
else if (res.data.status === 'success') {
|
||||||
|
// Create embed object
|
||||||
const embed = {
|
const embed = {
|
||||||
title: 'Lookup',
|
title: 'Lookup',
|
||||||
fields: [
|
fields: [
|
||||||
|
@ -61,13 +74,15 @@ module.exports = async (interaction) => {
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Send interaction reply
|
||||||
await interaction.editReply({ embeds: [embed] });
|
await interaction.editReply({ embeds: [embed] });
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(async (err) => {
|
.catch(async (e) => {
|
||||||
await logger.error(err);
|
await logger.error(e);
|
||||||
});
|
});
|
||||||
} catch {
|
} catch (e) {
|
||||||
await logger.error();
|
await logger.error(e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,35 +0,0 @@
|
||||||
const { Permissions } = require('discord.js');
|
|
||||||
|
|
||||||
const config = require('../../../../config.json');
|
|
||||||
const logger = require('../../../handlers/logger');
|
|
||||||
|
|
||||||
module.exports = async (interaction) => {
|
|
||||||
try {
|
|
||||||
if (!interaction.member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
|
||||||
const embed = {
|
|
||||||
title: 'Users failed',
|
|
||||||
description:
|
|
||||||
'You need to have permission to manage this guild (MANAGE_GUILD)',
|
|
||||||
};
|
|
||||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
|
||||||
}
|
|
||||||
|
|
||||||
// eslint-disable-next-line max-len
|
|
||||||
const userList = await interaction.client.users.cache.filter(
|
|
||||||
(user) => !user.bot
|
|
||||||
);
|
|
||||||
|
|
||||||
userList.map((user) => {
|
|
||||||
logger.info(user);
|
|
||||||
});
|
|
||||||
|
|
||||||
// await interaction.client.guilds.cache.get(interaction.member.guild.id).then((user) => logger.info(user));
|
|
||||||
|
|
||||||
// await interaction.client.users.fetch().then(async (user) => await logger.info(`${user}`));
|
|
||||||
// // interaction.client.users.fetch().then((user) => {
|
|
||||||
// // console.log(user);
|
|
||||||
// // }).catch(console.error);
|
|
||||||
} catch {
|
|
||||||
await logger.error();
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -1,8 +1,6 @@
|
||||||
const { SlashCommandBuilder } = require('@discordjs/builders');
|
const { SlashCommandBuilder } = require('@discordjs/builders');
|
||||||
const { Permissions } = require('discord.js');
|
|
||||||
|
|
||||||
const lookup = require('./addons/lookup');
|
const lookup = require('./addons/lookup');
|
||||||
const users = require('./addons/users');
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
|
@ -16,8 +14,8 @@ module.exports = {
|
||||||
)
|
)
|
||||||
.addStringOption((option) =>
|
.addStringOption((option) =>
|
||||||
option
|
option
|
||||||
.setName('target')
|
.setName('query')
|
||||||
.setDescription('The target you want to look up.')
|
.setDescription('The query you want to look up.')
|
||||||
.setRequired(true)
|
.setRequired(true)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -25,10 +23,10 @@ module.exports = {
|
||||||
subcommand.setName('users').setDescription('Iterate all users (ADMIN)')
|
subcommand.setName('users').setDescription('Iterate all users (ADMIN)')
|
||||||
),
|
),
|
||||||
async execute(interaction) {
|
async execute(interaction) {
|
||||||
|
// If subcommand is lookup
|
||||||
if (interaction.options.getSubcommand() === 'lookup') {
|
if (interaction.options.getSubcommand() === 'lookup') {
|
||||||
|
// Execute lookup addon
|
||||||
await lookup(interaction);
|
await lookup(interaction);
|
||||||
} else if (interaction.options.getSubcommand() === 'users') {
|
|
||||||
await users(interaction);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,8 +3,13 @@ const guilds = require('../helpers/database/models/guildSchema');
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'guildCreate',
|
name: 'guildCreate',
|
||||||
async execute(guild) {
|
async execute(guild) {
|
||||||
|
// Destructure client
|
||||||
const { client } = guild;
|
const { client } = guild;
|
||||||
|
|
||||||
|
// Create guild object if not already created
|
||||||
await guilds.findOne({ guildId: guild.id }, { new: true, upsert: true });
|
await guilds.findOne({ guildId: guild.id }, { new: true, upsert: true });
|
||||||
|
|
||||||
|
// Set client status
|
||||||
await client.user.setPresence({
|
await client.user.setPresence({
|
||||||
activities: [
|
activities: [
|
||||||
{ type: 'WATCHING', name: `${client.guilds.cache.size} guilds` },
|
{ type: 'WATCHING', name: `${client.guilds.cache.size} guilds` },
|
||||||
|
|
|
@ -6,19 +6,25 @@ const { guilds } = require('../helpers/database/models');
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'interactionCreate',
|
name: 'interactionCreate',
|
||||||
async execute(interaction) {
|
async execute(interaction) {
|
||||||
|
// Destructure member, client
|
||||||
const { member, client } = interaction;
|
const { member, client } = interaction;
|
||||||
|
|
||||||
|
// If interaction is command
|
||||||
if (interaction.isCommand()) {
|
if (interaction.isCommand()) {
|
||||||
|
// Get command from collection
|
||||||
const command = client.commands.get(interaction.commandName);
|
const command = client.commands.get(interaction.commandName);
|
||||||
|
|
||||||
|
// If command do not exist
|
||||||
if (!command) return;
|
if (!command) return;
|
||||||
|
|
||||||
|
// Create guild if it does not exist already
|
||||||
await guilds.findOne(
|
await guilds.findOne(
|
||||||
{ guildId: member.guild.id },
|
{ guildId: member.guild.id },
|
||||||
{ new: true, upsert: true }
|
{ new: true, upsert: true }
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// Defer reply
|
||||||
await interaction.deferReply({
|
await interaction.deferReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
{
|
{
|
||||||
|
@ -35,10 +41,17 @@ module.exports = {
|
||||||
],
|
],
|
||||||
ephemeral: true,
|
ephemeral: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Execute command
|
||||||
await command.execute(interaction);
|
await command.execute(interaction);
|
||||||
|
|
||||||
|
// Send debug message
|
||||||
await logger.debug(`Executing command: ${interaction.commandName}`);
|
await logger.debug(`Executing command: ${interaction.commandName}`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
// Send debug message
|
||||||
await logger.error(err);
|
await logger.error(err);
|
||||||
|
|
||||||
|
// Send interaction reply
|
||||||
await interaction.reply({
|
await interaction.reply({
|
||||||
embeds: [
|
embeds: [
|
||||||
{
|
{
|
||||||
|
@ -57,35 +70,5 @@ module.exports = {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// else if (interaction.isButton()) {
|
|
||||||
// const button = client.buttons.get(interaction.customId);
|
|
||||||
|
|
||||||
// try {
|
|
||||||
// if (!button) {
|
|
||||||
// await interaction.deferReply();
|
|
||||||
// await interaction.editReply({ content: `Button not exist: ${interaction.customId}` });
|
|
||||||
// }
|
|
||||||
|
|
||||||
// await button.execute(interaction);
|
|
||||||
// await logger.debug(`Button pressed: ${interaction.customId}`);
|
|
||||||
// } catch (err) {
|
|
||||||
// await logger.error(err);
|
|
||||||
// }
|
|
||||||
// } else if (interaction.isSelectMenu()) {
|
|
||||||
// const menu = client.menus.get(interaction.customId);
|
|
||||||
|
|
||||||
// try {
|
|
||||||
// if (!menu) {
|
|
||||||
// await interaction.deferReply();
|
|
||||||
// await interaction.editReply({ content: `Menu not exist: ${interaction.customId}` });
|
|
||||||
// }
|
|
||||||
|
|
||||||
// await menu.execute(interaction);
|
|
||||||
// await logger.debug(`Menu pressed: ${interaction.customId}`);
|
|
||||||
// } catch (err) {
|
|
||||||
// await logger.error(err);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,19 +0,0 @@
|
||||||
const logger = require('../handlers/logger');
|
|
||||||
|
|
||||||
const users = require('../helpers/database/models/userSchema');
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
name: 'interactionCreate',
|
|
||||||
async execute(user) {
|
|
||||||
// const guildExist = await guilds
|
|
||||||
// .findOne({ guildId: guild.id })
|
|
||||||
// .then(logger.debug(`Found guild: ${guild.id}`))
|
|
||||||
// .catch(logger.error);
|
|
||||||
// if (!guildExist) {
|
|
||||||
// await guilds
|
|
||||||
// .create({ guildId: guild.id })
|
|
||||||
// .then(() => logger.debug(`Create guild: ${guild.id} was success`))
|
|
||||||
// .catch((e) => logger.error(e));
|
|
||||||
// }
|
|
||||||
},
|
|
||||||
};
|
|
|
@ -12,29 +12,24 @@ module.exports = {
|
||||||
name: 'messageCreate',
|
name: 'messageCreate',
|
||||||
async execute(message) {
|
async execute(message) {
|
||||||
// Get guild object
|
// Get guild object
|
||||||
|
|
||||||
const guild = await guilds.findOne({ guildId: message.guild.id });
|
const guild = await guilds.findOne({ guildId: message.guild.id });
|
||||||
|
|
||||||
// Stop if message author is bot
|
// If message author is bot
|
||||||
|
|
||||||
if (message.author.bot) return;
|
if (message.author.bot) return;
|
||||||
|
|
||||||
// Create user if not already created
|
// Create user if not already created
|
||||||
|
|
||||||
await users.findOne(
|
await users.findOne(
|
||||||
{ userId: message.author.id },
|
{ userId: message.author.id },
|
||||||
{ new: true, upsert: true }
|
{ new: true, upsert: true }
|
||||||
);
|
);
|
||||||
|
|
||||||
// Stop if message content is shorter than guild configured minimum length
|
// If message length is below guild minimum length
|
||||||
|
|
||||||
if (message.content.length < guild.credits.minimumLength) return;
|
if (message.content.length < guild.credits.minimumLength) return;
|
||||||
|
|
||||||
// Needs to be updated for multi-guild to function properly
|
// Needs to be updated for multi-guild to function properly
|
||||||
// if (config.credits.excludedChannels.includes(message.channel.id)) return;
|
// if (config.credits.excludedChannels.includes(message.channel.id)) return;
|
||||||
|
|
||||||
// Check if user has a timeout
|
// Check if user has a timeout
|
||||||
|
|
||||||
const isTimeout = await timeouts.findOne({
|
const isTimeout = await timeouts.findOne({
|
||||||
guildId: message.guild.id,
|
guildId: message.guild.id,
|
||||||
userId: message.author.id,
|
userId: message.author.id,
|
||||||
|
@ -42,44 +37,52 @@ module.exports = {
|
||||||
});
|
});
|
||||||
|
|
||||||
// If user is not on timeout
|
// If user is not on timeout
|
||||||
|
|
||||||
if (!isTimeout) {
|
if (!isTimeout) {
|
||||||
// Add credits to user
|
// Add credits to user
|
||||||
|
|
||||||
await credits
|
await credits
|
||||||
.findOneAndUpdate(
|
.findOneAndUpdate(
|
||||||
{ userId: message.author.id, guildId: message.guild.id },
|
{ userId: message.author.id, guildId: message.guild.id },
|
||||||
{ $inc: { balance: guild.credits.rate } },
|
{ $inc: { balance: guild.credits.rate } },
|
||||||
{ new: true, upsert: true }
|
{ new: true, upsert: true }
|
||||||
)
|
)
|
||||||
.then(async () =>
|
|
||||||
|
// If successful
|
||||||
|
.then(async () => {
|
||||||
|
// Send debug message
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`Guild: ${message.guild.id} Credits added to user: ${message.author.id}`
|
`Guild: ${message.guild.id} Credits added to user: ${message.author.id}`
|
||||||
)
|
);
|
||||||
)
|
})
|
||||||
|
|
||||||
|
// If error
|
||||||
.catch(async (err) => {
|
.catch(async (err) => {
|
||||||
|
// Send error message
|
||||||
await logger.error(err);
|
await logger.error(err);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add points to user
|
// Add points to user
|
||||||
|
|
||||||
await experiences
|
await experiences
|
||||||
.findOneAndUpdate(
|
.findOneAndUpdate(
|
||||||
{ userId: message.author.id, guildId: message.guild.id },
|
{ userId: message.author.id, guildId: message.guild.id },
|
||||||
{ $inc: { points: guild.points.rate } },
|
{ $inc: { points: guild.points.rate } },
|
||||||
{ new: true, upsert: true }
|
{ new: true, upsert: true }
|
||||||
)
|
)
|
||||||
.then(async () =>
|
|
||||||
|
// If successful
|
||||||
|
.then(async () => {
|
||||||
|
// Send debug message
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`Guild: ${message.guild.id} Points added to user: ${message.author.id}`
|
`Guild: ${message.guild.id} Points added to user: ${message.author.id}`
|
||||||
)
|
);
|
||||||
)
|
})
|
||||||
|
|
||||||
|
// If error
|
||||||
.catch(async (err) => {
|
.catch(async (err) => {
|
||||||
|
// Send error message
|
||||||
await logger.error(err);
|
await logger.error(err);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Create a timeout for the user
|
// Create a timeout for the user
|
||||||
|
|
||||||
await timeouts.create({
|
await timeouts.create({
|
||||||
guildId: message.guild.id,
|
guildId: message.guild.id,
|
||||||
userId: message.author.id,
|
userId: message.author.id,
|
||||||
|
@ -87,6 +90,7 @@ module.exports = {
|
||||||
});
|
});
|
||||||
|
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
|
// Send debug message
|
||||||
await logger.debug(
|
await logger.debug(
|
||||||
`Guild: ${message.guild.id} User: ${
|
`Guild: ${message.guild.id} User: ${
|
||||||
message.author.id
|
message.author.id
|
||||||
|
@ -96,7 +100,6 @@ module.exports = {
|
||||||
);
|
);
|
||||||
|
|
||||||
// When timeout is out, remove it from the database
|
// When timeout is out, remove it from the database
|
||||||
|
|
||||||
await timeouts.deleteOne({
|
await timeouts.deleteOne({
|
||||||
guildId: message.guild.id,
|
guildId: message.guild.id,
|
||||||
userId: message.author.id,
|
userId: message.author.id,
|
||||||
|
@ -104,6 +107,7 @@ module.exports = {
|
||||||
});
|
});
|
||||||
}, guild.credits.timeout);
|
}, guild.credits.timeout);
|
||||||
} else {
|
} else {
|
||||||
|
// Sned debug message
|
||||||
await logger.debug(
|
await logger.debug(
|
||||||
`Guild: ${message.guild.id} User: ${
|
`Guild: ${message.guild.id} User: ${
|
||||||
message.author.id
|
message.author.id
|
||||||
|
|
|
@ -4,7 +4,10 @@ module.exports = {
|
||||||
name: 'ready',
|
name: 'ready',
|
||||||
once: true,
|
once: true,
|
||||||
async execute(client) {
|
async execute(client) {
|
||||||
|
// Send info message
|
||||||
await logger.info(`Ready! Logged in as ${client.user.tag}`);
|
await logger.info(`Ready! Logged in as ${client.user.tag}`);
|
||||||
|
|
||||||
|
// Set client status
|
||||||
await client.user.setPresence({
|
await client.user.setPresence({
|
||||||
activities: [
|
activities: [
|
||||||
{ type: 'WATCHING', name: `${client.guilds.cache.size} guilds` },
|
{ type: 'WATCHING', name: `${client.guilds.cache.size} guilds` },
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
const axios = require('axios');
|
|
||||||
|
|
||||||
const config = require('../../config.json');
|
|
||||||
|
|
||||||
module.exports = axios.create({
|
|
||||||
baseURL: config.credits.url,
|
|
||||||
headers: { Authorization: `Bearer ${config.credits.token}` },
|
|
||||||
});
|
|
Loading…
Add table
Reference in a new issue