💡 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');
|
||||
|
||||
// Database models
|
||||
|
||||
const { credits } = require('../../../../helpers/database/models');
|
||||
|
||||
const creditNoun = require('../../../../helpers/creditNoun');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
// Destructure member
|
||||
|
||||
const { member } = interaction;
|
||||
|
||||
// Check permission
|
||||
|
||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Admin',
|
||||
color: config.colors.error,
|
||||
|
@ -22,17 +21,18 @@ module.exports = async (interaction) => {
|
|||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Get options
|
||||
|
||||
const user = await interaction.options.getUser('user');
|
||||
const amount = await interaction.options.getInteger('amount');
|
||||
|
||||
// Stop if given amount is zero or below
|
||||
|
||||
// If amount is zero or below
|
||||
if (amount <= 0) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Give',
|
||||
description: "You can't give zero or below.",
|
||||
|
@ -40,19 +40,20 @@ module.exports = async (interaction) => {
|
|||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Get toUser object
|
||||
|
||||
const toUser = await credits.findOne({
|
||||
userId: user.id,
|
||||
guildId: interaction.member.guild.id,
|
||||
});
|
||||
|
||||
// Stop if user has zero or below credits
|
||||
|
||||
// If toUser has no credits
|
||||
if (!toUser) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Give',
|
||||
description:
|
||||
|
@ -61,38 +62,44 @@ module.exports = async (interaction) => {
|
|||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Increase toUser with amount
|
||||
|
||||
// Deposit amount to toUser
|
||||
toUser.balance += amount;
|
||||
|
||||
// Save toUser
|
||||
await toUser
|
||||
.save()
|
||||
|
||||
await toUser.save().then(async () => {
|
||||
const embed = {
|
||||
title: 'Give',
|
||||
description: `Gave ${creditNoun(amount)} to ${user}.`,
|
||||
color: 0x22bb33,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
await logger.debug(
|
||||
`Administrator: ${interaction.user.username} gave ${
|
||||
amount <= 1 ? `${amount} credit` : `${amount} credits`
|
||||
} to ${user.username}`
|
||||
);
|
||||
// Send reply
|
||||
// If successful
|
||||
.then(async () => {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Give',
|
||||
description: `Gave ${creditNoun(amount)} to ${user}.`,
|
||||
color: 0x22bb33,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
await 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(
|
||||
`Guild: ${member.guild.id} User: ${member.id} gave ${
|
||||
user.id
|
||||
} ${creditNoun(amount)}.`
|
||||
);
|
||||
});
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} gave ${
|
||||
user.id
|
||||
} ${creditNoun(amount)}.`
|
||||
);
|
||||
});
|
||||
};
|
||||
|
|
|
@ -9,12 +9,11 @@ const creditNoun = require('../../../../helpers/creditNoun');
|
|||
|
||||
module.exports = async (interaction) => {
|
||||
// Destructure member
|
||||
|
||||
const { member } = interaction;
|
||||
|
||||
// Check permission
|
||||
|
||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Admin',
|
||||
color: config.colors.error,
|
||||
|
@ -22,17 +21,18 @@ module.exports = async (interaction) => {
|
|||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Get options
|
||||
|
||||
const user = await interaction.options.getUser('user');
|
||||
const amount = await interaction.options.getInteger('amount');
|
||||
|
||||
// Stop if given amount is zero or below
|
||||
|
||||
// If amount is zero or below
|
||||
if (amount <= 0) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Give',
|
||||
description: "You can't give zero or below.",
|
||||
|
@ -40,19 +40,20 @@ module.exports = async (interaction) => {
|
|||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Get toUser object
|
||||
|
||||
const toUser = await credits.findOne({
|
||||
userId: user.id,
|
||||
guildId: interaction.member.guild.id,
|
||||
});
|
||||
|
||||
// Stop if user has zero or below credits
|
||||
|
||||
// If toUser has no credits
|
||||
if (!toUser) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Set',
|
||||
description:
|
||||
|
@ -61,38 +62,44 @@ module.exports = async (interaction) => {
|
|||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Set toUser with amount
|
||||
|
||||
toUser.balance = amount;
|
||||
|
||||
// Save toUser
|
||||
await toUser
|
||||
.save()
|
||||
|
||||
await toUser.save().then(async () => {
|
||||
const embed = {
|
||||
title: 'Set',
|
||||
description: `You set ${creditNoun(amount)} on ${user}.`,
|
||||
color: 0x22bb33,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
await logger.debug(
|
||||
`Administrator: ${interaction.user.username} set ${
|
||||
amount <= 1 ? `${amount} credit` : `${amount} credits`
|
||||
} on ${user.username}`
|
||||
);
|
||||
// Send reply
|
||||
// If successful
|
||||
.then(async () => {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Set',
|
||||
description: `You set ${creditNoun(amount)} on ${user}.`,
|
||||
color: 0x22bb33,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
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(
|
||||
`Guild: ${member.guild.id} User: ${member.id} set ${
|
||||
user.id
|
||||
} to ${creditNoun(amount)}.`
|
||||
);
|
||||
});
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} set ${
|
||||
user.id
|
||||
} to ${creditNoun(amount)}.`
|
||||
);
|
||||
});
|
||||
};
|
||||
|
|
|
@ -9,12 +9,11 @@ const creditNoun = require('../../../../helpers/creditNoun');
|
|||
|
||||
module.exports = async (interaction) => {
|
||||
// Destructure member
|
||||
|
||||
const { member } = interaction;
|
||||
|
||||
// Check permission
|
||||
|
||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Admin',
|
||||
color: config.colors.error,
|
||||
|
@ -22,17 +21,18 @@ module.exports = async (interaction) => {
|
|||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Get options
|
||||
|
||||
const user = await interaction.options.getUser('user');
|
||||
const amount = await interaction.options.getInteger('amount');
|
||||
|
||||
// Stop if given amount is zero or below
|
||||
|
||||
// If amount is zero or below
|
||||
if (amount <= 0) {
|
||||
// Give embed object
|
||||
const embed = {
|
||||
title: 'Take',
|
||||
description: "You can't take zero or below.",
|
||||
|
@ -40,19 +40,20 @@ module.exports = async (interaction) => {
|
|||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Get toUser object
|
||||
|
||||
const toUser = await credits.findOne({
|
||||
userId: user.id,
|
||||
guildId: interaction.member.guild.id,
|
||||
});
|
||||
|
||||
// Stop if user has zero or below credits
|
||||
|
||||
// If toUser has no credits
|
||||
if (!toUser) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Take',
|
||||
description:
|
||||
|
@ -61,38 +62,44 @@ module.exports = async (interaction) => {
|
|||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Decrease toUser with amount
|
||||
|
||||
// Withdraw amount from toUser
|
||||
toUser.balance -= amount;
|
||||
|
||||
// Save toUser
|
||||
await toUser
|
||||
.save()
|
||||
|
||||
await toUser.save().then(async () => {
|
||||
const embed = {
|
||||
title: 'Take',
|
||||
description: `You took ${creditNoun(amount)} to ${user}.`,
|
||||
color: 0x22bb33,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
await logger.debug(
|
||||
`Administrator: ${interaction.user.username} took ${
|
||||
amount <= 1 ? `${amount} credit` : `${amount} credits`
|
||||
} from ${user.username}`
|
||||
);
|
||||
// Send reply
|
||||
// If successful
|
||||
.then(async () => {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Take',
|
||||
description: `You took ${creditNoun(amount)} to ${user}.`,
|
||||
color: 0x22bb33,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
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(
|
||||
`Guild: ${member.guild.id} User: ${member.id} took ${creditNoun(
|
||||
amount
|
||||
)} from ${user.id}.`
|
||||
);
|
||||
});
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} took ${creditNoun(
|
||||
amount
|
||||
)} from ${user.id}.`
|
||||
);
|
||||
});
|
||||
};
|
||||
|
|
|
@ -10,12 +10,11 @@ const saveUser = require('../../../../helpers/saveUser');
|
|||
|
||||
module.exports = async (interaction) => {
|
||||
// Destructure member
|
||||
|
||||
const { member } = interaction;
|
||||
|
||||
// Check permission
|
||||
|
||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Admin',
|
||||
color: config.colors.error,
|
||||
|
@ -23,32 +22,31 @@ module.exports = async (interaction) => {
|
|||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Get options
|
||||
|
||||
const from = await interaction.options.getUser('from');
|
||||
const to = await interaction.options.getUser('to');
|
||||
const amount = await interaction.options.getInteger('amount');
|
||||
|
||||
// Get fromUser object
|
||||
|
||||
const fromUser = await credits.findOne({
|
||||
userId: from.id,
|
||||
guildId: interaction.member.guild.id,
|
||||
});
|
||||
|
||||
// Get toUser object
|
||||
|
||||
const toUser = await credits.findOne({
|
||||
userId: to.id,
|
||||
guildId: interaction.member.guild.id,
|
||||
});
|
||||
|
||||
// Stop if fromUser has zero credits or below
|
||||
|
||||
// If fromUser has no credits
|
||||
if (!fromUser) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Transfer',
|
||||
description:
|
||||
|
@ -57,12 +55,14 @@ module.exports = async (interaction) => {
|
|||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Stop if toUser has zero credits or below
|
||||
|
||||
// If toUser has no credits
|
||||
if (!toUser) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Transfer',
|
||||
description:
|
||||
|
@ -71,12 +71,14 @@ module.exports = async (interaction) => {
|
|||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Stop if amount is zero or below
|
||||
|
||||
// If amount is zero or below
|
||||
if (amount <= 0) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Transfer failed',
|
||||
description: "You can't transfer zero or below.",
|
||||
|
@ -84,48 +86,50 @@ module.exports = async (interaction) => {
|
|||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Decrease fromUser with amount
|
||||
|
||||
// Withdraw amount from fromUser
|
||||
fromUser.balance -= amount;
|
||||
|
||||
// Increase toUser with amount
|
||||
|
||||
// Deposit amount to toUser
|
||||
toUser.balance += amount;
|
||||
|
||||
await saveUser(fromUser, toUser).then(async () => {
|
||||
const embed = {
|
||||
title: 'Transfer',
|
||||
description: `You sent ${creditNoun(amount)} from ${from} to ${to}.`,
|
||||
color: 0x22bb33,
|
||||
fields: [
|
||||
{
|
||||
name: `${from.username} Balance`,
|
||||
value: `${fromUser.balance}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: `${to.username} Balance`,
|
||||
value: `${toUser.balance}`,
|
||||
inline: true,
|
||||
},
|
||||
],
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
// Save users
|
||||
await saveUser(fromUser, toUser)
|
||||
// If successful
|
||||
.then(async () => {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Transfer',
|
||||
description: `You sent ${creditNoun(amount)} from ${from} to ${to}.`,
|
||||
color: 0x22bb33,
|
||||
fields: [
|
||||
{
|
||||
name: `${from.username} Balance`,
|
||||
value: `${fromUser.balance}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: `${to.username} Balance`,
|
||||
value: `${toUser.balance}`,
|
||||
inline: true,
|
||||
},
|
||||
],
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// 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(
|
||||
`Guild: ${member.guild.id} User: ${member.id} transferred ${creditNoun(
|
||||
amount
|
||||
)} from ${from.id} to ${to.id}.`
|
||||
);
|
||||
});
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`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) => {
|
||||
// Destructure member
|
||||
|
||||
const { member } = interaction;
|
||||
|
||||
// Check permission
|
||||
|
||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Admin',
|
||||
color: config.colors.error,
|
||||
|
@ -19,31 +18,36 @@ module.exports = async (interaction) => {
|
|||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Command handler
|
||||
|
||||
// If subcommand is give
|
||||
if (interaction.options.getSubcommand() === 'give') {
|
||||
// Execute give addon
|
||||
|
||||
await give(interaction);
|
||||
} else if (interaction.options.getSubcommand() === 'take') {
|
||||
}
|
||||
|
||||
// If subcommand is take
|
||||
else if (interaction.options.getSubcommand() === 'take') {
|
||||
// Execute take addon
|
||||
|
||||
await take(interaction);
|
||||
} else if (interaction.options.getSubcommand() === 'set') {
|
||||
}
|
||||
|
||||
// If subcommand is set
|
||||
else if (interaction.options.getSubcommand() === 'set') {
|
||||
// Execute set addon
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
// Send debug message
|
||||
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} executed /${
|
||||
interaction.commandName
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
const { SlashCommandBuilder } = require('@discordjs/builders');
|
||||
const { Permissions } = require('discord.js');
|
||||
|
||||
const credits = require('./credits');
|
||||
|
||||
|
@ -87,9 +86,10 @@ module.exports = {
|
|||
)
|
||||
),
|
||||
async execute(interaction) {
|
||||
// If subcommand group is credits
|
||||
if (interaction.options.getSubcommandGroup() === 'credits') {
|
||||
// Execute credits group
|
||||
await credits(interaction);
|
||||
}
|
||||
return true;
|
||||
},
|
||||
};
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
const i18next = require('i18next');
|
||||
const config = require('../../../../config.json');
|
||||
const logger = require('../../../handlers/logger');
|
||||
|
||||
|
@ -7,15 +6,21 @@ const creditNoun = require('../../../helpers/creditNoun');
|
|||
|
||||
module.exports = async (interaction) => {
|
||||
try {
|
||||
// Get options
|
||||
const user = await interaction.options.getUser('user');
|
||||
|
||||
// Get credit object
|
||||
await credits
|
||||
.findOne({
|
||||
userId: user ? user.id : interaction.user.id,
|
||||
guildId: interaction.member.guild.id,
|
||||
})
|
||||
|
||||
// If successful
|
||||
.then(async (data) => {
|
||||
// If user has no credits
|
||||
if (!data) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Balance',
|
||||
description: `${user} has no credits.`,
|
||||
|
@ -24,10 +29,14 @@ module.exports = async (interaction) => {
|
|||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Destructure balance
|
||||
const { balance } = data;
|
||||
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Balance',
|
||||
description: `${user ? `${user} has` : 'You have'} ${creditNoun(
|
||||
|
@ -37,10 +46,16 @@ module.exports = async (interaction) => {
|
|||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
})
|
||||
.catch(async (err) => logger.error(err));
|
||||
} catch {
|
||||
await logger.error();
|
||||
.catch(async (e) => {
|
||||
// Send debug message
|
||||
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 logger = require('../../../handlers/logger');
|
||||
|
||||
|
@ -8,16 +7,20 @@ const creditNoun = require('../../../helpers/creditNoun');
|
|||
|
||||
module.exports = async (interaction) => {
|
||||
try {
|
||||
// Get options
|
||||
const user = await interaction.options.getUser('user');
|
||||
const amount = await interaction.options.getInteger('amount');
|
||||
const reason = await interaction.options.getString('reason');
|
||||
|
||||
// Get data object
|
||||
const data = await credits.findOne({
|
||||
userId: interaction.user.id,
|
||||
guildId: interaction.member.guild.id,
|
||||
});
|
||||
|
||||
// If receiver is same as sender
|
||||
if (user.id === interaction.user.id) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Gift',
|
||||
description: "You can't pay yourself.",
|
||||
|
@ -25,9 +28,14 @@ module.exports = async (interaction) => {
|
|||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// If amount is zero or below
|
||||
if (amount <= 0) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Gift',
|
||||
description: "You can't pay zero or below.",
|
||||
|
@ -35,9 +43,14 @@ module.exports = async (interaction) => {
|
|||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// If user has below gifting amount
|
||||
if (data.balance < amount) {
|
||||
// Create embed
|
||||
const embed = {
|
||||
title: 'Gift',
|
||||
description: `You have insufficient credits. Your balance is ${data.balance}`,
|
||||
|
@ -45,19 +58,26 @@ module.exports = async (interaction) => {
|
|||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
// eslint-disable-next-line max-len
|
||||
|
||||
// Get fromUser object
|
||||
const fromUser = await credits.findOne({
|
||||
userId: interaction.user.id,
|
||||
guildId: interaction.member.guild.id,
|
||||
});
|
||||
|
||||
// Get toUser object
|
||||
const toUser = await credits.findOne({
|
||||
userId: user.id,
|
||||
guildId: interaction.member.guild.id,
|
||||
});
|
||||
|
||||
// If toUser has no credits
|
||||
if (!toUser) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Gift',
|
||||
description:
|
||||
|
@ -66,44 +86,62 @@ module.exports = async (interaction) => {
|
|||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Withdraw amount from fromUser
|
||||
fromUser.balance -= amount;
|
||||
|
||||
// Deposit amount to toUser
|
||||
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 = {
|
||||
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 dmEmbed = {
|
||||
title: 'Gift',
|
||||
description: `You received ${creditNoun(amount)} from ${
|
||||
interaction.user
|
||||
}${
|
||||
reason ? ` with reason: ${reason}` : ''
|
||||
}. Your new balance is ${creditNoun(toUser.balance)}.`,
|
||||
color: 0x22bb33,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
const dmUser = await interaction.client.users.cache.get(user.id);
|
||||
await dmUser.send({ embeds: [dmEmbed] });
|
||||
await logger.debug(
|
||||
`Gift sent from: ${interaction.user.username} to: ${user.username}`
|
||||
);
|
||||
return await interaction.editReply({
|
||||
embeds: [interactionEmbed],
|
||||
ephemeral: true,
|
||||
// Create DM embed object
|
||||
const dmEmbed = {
|
||||
title: 'Gift',
|
||||
description: `You received ${creditNoun(amount)} from ${
|
||||
interaction.user
|
||||
}${
|
||||
reason ? ` with reason: ${reason}` : ''
|
||||
}. Your new balance is ${creditNoun(toUser.balance)}.`,
|
||||
color: 0x22bb33,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Get DM user object
|
||||
const dmUser = await interaction.client.users.cache.get(user.id);
|
||||
|
||||
// Send DM to user
|
||||
await dmUser.send({ embeds: [dmEmbed] });
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Gift sent from: ${interaction.user.username} to: ${user.username}`
|
||||
);
|
||||
|
||||
// Send interaction reply
|
||||
return await interaction.editReply({
|
||||
embeds: [interactionEmbed],
|
||||
ephemeral: true,
|
||||
});
|
||||
});
|
||||
} catch (e) {
|
||||
// Send debug message
|
||||
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');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
// Get all users in the guild
|
||||
await credits
|
||||
.find({ guildId: interaction.member.guild.id })
|
||||
|
||||
// If successful
|
||||
.then(async (data) => {
|
||||
// Get top ten
|
||||
const topTen = data
|
||||
|
||||
// Sort them after balance amount (ascending)
|
||||
.sort((a, b) => (a.balance > b.balance ? -1 : 1))
|
||||
|
||||
// Return the top 10
|
||||
.slice(0, 10);
|
||||
|
||||
const item = (x, index) =>
|
||||
// Create entry object
|
||||
const entry = (x, index) =>
|
||||
`**Top ${index + 1}** - <@${x.userId}> ${creditNoun(x.balance)}`;
|
||||
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Balance Top',
|
||||
description: `Below are the top ten.\n${topTen
|
||||
.map((x, index) => item(x, index))
|
||||
.map((x, index) => entry(x, index))
|
||||
.join('\n')}`,
|
||||
color: 0x22bb33,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
});
|
||||
};
|
||||
|
|
|
@ -7,14 +7,11 @@ const {
|
|||
} = require('../../../helpers/database/models');
|
||||
const creditNoun = require('../../../helpers/creditNoun');
|
||||
|
||||
const workedRecently = new Set();
|
||||
|
||||
// eslint-disable-next-line consistent-return
|
||||
module.exports = async (interaction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
|
||||
// Check if user has a timeout
|
||||
|
||||
const isTimeout = await timeouts.findOne({
|
||||
guildId: member.guild.id,
|
||||
userId: member.id,
|
||||
|
@ -22,13 +19,15 @@ module.exports = async (interaction) => {
|
|||
});
|
||||
|
||||
// If user is not on timeout
|
||||
|
||||
if (!isTimeout) {
|
||||
const guild = await guilds.findOne({
|
||||
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);
|
||||
|
||||
// Add credits to user
|
||||
await credits
|
||||
.findOneAndUpdate(
|
||||
{
|
||||
|
@ -38,8 +37,13 @@ module.exports = async (interaction) => {
|
|||
{ $inc: { balance: creditsEarned } },
|
||||
{ new: true, upsert: true }
|
||||
)
|
||||
|
||||
// If successful
|
||||
.then(async () => {
|
||||
// Send debug message
|
||||
logger.debug(`Credits added to user: ${interaction.member.id}`);
|
||||
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Work',
|
||||
description: `You earned ${creditNoun(creditsEarned)}`,
|
||||
|
@ -48,11 +52,11 @@ module.exports = async (interaction) => {
|
|||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
});
|
||||
|
||||
// Create a timeout for the user
|
||||
|
||||
await timeouts.create({
|
||||
guildId: member.guild.id,
|
||||
userId: member.id,
|
||||
|
@ -60,6 +64,7 @@ module.exports = async (interaction) => {
|
|||
});
|
||||
|
||||
setTimeout(async () => {
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${
|
||||
member.id
|
||||
|
@ -69,7 +74,6 @@ module.exports = async (interaction) => {
|
|||
);
|
||||
|
||||
// When timeout is out, remove it from the database
|
||||
|
||||
await timeouts.deleteOne({
|
||||
guildId: member.guild.id,
|
||||
userId: member.id,
|
||||
|
@ -77,6 +81,7 @@ module.exports = async (interaction) => {
|
|||
});
|
||||
}, 86400000);
|
||||
} else {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Work',
|
||||
description: `You have worked within the last ${
|
||||
|
@ -87,8 +92,10 @@ module.exports = async (interaction) => {
|
|||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
await interaction.editReply({ embeds: [embed] });
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`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 { Permissions } = require('discord.js');
|
||||
|
||||
const config = require('../../../config.json');
|
||||
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');
|
||||
const { balance, gift, top, work } = require('./addons');
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
|
@ -25,16 +17,6 @@ module.exports = {
|
|||
.setRequired(false)
|
||||
)
|
||||
)
|
||||
.addSubcommand((subcommand) =>
|
||||
subcommand
|
||||
.setName('redeem')
|
||||
.setDescription('Redeem your credits.')
|
||||
.addIntegerOption((option) =>
|
||||
option
|
||||
.setName('amount')
|
||||
.setDescription('How much credit you want to withdraw.')
|
||||
)
|
||||
)
|
||||
.addSubcommand((subcommand) =>
|
||||
subcommand
|
||||
.setName('gift')
|
||||
|
@ -62,35 +44,28 @@ module.exports = {
|
|||
subcommand.setName('work').setDescription('Work for credits.')
|
||||
),
|
||||
async execute(interaction) {
|
||||
const guild = await guilds.findOne({
|
||||
guildId: interaction.member.guild.id,
|
||||
});
|
||||
|
||||
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 subcommand is balance
|
||||
if (interaction.options.getSubcommand() === 'balance') {
|
||||
// Execute balance addon
|
||||
await balance(interaction);
|
||||
}
|
||||
|
||||
if (interaction.options.getSubcommand() === 'balance') {
|
||||
await balance(interaction);
|
||||
} else if (interaction.options.getSubcommand() === 'gift') {
|
||||
// If subcommand is gift
|
||||
else if (interaction.options.getSubcommand() === 'gift') {
|
||||
// Execute gift addon
|
||||
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);
|
||||
} else if (interaction.options.getSubcommand() === 'work') {
|
||||
}
|
||||
|
||||
// If subcommand is work
|
||||
else if (interaction.options.getSubcommand() === 'work') {
|
||||
// Execute work addon
|
||||
await work(interaction);
|
||||
}
|
||||
return true;
|
||||
},
|
||||
};
|
||||
|
|
|
@ -10,32 +10,35 @@ const {
|
|||
|
||||
module.exports = async (interaction) => {
|
||||
try {
|
||||
// Destructure member
|
||||
const { member } = await interaction;
|
||||
|
||||
// Options
|
||||
// Get options
|
||||
const target = await interaction.options.getUser('target');
|
||||
|
||||
// Get discord user object
|
||||
const discordUser = await interaction.client.users.fetch(
|
||||
`${target ? target.id : member.id}`
|
||||
);
|
||||
|
||||
// Databases
|
||||
// Fetch user from user
|
||||
// Get user object
|
||||
const user = await users.findOne({ userId: await discordUser.id });
|
||||
|
||||
// Fetch credit from user and guild
|
||||
// Get experience object
|
||||
const experience = await experiences.findOne({
|
||||
userId: await discordUser.id,
|
||||
guildId: await member.guild.id,
|
||||
});
|
||||
|
||||
// Fetch credit from user and guild
|
||||
// Get credit object
|
||||
const credit = await credits.findOne({
|
||||
userId: await discordUser.id,
|
||||
guildId: await member.guild.id,
|
||||
});
|
||||
|
||||
// If any of the objects return is null
|
||||
if (user === null || experience === null || credit === null) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Profile',
|
||||
description: `${
|
||||
|
@ -48,6 +51,7 @@ module.exports = async (interaction) => {
|
|||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return await interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
|
@ -80,7 +84,7 @@ module.exports = async (interaction) => {
|
|||
}
|
||||
);
|
||||
|
||||
// Create embed
|
||||
// Create embed object
|
||||
const embed = {
|
||||
author: {
|
||||
name: `${await discordUser.username}#${await discordUser.discriminator}`,
|
||||
|
@ -118,10 +122,10 @@ module.exports = async (interaction) => {
|
|||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send reply
|
||||
// Send interaction reply
|
||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
} catch (e) {
|
||||
// Send debug message
|
||||
await logger.error(e);
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
|
|
@ -17,9 +17,10 @@ module.exports = {
|
|||
)
|
||||
),
|
||||
async execute(interaction) {
|
||||
// If subcommand is view
|
||||
if (interaction.options.getSubcommand() === 'view') {
|
||||
// Execute view addon
|
||||
await view(interaction);
|
||||
}
|
||||
return true;
|
||||
},
|
||||
};
|
||||
|
|
|
@ -6,20 +6,16 @@ const { users, timeouts } = require('../../../helpers/database/models');
|
|||
|
||||
module.exports = async (interaction) => {
|
||||
// Destructure member
|
||||
|
||||
const { member } = interaction;
|
||||
|
||||
// Get options
|
||||
|
||||
const target = await interaction.options.getUser('target');
|
||||
const type = await interaction.options.getString('type');
|
||||
|
||||
// Get user object
|
||||
|
||||
const user = await users.findOne({ userId: interaction.member.id });
|
||||
|
||||
// Check if user has a timeout
|
||||
|
||||
const isTimeout = await timeouts.findOne({
|
||||
guildId: member.guild.id,
|
||||
userId: member.id,
|
||||
|
@ -27,13 +23,10 @@ module.exports = async (interaction) => {
|
|||
});
|
||||
|
||||
// If user is not on timeout
|
||||
|
||||
if (!isTimeout) {
|
||||
// Do not allow self reputation
|
||||
|
||||
if (target.id === interaction.member.id) {
|
||||
// Build embed
|
||||
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: i18next.t(
|
||||
'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] });
|
||||
}
|
||||
|
||||
// Math operators depending on type of reputation
|
||||
|
||||
// If type is positive
|
||||
if (type === 'positive') {
|
||||
user.reputation += 1;
|
||||
}
|
||||
|
||||
// If type is negative
|
||||
if (type === 'negative') {
|
||||
user.reputation -= 1;
|
||||
}
|
||||
|
||||
// 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 = {
|
||||
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 },
|
||||
};
|
||||
|
||||
// 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,
|
||||
// Create a timeout for the user
|
||||
await timeouts.create({
|
||||
guildId: member.guild.id,
|
||||
userId: member.id,
|
||||
timeoutId: 2,
|
||||
});
|
||||
});
|
||||
|
||||
setTimeout(async () => {
|
||||
// send debug message
|
||||
await logger.debug(
|
||||
`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
|
||||
|
||||
await timeouts.deleteOne({
|
||||
guildId: member.guild.id,
|
||||
userId: member.id,
|
||||
|
@ -121,6 +109,7 @@ module.exports = async (interaction) => {
|
|||
});
|
||||
}, 86400000);
|
||||
} else {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: i18next.t(
|
||||
'commands:reputation:addons:give:version01:embed:title',
|
||||
|
@ -139,8 +128,10 @@ module.exports = async (interaction) => {
|
|||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
await interaction.editReply({ embeds: [embed] });
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`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) {
|
||||
// Destructure member
|
||||
|
||||
const { member } = interaction;
|
||||
|
||||
// Command handler
|
||||
|
||||
// If subcommand is give
|
||||
if (interaction.options.getSubcommand() === 'give') {
|
||||
// Execute give addon
|
||||
|
||||
await give(interaction);
|
||||
}
|
||||
// Send debug message
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} executed /${
|
||||
interaction.commandName
|
||||
|
|
|
@ -3,29 +3,28 @@ const config = require('../../../../../config.json');
|
|||
const logger = require('../../../../handlers/logger');
|
||||
|
||||
// Database models
|
||||
|
||||
const { guilds } = require('../../../../helpers/database/models');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
// Destructure member
|
||||
|
||||
const { member } = interaction;
|
||||
|
||||
// Check permission
|
||||
|
||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Settings',
|
||||
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(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Get options
|
||||
|
||||
const status = await interaction.options.getBoolean('status');
|
||||
const rate = await interaction.options.getNumber('rate');
|
||||
const timeout = await interaction.options.getNumber('timeout');
|
||||
|
@ -34,11 +33,9 @@ module.exports = async (interaction) => {
|
|||
const workTimeout = await interaction.options.getNumber('work-timeout');
|
||||
|
||||
// Get guild object
|
||||
|
||||
const guild = await guilds.findOne({ guildId: interaction.member.guild.id });
|
||||
|
||||
// Modify values
|
||||
|
||||
guild.credits.status = status !== null ? status : guild.credits.status;
|
||||
guild.credits.rate = rate !== null ? rate : guild.credits.rate;
|
||||
guild.credits.timeout = timeout !== null ? timeout : guild.credits.timeout;
|
||||
|
@ -50,10 +47,8 @@ module.exports = async (interaction) => {
|
|||
minimumLength !== null ? minimumLength : guild.credits.minimumLength;
|
||||
|
||||
// Save guild
|
||||
|
||||
await guild.save().then(async () => {
|
||||
// Build embed
|
||||
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Credits',
|
||||
description: 'Following settings is set!',
|
||||
|
@ -82,12 +77,10 @@ module.exports = async (interaction) => {
|
|||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send reply
|
||||
|
||||
// Send interaction reply
|
||||
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
|
||||
// Send debug message
|
||||
|
||||
await logger.debug(
|
||||
`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) => {
|
||||
// Destructure member
|
||||
|
||||
const { member } = interaction;
|
||||
|
||||
// Check permission
|
||||
|
||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Settings',
|
||||
color: config.colors.error,
|
||||
|
@ -21,6 +20,8 @@ module.exports = async (interaction) => {
|
|||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
|
|
|
@ -6,12 +6,11 @@ const { pterodactyl, credits } = require('./addons');
|
|||
|
||||
module.exports = async (interaction) => {
|
||||
// Destructure member
|
||||
|
||||
const { member } = interaction;
|
||||
|
||||
// Check permission
|
||||
|
||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Settings',
|
||||
color: config.colors.error,
|
||||
|
@ -19,23 +18,24 @@ module.exports = async (interaction) => {
|
|||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Command handler
|
||||
|
||||
// If subcommand is pterodactyl
|
||||
if (interaction.options.getSubcommand() === 'pterodactyl') {
|
||||
// Execute pterodactyl addon
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
// Send debug message
|
||||
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} executed /${
|
||||
interaction.commandName
|
||||
|
|
|
@ -87,11 +87,15 @@ module.exports = {
|
|||
)
|
||||
),
|
||||
async execute(interaction) {
|
||||
// If subcommand group is guild
|
||||
if (interaction.options.getSubcommandGroup() === 'guild') {
|
||||
// Execute guild group
|
||||
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);
|
||||
}
|
||||
return true;
|
||||
},
|
||||
};
|
||||
|
|
|
@ -1,33 +1,25 @@
|
|||
const { Permissions } = require('discord.js');
|
||||
const config = require('../../../../../config.json');
|
||||
const logger = require('../../../../handlers/logger');
|
||||
|
||||
// Database models
|
||||
|
||||
const { users } = require('../../../../helpers/database/models');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
// Destructure member
|
||||
|
||||
const { member } = interaction;
|
||||
|
||||
// Get options
|
||||
|
||||
const language = await interaction.options.getString('language');
|
||||
|
||||
// Get user object
|
||||
|
||||
const user = await users.findOne({ userId: interaction.member.id });
|
||||
|
||||
// Modify values
|
||||
|
||||
user.language = language !== null ? language : user.language;
|
||||
|
||||
// Save guild
|
||||
|
||||
await user.save().then(async () => {
|
||||
// Build embed
|
||||
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Appearance',
|
||||
description: 'Following settings is set!',
|
||||
|
@ -43,12 +35,10 @@ module.exports = async (interaction) => {
|
|||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send reply
|
||||
|
||||
// Send interaction reply
|
||||
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
|
||||
// Send debug message
|
||||
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} has changed appearance settings.`
|
||||
);
|
||||
|
|
|
@ -6,32 +6,30 @@ const { appearance } = require('./addons');
|
|||
|
||||
module.exports = async (interaction) => {
|
||||
// Destructure member
|
||||
|
||||
const { member } = interaction;
|
||||
|
||||
// Check permission
|
||||
|
||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Settings',
|
||||
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(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Command handler
|
||||
|
||||
// If subcommand is appearance
|
||||
if (interaction.options.getSubcommand() === 'appearance') {
|
||||
// Execute appearance addon
|
||||
|
||||
await appearance(interaction);
|
||||
}
|
||||
|
||||
// Send debug message
|
||||
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} executed /${
|
||||
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) => {
|
||||
try {
|
||||
const target = await interaction.options.getString('target');
|
||||
// Get lookup query
|
||||
const query = await interaction.options.getString('query');
|
||||
|
||||
// Make API request
|
||||
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) => {
|
||||
// If query failed
|
||||
if (res.data.status === 'fail') {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Lookup',
|
||||
description: `${res.data.message}: ${res.data.query}`,
|
||||
|
@ -18,8 +25,14 @@ module.exports = async (interaction) => {
|
|||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
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 = {
|
||||
title: 'Lookup',
|
||||
fields: [
|
||||
|
@ -61,13 +74,15 @@ module.exports = async (interaction) => {
|
|||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
await interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
})
|
||||
.catch(async (err) => {
|
||||
await logger.error(err);
|
||||
.catch(async (e) => {
|
||||
await logger.error(e);
|
||||
});
|
||||
} catch {
|
||||
await logger.error();
|
||||
} catch (e) {
|
||||
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 { Permissions } = require('discord.js');
|
||||
|
||||
const lookup = require('./addons/lookup');
|
||||
const users = require('./addons/users');
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
|
@ -16,8 +14,8 @@ module.exports = {
|
|||
)
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName('target')
|
||||
.setDescription('The target you want to look up.')
|
||||
.setName('query')
|
||||
.setDescription('The query you want to look up.')
|
||||
.setRequired(true)
|
||||
)
|
||||
)
|
||||
|
@ -25,10 +23,10 @@ module.exports = {
|
|||
subcommand.setName('users').setDescription('Iterate all users (ADMIN)')
|
||||
),
|
||||
async execute(interaction) {
|
||||
// If subcommand is lookup
|
||||
if (interaction.options.getSubcommand() === 'lookup') {
|
||||
// Execute lookup addon
|
||||
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 = {
|
||||
name: 'guildCreate',
|
||||
async execute(guild) {
|
||||
// Destructure client
|
||||
const { client } = guild;
|
||||
|
||||
// Create guild object if not already created
|
||||
await guilds.findOne({ guildId: guild.id }, { new: true, upsert: true });
|
||||
|
||||
// Set client status
|
||||
await client.user.setPresence({
|
||||
activities: [
|
||||
{ type: 'WATCHING', name: `${client.guilds.cache.size} guilds` },
|
||||
|
|
|
@ -6,19 +6,25 @@ const { guilds } = require('../helpers/database/models');
|
|||
module.exports = {
|
||||
name: 'interactionCreate',
|
||||
async execute(interaction) {
|
||||
// Destructure member, client
|
||||
const { member, client } = interaction;
|
||||
|
||||
// If interaction is command
|
||||
if (interaction.isCommand()) {
|
||||
// Get command from collection
|
||||
const command = client.commands.get(interaction.commandName);
|
||||
|
||||
// If command do not exist
|
||||
if (!command) return;
|
||||
|
||||
// Create guild if it does not exist already
|
||||
await guilds.findOne(
|
||||
{ guildId: member.guild.id },
|
||||
{ new: true, upsert: true }
|
||||
);
|
||||
|
||||
try {
|
||||
// Defer reply
|
||||
await interaction.deferReply({
|
||||
embeds: [
|
||||
{
|
||||
|
@ -35,10 +41,17 @@ module.exports = {
|
|||
],
|
||||
ephemeral: true,
|
||||
});
|
||||
|
||||
// Execute command
|
||||
await command.execute(interaction);
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(`Executing command: ${interaction.commandName}`);
|
||||
} catch (err) {
|
||||
// Send debug message
|
||||
await logger.error(err);
|
||||
|
||||
// Send interaction reply
|
||||
await interaction.reply({
|
||||
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',
|
||||
async execute(message) {
|
||||
// Get guild object
|
||||
|
||||
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;
|
||||
|
||||
// Create user if not already created
|
||||
|
||||
await users.findOne(
|
||||
{ userId: message.author.id },
|
||||
{ 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;
|
||||
|
||||
// Needs to be updated for multi-guild to function properly
|
||||
// if (config.credits.excludedChannels.includes(message.channel.id)) return;
|
||||
|
||||
// Check if user has a timeout
|
||||
|
||||
const isTimeout = await timeouts.findOne({
|
||||
guildId: message.guild.id,
|
||||
userId: message.author.id,
|
||||
|
@ -42,44 +37,52 @@ module.exports = {
|
|||
});
|
||||
|
||||
// If user is not on timeout
|
||||
|
||||
if (!isTimeout) {
|
||||
// Add credits to user
|
||||
|
||||
await credits
|
||||
.findOneAndUpdate(
|
||||
{ userId: message.author.id, guildId: message.guild.id },
|
||||
{ $inc: { balance: guild.credits.rate } },
|
||||
{ new: true, upsert: true }
|
||||
)
|
||||
.then(async () =>
|
||||
|
||||
// If successful
|
||||
.then(async () => {
|
||||
// Send debug message
|
||||
logger.debug(
|
||||
`Guild: ${message.guild.id} Credits added to user: ${message.author.id}`
|
||||
)
|
||||
)
|
||||
);
|
||||
})
|
||||
|
||||
// If error
|
||||
.catch(async (err) => {
|
||||
// Send error message
|
||||
await logger.error(err);
|
||||
});
|
||||
|
||||
// Add points to user
|
||||
|
||||
await experiences
|
||||
.findOneAndUpdate(
|
||||
{ userId: message.author.id, guildId: message.guild.id },
|
||||
{ $inc: { points: guild.points.rate } },
|
||||
{ new: true, upsert: true }
|
||||
)
|
||||
.then(async () =>
|
||||
|
||||
// If successful
|
||||
.then(async () => {
|
||||
// Send debug message
|
||||
logger.debug(
|
||||
`Guild: ${message.guild.id} Points added to user: ${message.author.id}`
|
||||
)
|
||||
)
|
||||
);
|
||||
})
|
||||
|
||||
// If error
|
||||
.catch(async (err) => {
|
||||
// Send error message
|
||||
await logger.error(err);
|
||||
});
|
||||
|
||||
// Create a timeout for the user
|
||||
|
||||
await timeouts.create({
|
||||
guildId: message.guild.id,
|
||||
userId: message.author.id,
|
||||
|
@ -87,6 +90,7 @@ module.exports = {
|
|||
});
|
||||
|
||||
setTimeout(async () => {
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${message.guild.id} User: ${
|
||||
message.author.id
|
||||
|
@ -96,7 +100,6 @@ module.exports = {
|
|||
);
|
||||
|
||||
// When timeout is out, remove it from the database
|
||||
|
||||
await timeouts.deleteOne({
|
||||
guildId: message.guild.id,
|
||||
userId: message.author.id,
|
||||
|
@ -104,6 +107,7 @@ module.exports = {
|
|||
});
|
||||
}, guild.credits.timeout);
|
||||
} else {
|
||||
// Sned debug message
|
||||
await logger.debug(
|
||||
`Guild: ${message.guild.id} User: ${
|
||||
message.author.id
|
||||
|
|
|
@ -4,7 +4,10 @@ module.exports = {
|
|||
name: 'ready',
|
||||
once: true,
|
||||
async execute(client) {
|
||||
// Send info message
|
||||
await logger.info(`Ready! Logged in as ${client.user.tag}`);
|
||||
|
||||
// Set client status
|
||||
await client.user.setPresence({
|
||||
activities: [
|
||||
{ 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