🥅 fixed errors and redone database structure
This commit is contained in:
parent
25a1739714
commit
ddef139906
41 changed files with 819 additions and 584 deletions
|
@ -12,7 +12,7 @@ module.exports = async (interaction) => {
|
|||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Admin',
|
||||
title: ':toolbox: Admin - Counter',
|
||||
color: config.colors.error,
|
||||
description: 'You do not have permission to manage this!',
|
||||
timestamp: new Date(),
|
||||
|
|
|
@ -3,19 +3,20 @@ const config = require('../../../../../config.json');
|
|||
const logger = require('../../../../handlers/logger');
|
||||
|
||||
// Database models
|
||||
const { credits } = require('../../../../helpers/database/models');
|
||||
const { users } = require('../../../../helpers/database/models');
|
||||
|
||||
const creditNoun = require('../../../../helpers/creditNoun');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
const { guild } = member;
|
||||
|
||||
// Check permission
|
||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Admin',
|
||||
title: ':toolbox: Admin - Credits [Give]',
|
||||
color: config.colors.error,
|
||||
description: 'You do not have permission to manage this!',
|
||||
timestamp: new Date(),
|
||||
|
@ -34,7 +35,7 @@ module.exports = async (interaction) => {
|
|||
if (amount <= 0) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Give',
|
||||
title: ':toolbox: Admin - Credits [Give]',
|
||||
description: "You can't give zero or below.",
|
||||
color: 0xbb2124,
|
||||
timestamp: new Date(),
|
||||
|
@ -45,17 +46,17 @@ module.exports = async (interaction) => {
|
|||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Get toUser object
|
||||
const toUser = await credits.findOne({
|
||||
// Get toUserDB object
|
||||
const toUserDB = await users.findOne({
|
||||
userId: user.id,
|
||||
guildId: interaction.member.guild.id,
|
||||
});
|
||||
|
||||
// If toUser has no credits
|
||||
if (!toUser) {
|
||||
// If toUserDB has no credits
|
||||
if (!toUserDB) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Give',
|
||||
title: ':toolbox: Admin - Credits [Give]',
|
||||
description:
|
||||
'That user has no credits, I can not give credits to the user',
|
||||
color: config.colors.error,
|
||||
|
@ -67,18 +68,18 @@ module.exports = async (interaction) => {
|
|||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Deposit amount to toUser
|
||||
toUser.balance += amount;
|
||||
// Deposit amount to toUserDB
|
||||
toUserDB.credits += amount;
|
||||
|
||||
// Save toUser
|
||||
await toUser
|
||||
// Save toUserDB
|
||||
await toUserDB
|
||||
.save()
|
||||
|
||||
// If successful
|
||||
.then(async () => {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Give',
|
||||
title: ':toolbox: Admin - Credits [Give]',
|
||||
description: `Gave ${creditNoun(amount)} to ${user}.`,
|
||||
color: 0x22bb33,
|
||||
timestamp: new Date(),
|
||||
|
@ -97,9 +98,9 @@ module.exports = async (interaction) => {
|
|||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} gave ${
|
||||
user.id
|
||||
} ${creditNoun(amount)}.`
|
||||
`Guild: ${guild.id} User: ${member.id} gave ${user.id} ${creditNoun(
|
||||
amount
|
||||
)}.`
|
||||
);
|
||||
});
|
||||
};
|
||||
|
|
|
@ -4,7 +4,7 @@ const logger = require('../../../../handlers/logger');
|
|||
|
||||
// Database models
|
||||
|
||||
const { credits } = require('../../../../helpers/database/models');
|
||||
const { users } = require('../../../../helpers/database/models');
|
||||
const creditNoun = require('../../../../helpers/creditNoun');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
|
@ -15,7 +15,7 @@ module.exports = async (interaction) => {
|
|||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Admin',
|
||||
title: ':toolbox: Admin - Credits [Set]',
|
||||
color: config.colors.error,
|
||||
description: 'You do not have permission to manage this!',
|
||||
timestamp: new Date(),
|
||||
|
@ -34,7 +34,7 @@ module.exports = async (interaction) => {
|
|||
if (amount <= 0) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Give',
|
||||
title: ':toolbox: Admin - Credits [Set]',
|
||||
description: "You can't give zero or below.",
|
||||
color: 0xbb2124,
|
||||
timestamp: new Date(),
|
||||
|
@ -45,17 +45,17 @@ module.exports = async (interaction) => {
|
|||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Get toUser object
|
||||
const toUser = await credits.findOne({
|
||||
// Get toUserDB object
|
||||
const toUserDB = await users.findOne({
|
||||
userId: user.id,
|
||||
guildId: interaction.member.guild.id,
|
||||
});
|
||||
|
||||
// If toUser has no credits
|
||||
if (!toUser) {
|
||||
// If toUserDB has no credits
|
||||
if (!toUserDB) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Set',
|
||||
title: ':toolbox: Admin - Credits [Set]',
|
||||
description:
|
||||
'That user has no credits, I can not set credits to the user',
|
||||
color: config.colors.error,
|
||||
|
@ -67,18 +67,18 @@ module.exports = async (interaction) => {
|
|||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Set toUser with amount
|
||||
toUser.balance = amount;
|
||||
// Set toUserDB with amount
|
||||
toUserDB.credits = amount;
|
||||
|
||||
// Save toUser
|
||||
await toUser
|
||||
// Save toUserDB
|
||||
await toUserDB
|
||||
.save()
|
||||
|
||||
// If successful
|
||||
.then(async () => {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Set',
|
||||
title: ':toolbox: Admin - Credits [Set]',
|
||||
description: `You set ${creditNoun(amount)} on ${user}.`,
|
||||
color: 0x22bb33,
|
||||
timestamp: new Date(),
|
||||
|
|
|
@ -4,7 +4,7 @@ const logger = require('../../../../handlers/logger');
|
|||
|
||||
// Database models
|
||||
|
||||
const { credits } = require('../../../../helpers/database/models');
|
||||
const { users } = require('../../../../helpers/database/models');
|
||||
const creditNoun = require('../../../../helpers/creditNoun');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
|
@ -15,7 +15,7 @@ module.exports = async (interaction) => {
|
|||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Admin',
|
||||
title: ':toolbox: Admin - Credits [Take]',
|
||||
color: config.colors.error,
|
||||
description: 'You do not have permission to manage this!',
|
||||
timestamp: new Date(),
|
||||
|
@ -34,7 +34,7 @@ module.exports = async (interaction) => {
|
|||
if (amount <= 0) {
|
||||
// Give embed object
|
||||
const embed = {
|
||||
title: 'Take',
|
||||
title: ':toolbox: Admin - Credits [Take]',
|
||||
description: "You can't take zero or below.",
|
||||
color: 0xbb2124,
|
||||
timestamp: new Date(),
|
||||
|
@ -46,7 +46,7 @@ module.exports = async (interaction) => {
|
|||
}
|
||||
|
||||
// Get toUser object
|
||||
const toUser = await credits.findOne({
|
||||
const toUser = await users.findOne({
|
||||
userId: user.id,
|
||||
guildId: interaction.member.guild.id,
|
||||
});
|
||||
|
@ -55,7 +55,7 @@ module.exports = async (interaction) => {
|
|||
if (!toUser) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Take',
|
||||
title: ':toolbox: Admin - Credits [Take]',
|
||||
description:
|
||||
'That user has no credits, I can not take credits from the user',
|
||||
color: config.colors.error,
|
||||
|
@ -68,7 +68,7 @@ module.exports = async (interaction) => {
|
|||
}
|
||||
|
||||
// Withdraw amount from toUser
|
||||
toUser.balance -= amount;
|
||||
toUser.credits -= amount;
|
||||
|
||||
// Save toUser
|
||||
await toUser
|
||||
|
@ -78,7 +78,7 @@ module.exports = async (interaction) => {
|
|||
.then(async () => {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Take',
|
||||
title: ':toolbox: Admin - Credits [Take]',
|
||||
description: `You took ${creditNoun(amount)} to ${user}.`,
|
||||
color: 0x22bb33,
|
||||
timestamp: new Date(),
|
||||
|
|
|
@ -4,7 +4,7 @@ const logger = require('../../../../handlers/logger');
|
|||
|
||||
// Database models
|
||||
|
||||
const { credits } = require('../../../../helpers/database/models');
|
||||
const { users } = require('../../../../helpers/database/models');
|
||||
const creditNoun = require('../../../../helpers/creditNoun');
|
||||
const saveUser = require('../../../../helpers/saveUser');
|
||||
|
||||
|
@ -16,7 +16,7 @@ module.exports = async (interaction) => {
|
|||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Admin',
|
||||
title: ':toolbox: Admin - Credits [Transfer]',
|
||||
color: config.colors.error,
|
||||
description: 'You do not have permission to manage this!',
|
||||
timestamp: new Date(),
|
||||
|
@ -33,13 +33,13 @@ module.exports = async (interaction) => {
|
|||
const amount = await interaction.options.getInteger('amount');
|
||||
|
||||
// Get fromUser object
|
||||
const fromUser = await credits.findOne({
|
||||
const fromUser = await users.findOne({
|
||||
userId: from.id,
|
||||
guildId: interaction.member.guild.id,
|
||||
});
|
||||
|
||||
// Get toUser object
|
||||
const toUser = await credits.findOne({
|
||||
const toUser = await users.findOne({
|
||||
userId: to.id,
|
||||
guildId: interaction.member.guild.id,
|
||||
});
|
||||
|
@ -48,7 +48,7 @@ module.exports = async (interaction) => {
|
|||
if (!fromUser) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Transfer',
|
||||
title: ':toolbox: Admin - Credits [Transfer]',
|
||||
description:
|
||||
'That user has no credits, I can not transfer credits from the user',
|
||||
color: config.colors.error,
|
||||
|
@ -64,7 +64,7 @@ module.exports = async (interaction) => {
|
|||
if (!toUser) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Transfer',
|
||||
title: ':toolbox: Admin - Credits [Transfer]',
|
||||
description:
|
||||
'That user has no credits, I can not transfer credits to the user',
|
||||
color: config.colors.error,
|
||||
|
@ -80,9 +80,9 @@ module.exports = async (interaction) => {
|
|||
if (amount <= 0) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Transfer failed',
|
||||
title: ':toolbox: Admin - Credits [Transfer]',
|
||||
description: "You can't transfer zero or below.",
|
||||
color: 0xbb2124,
|
||||
color: config.colors.error,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
@ -92,10 +92,10 @@ module.exports = async (interaction) => {
|
|||
}
|
||||
|
||||
// Withdraw amount from fromUser
|
||||
fromUser.balance -= amount;
|
||||
fromUser.credits -= amount;
|
||||
|
||||
// Deposit amount to toUser
|
||||
toUser.balance += amount;
|
||||
toUser.credits += amount;
|
||||
|
||||
// Save users
|
||||
await saveUser(fromUser, toUser)
|
||||
|
@ -103,18 +103,18 @@ module.exports = async (interaction) => {
|
|||
.then(async () => {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Transfer',
|
||||
title: ':toolbox: Admin - Credits [Transfer]',
|
||||
description: `You sent ${creditNoun(amount)} from ${from} to ${to}.`,
|
||||
color: 0x22bb33,
|
||||
color: config.colors.success,
|
||||
fields: [
|
||||
{
|
||||
name: `${from.username} Balance`,
|
||||
value: `${fromUser.balance}`,
|
||||
value: `${fromUser.credits}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: `${to.username} Balance`,
|
||||
value: `${toUser.balance}`,
|
||||
value: `${toUser.credits}`,
|
||||
inline: true,
|
||||
},
|
||||
],
|
||||
|
|
|
@ -12,7 +12,7 @@ module.exports = async (interaction) => {
|
|||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Admin',
|
||||
title: ':toolbox: Admin - Credits',
|
||||
color: config.colors.error,
|
||||
description: 'You do not have permission to manage this!',
|
||||
timestamp: new Date(),
|
||||
|
|
|
@ -1,61 +1,68 @@
|
|||
const config = require('../../../../config.json');
|
||||
const logger = require('../../../handlers/logger');
|
||||
|
||||
const credits = require('../../../helpers/database/models/creditSchema');
|
||||
const { users } = require('../../../helpers/database/models');
|
||||
const creditNoun = require('../../../helpers/creditNoun');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
try {
|
||||
// Get options
|
||||
const user = await interaction.options.getUser('user');
|
||||
// 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,
|
||||
})
|
||||
// Get credit object
|
||||
const userDB = await users.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.`,
|
||||
color: config.colors.success,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
// Destructure balance
|
||||
const { credits } = userDB;
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
// If !userDB
|
||||
if (!userDB) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':dollar: Credits - Balance',
|
||||
description: `${
|
||||
user ? `${user} is` : 'You are'
|
||||
} not found in the database.`,
|
||||
color: config.colors.error,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Destructure balance
|
||||
const { balance } = data;
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Balance',
|
||||
description: `${user ? `${user} has` : 'You have'} ${creditNoun(
|
||||
balance
|
||||
)}.`,
|
||||
color: config.colors.success,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
// If !credits
|
||||
if (!credits) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':dollar: Credits - Balance',
|
||||
description: `${user ? `${user} has` : 'You have'} no credits.`,
|
||||
color: config.colors.success,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
})
|
||||
.catch(async (e) => {
|
||||
// Send debug message
|
||||
await logger.error(e);
|
||||
});
|
||||
} catch (e) {
|
||||
// Send debug message
|
||||
await logger.error(e);
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// If credits
|
||||
else if (credits) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':dollar: Credits - Balance',
|
||||
description: `${user ? `${user} has` : 'You have'} ${creditNoun(
|
||||
credits
|
||||
)}.`,
|
||||
color: config.colors.success,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
const config = require('../../../../config.json');
|
||||
const logger = require('../../../handlers/logger');
|
||||
|
||||
const credits = require('../../../helpers/database/models/creditSchema');
|
||||
const { users } = require('../../../helpers/database/models');
|
||||
const saveUser = require('../../../helpers/saveUser');
|
||||
const creditNoun = require('../../../helpers/creditNoun');
|
||||
|
||||
|
@ -12,17 +12,26 @@ module.exports = async (interaction) => {
|
|||
const amount = await interaction.options.getInteger('amount');
|
||||
const reason = await interaction.options.getString('reason');
|
||||
|
||||
// Get data object
|
||||
const data = await credits.findOne({
|
||||
const { member } = interaction;
|
||||
const { guild } = member;
|
||||
|
||||
// Get fromUserDB object
|
||||
const fromUserDB = await users.findOne({
|
||||
userId: interaction.user.id,
|
||||
guildId: interaction.member.guild.id,
|
||||
});
|
||||
|
||||
// Get toUserDB object
|
||||
const toUserDB = await users.findOne({
|
||||
userId: 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',
|
||||
title: ':dollar: Credits - Gift',
|
||||
description: "You can't pay yourself.",
|
||||
color: 0xbb2124,
|
||||
timestamp: new Date(),
|
||||
|
@ -37,7 +46,7 @@ module.exports = async (interaction) => {
|
|||
if (amount <= 0) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Gift',
|
||||
title: ':dollar: Credits - Gift',
|
||||
description: "You can't pay zero or below.",
|
||||
color: 0xbb2124,
|
||||
timestamp: new Date(),
|
||||
|
@ -49,11 +58,11 @@ module.exports = async (interaction) => {
|
|||
}
|
||||
|
||||
// If user has below gifting amount
|
||||
if (data.balance < amount) {
|
||||
if (fromUserDB.credits < amount) {
|
||||
// Create embed
|
||||
const embed = {
|
||||
title: 'Gift',
|
||||
description: `You have insufficient credits. Your balance is ${data.balance}`,
|
||||
title: ':dollar: Credits - Gift',
|
||||
description: `You have insufficient credits. Your credits is ${fromUserDB.credits}`,
|
||||
color: 0xbb2124,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
|
@ -63,23 +72,11 @@ module.exports = async (interaction) => {
|
|||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// 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) {
|
||||
// If toUserDB has no credits
|
||||
if (!toUserDB) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Gift',
|
||||
title: ':dollar: Credits - Gift',
|
||||
description:
|
||||
'That user has no credits, I can not gift credits to the user',
|
||||
color: config.colors.error,
|
||||
|
@ -91,20 +88,20 @@ module.exports = async (interaction) => {
|
|||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
|
||||
// Withdraw amount from fromUser
|
||||
fromUser.balance -= amount;
|
||||
// Withdraw amount from fromUserDB
|
||||
fromUserDB.credits -= amount;
|
||||
|
||||
// Deposit amount to toUser
|
||||
toUser.balance += amount;
|
||||
// Deposit amount to toUserDB
|
||||
toUserDB.credits += amount;
|
||||
|
||||
// Save users
|
||||
await saveUser(fromUser, toUser).then(async () => {
|
||||
await saveUser(fromUserDB, toUserDB).then(async () => {
|
||||
// Create interaction embed object
|
||||
const interactionEmbed = {
|
||||
title: 'Gift',
|
||||
title: ':dollar: Credits - Gift',
|
||||
description: `You sent ${creditNoun(amount)} to ${user}${
|
||||
reason ? ` with reason: ${reason}` : ''
|
||||
}. Your new balance is ${creditNoun(fromUser.balance)}.`,
|
||||
}. Your new credits is ${creditNoun(fromUserDB.credits)}.`,
|
||||
color: 0x22bb33,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
|
@ -112,12 +109,12 @@ module.exports = async (interaction) => {
|
|||
|
||||
// Create DM embed object
|
||||
const dmEmbed = {
|
||||
title: 'Gift',
|
||||
title: ':dollar: Credits - Gift',
|
||||
description: `You received ${creditNoun(amount)} from ${
|
||||
interaction.user
|
||||
}${
|
||||
reason ? ` with reason: ${reason}` : ''
|
||||
}. Your new balance is ${creditNoun(toUser.balance)}.`,
|
||||
}. Your new credits is ${creditNoun(toUserDB.credits)}.`,
|
||||
color: 0x22bb33,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
|
@ -131,7 +128,7 @@ module.exports = async (interaction) => {
|
|||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Gift sent from: ${interaction.user.username} to: ${user.username}`
|
||||
`Guild: ${guild.id} User: ${member.id} gift sent from: ${interaction.user.id} to: ${user.id}`
|
||||
);
|
||||
|
||||
// Send interaction reply
|
||||
|
|
|
@ -1,39 +1,35 @@
|
|||
const config = require('../../../../config.json');
|
||||
const credits = require('../../../helpers/database/models/creditSchema');
|
||||
const { users } = require('../../../helpers/database/models');
|
||||
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
|
||||
const usersDB = await users.find({ guildId: interaction.member.guild.id });
|
||||
|
||||
// Sort them after balance amount (ascending)
|
||||
.sort((a, b) => (a.balance > b.balance ? -1 : 1))
|
||||
const topTen = usersDB
|
||||
|
||||
// Return the top 10
|
||||
.slice(0, 10);
|
||||
// Sort them after credits amount (ascending)
|
||||
.sort((a, b) => (a.credits > b.credits ? -1 : 1))
|
||||
|
||||
// Create entry object
|
||||
const entry = (x, index) =>
|
||||
`**Top ${index + 1}** - <@${x.userId}> ${creditNoun(x.balance)}`;
|
||||
// Return the top 10
|
||||
.slice(0, 10);
|
||||
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Balance Top',
|
||||
description: `Below are the top ten.\n${topTen
|
||||
.map((x, index) => entry(x, index))
|
||||
.join('\n')}`,
|
||||
color: 0x22bb33,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
// Create entry object
|
||||
const entry = (x, index) =>
|
||||
`**Top ${index + 1}** - <@${x.userId}> ${creditNoun(x.credits)}`;
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
});
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':dollar: Credits - Top',
|
||||
description: `Below are the top ten.\n${topTen
|
||||
.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 });
|
||||
};
|
||||
|
|
|
@ -10,82 +10,76 @@ const creditNoun = require('../../../helpers/creditNoun');
|
|||
module.exports = async (interaction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
const { guild } = member;
|
||||
|
||||
// Check if user has a timeout
|
||||
const isTimeout = await timeouts.findOne({
|
||||
guildId: member.guild.id,
|
||||
guildId: guild.id,
|
||||
userId: member.id,
|
||||
timeoutId: 3,
|
||||
timeoutId: '2022-03-15-19-16',
|
||||
});
|
||||
|
||||
const guild = await guilds.findOne({
|
||||
guildId: member.guild.id,
|
||||
const guildDB = await guilds.findOne({
|
||||
guildId: guild.id,
|
||||
});
|
||||
|
||||
// If user is not on timeout
|
||||
if (!isTimeout) {
|
||||
// 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() * guildDB.credits.workRate);
|
||||
|
||||
// Add credits to user
|
||||
await credits
|
||||
.findOneAndUpdate(
|
||||
{
|
||||
userId: interaction.member.id,
|
||||
guildId: interaction.member.guild.id,
|
||||
},
|
||||
{ $inc: { balance: creditsEarned } },
|
||||
{ new: true, upsert: true }
|
||||
)
|
||||
const userDB = await users.findOne({
|
||||
userId: member.id,
|
||||
guildId: guild.id,
|
||||
});
|
||||
|
||||
// If successful
|
||||
.then(async () => {
|
||||
// Send debug message
|
||||
logger.debug(`Credits added to user: ${interaction.member.id}`);
|
||||
userDB.credits += creditsEarned;
|
||||
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Work',
|
||||
description: `You earned ${creditNoun(creditsEarned)}`,
|
||||
color: config.colors.success,
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
await userDB.save().then(async () => {
|
||||
// Send debug message
|
||||
await logger.debug(`Credits added to user: ${interaction.member.id}`);
|
||||
|
||||
// Send interaction reply
|
||||
return interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
});
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':dollar: Credits - Work',
|
||||
description: `You have earned ${creditNoun(creditsEarned)}`,
|
||||
color: config.colors.success,
|
||||
timestamp: new Date(),
|
||||
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,
|
||||
guildId: guild.id,
|
||||
userId: member.id,
|
||||
timeoutId: 3,
|
||||
timeoutId: '2022-03-15-19-16',
|
||||
});
|
||||
|
||||
setTimeout(async () => {
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${
|
||||
member.id
|
||||
} has not worked within the last ${
|
||||
guild.work.timeout / 1000
|
||||
`Guild: ${guild.id} User: ${member.id} has not worked within the last ${
|
||||
guildDB.work.timeout / 1000
|
||||
} seconds, work can be done`
|
||||
);
|
||||
|
||||
// When timeout is out, remove it from the database
|
||||
await timeouts.deleteOne({
|
||||
guildId: member.guild.id,
|
||||
guildId: guild.id,
|
||||
userId: member.id,
|
||||
timeoutId: 3,
|
||||
timeoutId: '2022-03-15-19-16',
|
||||
});
|
||||
}, 86400000);
|
||||
}, guildDB.credits.workTimeout);
|
||||
} else {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Work',
|
||||
title: ':dollar: Credits - Work',
|
||||
description: `You have worked within the last ${
|
||||
guild.credits.workTimeout / 1000
|
||||
guildDB.credits.workTimeout / 1000
|
||||
} seconds, you can not work now!`,
|
||||
timestamp: new Date(),
|
||||
color: config.colors.error,
|
||||
|
@ -97,7 +91,7 @@ module.exports = async (interaction) => {
|
|||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} has worked within last day, no work can be done`
|
||||
`Guild: ${guild.id} User: ${member.id} has worked within last day, no work can be done`
|
||||
);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -12,6 +12,7 @@ module.exports = async (interaction) => {
|
|||
try {
|
||||
// Destructure member
|
||||
const { member } = await interaction;
|
||||
const { guild } = member;
|
||||
|
||||
// Get options
|
||||
const target = await interaction.options.getUser('target');
|
||||
|
@ -22,68 +23,11 @@ module.exports = async (interaction) => {
|
|||
);
|
||||
|
||||
// Get user object
|
||||
const user = await users.findOne({ userId: await discordUser.id });
|
||||
|
||||
// Get experience object
|
||||
const experience = await experiences.findOne({
|
||||
const userDB = await users.findOne({
|
||||
userId: await discordUser.id,
|
||||
guildId: await member.guild.id,
|
||||
guildId: guild.id,
|
||||
});
|
||||
|
||||
// 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: `${
|
||||
target || 'You'
|
||||
} have to write something before viewing ${
|
||||
target ? 'their' : 'your'
|
||||
} profile!`,
|
||||
timestamp: new Date(),
|
||||
color: config.colors.error,
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
return await interaction.editReply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
// Language variables
|
||||
const notAvailableText = i18next.t('general:not_available', {
|
||||
lng: await user.language,
|
||||
});
|
||||
const reputationText = i18next.t(
|
||||
'commands:profile:addons:view:embed:reputation',
|
||||
{
|
||||
lng: await user.language,
|
||||
}
|
||||
);
|
||||
const levelText = i18next.t('commands:profile:addons:view:embed:level', {
|
||||
lng: await user.language,
|
||||
});
|
||||
const pointsText = i18next.t('commands:profile:addons:view:embed:points', {
|
||||
lng: await user.language,
|
||||
});
|
||||
const creditsText = i18next.t(
|
||||
'commands:profile:addons:view:embed:credits',
|
||||
{
|
||||
lng: await user.language,
|
||||
}
|
||||
);
|
||||
const languageCodeText = i18next.t(
|
||||
'commands:profile:addons:view:embed:language_code',
|
||||
{
|
||||
lng: await user.language,
|
||||
}
|
||||
);
|
||||
|
||||
// Create embed object
|
||||
const embed = {
|
||||
author: {
|
||||
|
@ -93,28 +37,28 @@ module.exports = async (interaction) => {
|
|||
color: config.colors.success,
|
||||
fields: [
|
||||
{
|
||||
name: `:money_with_wings: ${creditsText}`,
|
||||
value: `${(await credit.balance) || `${notAvailableText}`}`,
|
||||
name: `:dollar: Credits`,
|
||||
value: `${userDB.credits || 'Not found'}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: `:squeeze_bottle: ${levelText}`,
|
||||
value: `${(await experience.level) || `${notAvailableText}`}`,
|
||||
name: `:squeeze_bottle: Level`,
|
||||
value: `${userDB.level || 'Not found'}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: `:squeeze_bottle: ${pointsText}`,
|
||||
value: `${(await experience.points) || `${notAvailableText}`}`,
|
||||
name: `:squeeze_bottle: Points`,
|
||||
value: `${userDB.points || 'Not found'}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: `:loudspeaker: ${reputationText}`,
|
||||
value: `${(await user.reputation) || `${notAvailableText}`}`,
|
||||
name: `:loudspeaker: Reputation`,
|
||||
value: `${userDB.reputation || 'Not found'}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: `:rainbow_flag: ${languageCodeText}`,
|
||||
value: `${(await user.language) || `${notAvailableText}`}`,
|
||||
name: `:rainbow_flag: Language`,
|
||||
value: `${userDB.language || 'Not found'}`,
|
||||
inline: true,
|
||||
},
|
||||
],
|
||||
|
|
|
@ -7,17 +7,21 @@ const { users, timeouts } = require('../../../helpers/database/models');
|
|||
module.exports = async (interaction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
const { guild } = member;
|
||||
|
||||
// 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 });
|
||||
const userDB = await users.findOne({
|
||||
userId: member.id,
|
||||
guildId: guild.id,
|
||||
});
|
||||
|
||||
// Check if user has a timeout
|
||||
const isTimeout = await timeouts.findOne({
|
||||
guildId: member.guild.id,
|
||||
guildId: guild.id,
|
||||
userId: member.id,
|
||||
timeoutId: 2,
|
||||
});
|
||||
|
@ -28,18 +32,11 @@ module.exports = async (interaction) => {
|
|||
if (target.id === interaction.member.id) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: i18next.t(
|
||||
'commands:reputation:addons:give:version03:embed:title',
|
||||
{
|
||||
lng: await user.language,
|
||||
}
|
||||
),
|
||||
description: i18next.t(
|
||||
'commands:reputation:addons:give:version02:embed:title',
|
||||
{
|
||||
lng: await user.language,
|
||||
}
|
||||
),
|
||||
title: ':loudspeaker: Reputation - Give',
|
||||
description: 'You can not repute yourself.',
|
||||
timestamp: new Date(),
|
||||
color: config.colors.error,
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
|
@ -48,24 +45,19 @@ module.exports = async (interaction) => {
|
|||
|
||||
// If type is positive
|
||||
if (type === 'positive') {
|
||||
user.reputation += 1;
|
||||
userDB.reputation += 1;
|
||||
}
|
||||
|
||||
// If type is negative
|
||||
if (type === 'negative') {
|
||||
user.reputation -= 1;
|
||||
userDB.reputation -= 1;
|
||||
}
|
||||
|
||||
// Save user
|
||||
await user.save().then(async () => {
|
||||
await userDB.save().then(async () => {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: i18next.t(
|
||||
'commands:reputation:addons:give:version02:embed:title',
|
||||
{
|
||||
lng: await user.language,
|
||||
}
|
||||
),
|
||||
title: ':loudspeaker: Reputation - Give',
|
||||
description: `You have given ${target} a ${type} reputation!`,
|
||||
timestamp: new Date(),
|
||||
color: config.colors.success,
|
||||
|
@ -91,7 +83,11 @@ module.exports = async (interaction) => {
|
|||
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`
|
||||
`Guild: ${member.guild.id} User: ${
|
||||
member.id
|
||||
} has not repute within last ${
|
||||
config.reputation.timeout / 1000
|
||||
} seconds, reputation can be given`
|
||||
);
|
||||
|
||||
// When timeout is out, remove it from the database
|
||||
|
@ -100,22 +96,14 @@ module.exports = async (interaction) => {
|
|||
userId: member.id,
|
||||
timeoutId: 2,
|
||||
});
|
||||
}, 86400000);
|
||||
}, config.reputation.timeout);
|
||||
} else {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: i18next.t(
|
||||
'commands:reputation:addons:give:version01:embed:title',
|
||||
{
|
||||
lng: await user.language,
|
||||
}
|
||||
),
|
||||
description: i18next.t(
|
||||
'commands:reputation:addons:give:version01:embed:description',
|
||||
{
|
||||
lng: await user.language,
|
||||
}
|
||||
),
|
||||
title: ':loudspeaker: Reputation - Give',
|
||||
description: `You have given reputation within the last ${
|
||||
config.reputation.timeout / 1000
|
||||
} seconds, you can not repute now!`,
|
||||
timestamp: new Date(),
|
||||
color: config.colors.error,
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
|
@ -126,7 +114,9 @@ module.exports = async (interaction) => {
|
|||
|
||||
// Send debug message
|
||||
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 ${
|
||||
config.reputation.timeout / 1000
|
||||
} seconds, no reputation can be given`
|
||||
);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -8,12 +8,13 @@ const { guilds } = require('../../../../helpers/database/models');
|
|||
module.exports = async (interaction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
const { guild } = member;
|
||||
|
||||
// Check permission
|
||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Settings',
|
||||
title: ':hammer: Settings - Guild [Credits]',
|
||||
color: config.colors.error,
|
||||
description: `You don't have permission to manage this!`,
|
||||
timestamp: new Date(),
|
||||
|
@ -33,43 +34,50 @@ 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 });
|
||||
const guildDB = await guilds.findOne({
|
||||
guildId: 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;
|
||||
guild.credits.workRate =
|
||||
workRate !== null ? workRate : guild.credits.workRate;
|
||||
guild.credits.workTimeout =
|
||||
workTimeout !== null ? workTimeout : guild.credits.workTimeout;
|
||||
guild.credits.minimumLength =
|
||||
minimumLength !== null ? minimumLength : guild.credits.minimumLength;
|
||||
guildDB.credits.status = status !== null ? status : guildDB.credits.status;
|
||||
guildDB.credits.rate = rate !== null ? rate : guildDB.credits.rate;
|
||||
guildDB.credits.timeout =
|
||||
timeout !== null ? timeout : guildDB.credits.timeout;
|
||||
guildDB.credits.workRate =
|
||||
workRate !== null ? workRate : guildDB.credits.workRate;
|
||||
guildDB.credits.workTimeout =
|
||||
workTimeout !== null ? workTimeout : guildDB.credits.workTimeout;
|
||||
guildDB.credits.minimumLength =
|
||||
minimumLength !== null ? minimumLength : guildDB.credits.minimumLength;
|
||||
|
||||
// Save guild
|
||||
await guild.save().then(async () => {
|
||||
await guildDB.save().then(async () => {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Settings - Guild - Credits',
|
||||
title: ':hammer: Settings - Guild [Credits]',
|
||||
description: 'Following settings is set!',
|
||||
color: config.colors.success,
|
||||
fields: [
|
||||
{ name: '🤖 Status', value: `${guild.credits.status}`, inline: true },
|
||||
{ name: '📈 Rate', value: `${guild.credits.rate}`, inline: true },
|
||||
{ name: '🤖 Status', value: `${guildDB.credits.status}`, inline: true },
|
||||
{ name: '📈 Rate', value: `${guildDB.credits.rate}`, inline: true },
|
||||
{
|
||||
name: '📈 Work Rate',
|
||||
value: `${guild.credits.workRate}`,
|
||||
value: `${guildDB.credits.workRate}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: '🔨 Minimum Length',
|
||||
value: `${guild.credits.minimumLength}`,
|
||||
value: `${guildDB.credits.minimumLength}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: '⏰ Timeout',
|
||||
value: `${guildDB.credits.timeout}`,
|
||||
inline: true,
|
||||
},
|
||||
{ name: '⏰ Timeout', value: `${guild.credits.timeout}`, inline: true },
|
||||
{
|
||||
name: '⏰ Work Timeout',
|
||||
value: `${guild.credits.workTimeout}`,
|
||||
value: `${guildDB.credits.workTimeout}`,
|
||||
inline: true,
|
||||
},
|
||||
],
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
const pterodactyl = require('./pterodactyl');
|
||||
const credits = require('./credits');
|
||||
const points = require('./points');
|
||||
|
||||
module.exports = { pterodactyl, credits };
|
||||
module.exports = { pterodactyl, credits, points };
|
||||
|
|
80
src/commands/settings/guild/addons/points.js
Normal file
80
src/commands/settings/guild/addons/points.js
Normal file
|
@ -0,0 +1,80 @@
|
|||
const { Permissions } = require('discord.js');
|
||||
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;
|
||||
const { guild } = member;
|
||||
|
||||
// Check permission
|
||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':hammer: Settings - Guild [Points]',
|
||||
color: config.colors.error,
|
||||
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');
|
||||
const minimumLength = await interaction.options.getNumber('minimum-length');
|
||||
|
||||
// Get guild object
|
||||
const guildDB = await guilds.findOne({
|
||||
guildId: guild.id,
|
||||
});
|
||||
|
||||
// Modify values
|
||||
guildDB.credits.status = status !== null ? status : guildDB.credits.status;
|
||||
guildDB.credits.rate = rate !== null ? rate : guildDB.credits.rate;
|
||||
guildDB.credits.timeout =
|
||||
timeout !== null ? timeout : guildDB.credits.timeout;
|
||||
guildDB.credits.minimumLength =
|
||||
minimumLength !== null ? minimumLength : guildDB.credits.minimumLength;
|
||||
|
||||
// Save guild
|
||||
await guildDB.save().then(async () => {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: ':hammer: Settings - Guild [Points]',
|
||||
description: 'Following settings is set!',
|
||||
color: config.colors.success,
|
||||
fields: [
|
||||
{ name: '🤖 Status', value: `${guildDB.credits.status}`, inline: true },
|
||||
{ name: '📈 Rate', value: `${guildDB.credits.rate}`, inline: true },
|
||||
{
|
||||
name: '🔨 Minimum Length',
|
||||
value: `${guildDB.credits.minimumLength}`,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: '⏰ Timeout',
|
||||
value: `${guildDB.credits.timeout}`,
|
||||
inline: true,
|
||||
},
|
||||
],
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Send interaction reply
|
||||
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${guild.id} User: ${member.id} has changed credit details.`
|
||||
);
|
||||
});
|
||||
};
|
|
@ -9,12 +9,13 @@ const { apis } = require('../../../../helpers/database/models');
|
|||
module.exports = async (interaction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
const { guild } = member;
|
||||
|
||||
// Check permission
|
||||
if (!member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Settings - Guild - Pterodactyl',
|
||||
title: ':hammer: Settings - Guild [Pterodactyl]',
|
||||
color: config.colors.error,
|
||||
description: 'You do not have permission to manage this!',
|
||||
timestamp: new Date(),
|
||||
|
@ -34,7 +35,7 @@ module.exports = async (interaction) => {
|
|||
|
||||
await apis
|
||||
.findOneAndUpdate(
|
||||
{ guildId: member.guild.id },
|
||||
{ guildId: guild.id },
|
||||
{ url, token },
|
||||
{ new: true, upsert: true }
|
||||
)
|
||||
|
@ -42,7 +43,7 @@ module.exports = async (interaction) => {
|
|||
// Build embed
|
||||
|
||||
const embed = {
|
||||
title: 'Settings - Guild - Pterodactyl',
|
||||
title: ':hammer: Settings - Guild [Pterodactyl]',
|
||||
color: config.colors.success,
|
||||
description: 'Pterodactyl settings is saved!',
|
||||
timestamp: new Date(),
|
||||
|
@ -56,7 +57,7 @@ module.exports = async (interaction) => {
|
|||
// Send debug message
|
||||
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} has changed api credentials.`
|
||||
`Guild: ${guild.id} User: ${member.id} has changed api credentials.`
|
||||
);
|
||||
});
|
||||
};
|
||||
|
|
|
@ -2,7 +2,7 @@ const { Permissions } = require('discord.js');
|
|||
const config = require('../../../../config.json');
|
||||
const logger = require('../../../handlers/logger');
|
||||
|
||||
const { pterodactyl, credits } = require('./addons');
|
||||
const { pterodactyl, credits, points } = require('./addons');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
// Destructure member
|
||||
|
@ -35,6 +35,12 @@ module.exports = async (interaction) => {
|
|||
await credits(interaction);
|
||||
}
|
||||
|
||||
// If subcommand is points
|
||||
else if (interaction.options.getSubcommand() === 'points') {
|
||||
// Execute points addon
|
||||
await points(interaction);
|
||||
}
|
||||
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} executed /${
|
||||
|
|
|
@ -68,6 +68,33 @@ module.exports = {
|
|||
)
|
||||
)
|
||||
)
|
||||
.addSubcommand((command) =>
|
||||
command
|
||||
.setName('points')
|
||||
.setDescription('Points')
|
||||
.addBooleanOption((option) =>
|
||||
option
|
||||
.setName('status')
|
||||
.setDescription('Should credits be enabled?')
|
||||
)
|
||||
.addNumberOption((option) =>
|
||||
option
|
||||
.setName('rate')
|
||||
.setDescription('Amount of credits per message.')
|
||||
)
|
||||
.addNumberOption((option) =>
|
||||
option
|
||||
.setName('minimum-length')
|
||||
.setDescription('Minimum length of message to earn credits.')
|
||||
)
|
||||
.addNumberOption((option) =>
|
||||
option
|
||||
.setName('timeout')
|
||||
.setDescription(
|
||||
'Timeout between earning credits (milliseconds).'
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
.addSubcommandGroup((group) =>
|
||||
group
|
||||
|
|
|
@ -7,27 +7,28 @@ const { users } = require('../../../../helpers/database/models');
|
|||
module.exports = async (interaction) => {
|
||||
// Destructure member
|
||||
const { member } = interaction;
|
||||
const { guild } = member;
|
||||
|
||||
// Get options
|
||||
const language = await interaction.options.getString('language');
|
||||
|
||||
// Get user object
|
||||
const user = await users.findOne({ userId: interaction.member.id });
|
||||
const userDB = await users.findOne({ userId: member.id, guildId: guild.id });
|
||||
|
||||
// Modify values
|
||||
user.language = language !== null ? language : user.language;
|
||||
userDB.language = language !== null ? language : userDB.language;
|
||||
|
||||
// Save guild
|
||||
await user.save().then(async () => {
|
||||
await userDB.save().then(async () => {
|
||||
// Create embed object
|
||||
const embed = {
|
||||
title: 'Settings - User - Appearance',
|
||||
title: ':hammer: Settings - User [Appearance]',
|
||||
description: 'Following settings is set!',
|
||||
color: config.colors.success,
|
||||
fields: [
|
||||
{
|
||||
name: '🏳️🌈 Language',
|
||||
value: `${user.language}`,
|
||||
value: `${userDB.language}`,
|
||||
inline: true,
|
||||
},
|
||||
],
|
||||
|
|
|
@ -8,21 +8,6 @@ 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 - User',
|
||||
color: config.colors.error,
|
||||
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 });
|
||||
}
|
||||
|
||||
// If subcommand is appearance
|
||||
if (interaction.options.getSubcommand() === 'appearance') {
|
||||
// Execute appearance addon
|
||||
|
|
|
@ -7,66 +7,60 @@ 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 });
|
||||
}
|
||||
const { member } = interaction;
|
||||
const { guild } = member;
|
||||
|
||||
// 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,
|
||||
const userDB = await users.findOne({
|
||||
userId: member.id,
|
||||
guildId: guild.id,
|
||||
});
|
||||
|
||||
// Get DM user object
|
||||
const dmUser = interaction.client.users.cache.get(interaction.member.user.id);
|
||||
const dmUser = interaction.client.users.cache.get(member.id);
|
||||
|
||||
// Stop if amount or user balance is below 100
|
||||
if ((amount || user.balance) < 100) {
|
||||
// Stop if amount or user credits is below 100
|
||||
if ((amount || userDB.credits) < 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)}` }],
|
||||
fields: [
|
||||
{ name: 'Your balance', value: `${creditNoun(userDB.credits)}` },
|
||||
],
|
||||
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) {
|
||||
// Stop if amount or user credits is above 1.000.000
|
||||
if ((amount || userDB.credits) > 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)}` }],
|
||||
fields: [
|
||||
{ name: 'Your balance', value: `${creditNoun(userDB.credits)}` },
|
||||
],
|
||||
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) {
|
||||
// Stop if user credits is below amount
|
||||
if (userDB.credits < 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)}` }],
|
||||
fields: [
|
||||
{ name: 'Your balance', value: `${creditNoun(userDB.credits)}` },
|
||||
],
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
@ -78,7 +72,7 @@ module.exports = async (interaction) => {
|
|||
|
||||
// Get api object
|
||||
const apiCredentials = await apis.findOne({
|
||||
guildId: interaction.member.guild.id,
|
||||
guildId: guild.id,
|
||||
});
|
||||
|
||||
// Create a api instance
|
||||
|
@ -97,8 +91,8 @@ module.exports = async (interaction) => {
|
|||
.post('vouchers', {
|
||||
uses: 1,
|
||||
code,
|
||||
credits: amount || user.balance,
|
||||
memo: `${interaction.createdTimestamp} - ${interaction.user.id}`,
|
||||
credits: amount || userDB.credits,
|
||||
memo: `${interaction.createdTimestamp} - ${member.id}`,
|
||||
})
|
||||
|
||||
// If successful
|
||||
|
@ -111,7 +105,7 @@ module.exports = async (interaction) => {
|
|||
{ name: 'Code', value: `${code}`, inline: true },
|
||||
{
|
||||
name: 'Credits',
|
||||
value: `${amount || user.balance}`,
|
||||
value: `${amount || userDB.credits}`,
|
||||
inline: true,
|
||||
},
|
||||
],
|
||||
|
@ -129,17 +123,17 @@ module.exports = async (interaction) => {
|
|||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
|
||||
// Withdraw amount from user balance
|
||||
user.balance -= amount || user.balance;
|
||||
// Withdraw amount from user credits
|
||||
userDB.credits -= amount || userDB.credits;
|
||||
|
||||
// Save new balance
|
||||
await user
|
||||
// Save new credits
|
||||
await userDB
|
||||
.save()
|
||||
// If successful
|
||||
.then(async () => {
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`User: ${user.username} redeemed: ${creditNoun(amount)}`
|
||||
`User: ${member.username} redeemed: ${creditNoun(amount)}`
|
||||
);
|
||||
|
||||
// Send DM message
|
||||
|
|
|
@ -3,12 +3,17 @@ const axios = require('axios');
|
|||
const config = require('../../../../config.json');
|
||||
const logger = require('../../../handlers/logger');
|
||||
|
||||
const { credits, apis } = require('../../../helpers/database/models');
|
||||
const { guilds, users } = require('../../../helpers/database/models');
|
||||
const creditNoun = require('../../../helpers/creditNoun');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
const name = interaction.options.getString('name');
|
||||
|
||||
const { member } = interaction;
|
||||
const { guild } = member;
|
||||
|
||||
const guildDB = await guilds.findOne({ guildId: guild.id });
|
||||
|
||||
guild.roles
|
||||
.create({
|
||||
data: {
|
||||
|
@ -17,8 +22,25 @@ module.exports = async (interaction) => {
|
|||
},
|
||||
reason: `${interaction.member.id} bought from shop`,
|
||||
})
|
||||
.then(console.log)
|
||||
.then(async (role) => {
|
||||
console.log(role);
|
||||
userDB.credits -= guildDB.shop.roles.pricePerHour;
|
||||
await userDB.save().then(async () => {
|
||||
const embed = {
|
||||
title: ':shopping_cart: Shop - Roles',
|
||||
description: `You have bought ${role.name} for ${guildDB.shop.roles.pricePerHour} per hour.`,
|
||||
color: config.colors.error,
|
||||
fields: [
|
||||
{ name: 'Your balance', value: `${creditNoun(userDB.credits)}` },
|
||||
],
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
return await interaction.editReply({
|
||||
embeds: [embed],
|
||||
ephemeral: true,
|
||||
});
|
||||
});
|
||||
})
|
||||
.catch(console.error);
|
||||
|
||||
interaction.editReply({ content: 'Roles' });
|
||||
};
|
||||
|
|
|
@ -38,9 +38,9 @@ module.exports = {
|
|||
command
|
||||
.setName('cancel')
|
||||
.setDescription('Cancel a custom role')
|
||||
.addStringOption((option) =>
|
||||
.addRoleOption((option) =>
|
||||
option
|
||||
.setName('name')
|
||||
.setName('role')
|
||||
.setDescription('Name of the role you wish to cancel.')
|
||||
)
|
||||
)
|
||||
|
|
|
@ -4,8 +4,7 @@ const config = require('../../../../../config.json');
|
|||
const logger = require('../../../../handlers/logger');
|
||||
|
||||
const {
|
||||
credits,
|
||||
apis,
|
||||
users,
|
||||
shopRoles,
|
||||
guilds,
|
||||
} = require('../../../../helpers/database/models');
|
||||
|
@ -13,6 +12,7 @@ const creditNoun = require('../../../../helpers/creditNoun');
|
|||
|
||||
module.exports = async (interaction) => {
|
||||
const { member } = interaction;
|
||||
const { guild } = member;
|
||||
|
||||
const name = await interaction.options.getString('name');
|
||||
|
||||
|
@ -22,32 +22,47 @@ module.exports = async (interaction) => {
|
|||
color: 'RED',
|
||||
reason: `${interaction.member.id} bought from shop`,
|
||||
})
|
||||
.then(async (data) => {
|
||||
.then(async (role) => {
|
||||
// Get guild object
|
||||
const guild = await guilds.findOne({
|
||||
const guildDB = await guilds.findOne({
|
||||
guildId: interaction.member.guild.id,
|
||||
});
|
||||
|
||||
const userObject = await credits.findOne({
|
||||
const userDB = await users.findOne({
|
||||
userId: member.id,
|
||||
guildId: interaction.member.guild.id,
|
||||
guildId: guild.id,
|
||||
});
|
||||
const { pricePerHour } = guild.shop.roles;
|
||||
const { pricePerHour } = guildDB.shop.roles;
|
||||
|
||||
userObject.balance -= pricePerHour;
|
||||
userDB.credits -= pricePerHour;
|
||||
|
||||
shopRoles.create({
|
||||
roleId: data.id,
|
||||
await userDB.save();
|
||||
|
||||
await shopRoles.create({
|
||||
roleId: role.id,
|
||||
userId: member.id,
|
||||
guildId: member.guild.id,
|
||||
guildId: guild.id,
|
||||
pricePerHour,
|
||||
lastPayed: new Date(),
|
||||
});
|
||||
|
||||
interaction.member.roles.add(data.id);
|
||||
shopRoles.find().then((data) => console.log(data));
|
||||
member.roles.add(role.id);
|
||||
await shopRoles.find().then((role) => console.log(role));
|
||||
|
||||
const embed = {
|
||||
title: ':shopping_cart: Shop - Roles [Buy]',
|
||||
description: `You have bought ${role.name} for ${guildDB.shop.roles.pricePerHour} per hour.`,
|
||||
color: config.colors.success,
|
||||
fields: [
|
||||
{ name: 'Your balance', value: `${creditNoun(userDB.credits)}` },
|
||||
],
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
return await interaction.editReply({
|
||||
embeds: [embed],
|
||||
ephemeral: true,
|
||||
});
|
||||
})
|
||||
.catch(console.error);
|
||||
|
||||
await interaction.editReply({ content: 'Roles bought' });
|
||||
};
|
||||
|
|
|
@ -3,11 +3,62 @@ const axios = require('axios');
|
|||
const config = require('../../../../../config.json');
|
||||
const logger = require('../../../../handlers/logger');
|
||||
|
||||
const { credits, apis } = require('../../../../helpers/database/models');
|
||||
const {
|
||||
users,
|
||||
shopRoles,
|
||||
guilds,
|
||||
} = require('../../../../helpers/database/models');
|
||||
const creditNoun = require('../../../../helpers/creditNoun');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
const name = interaction.options.getString('name');
|
||||
const { member } = interaction;
|
||||
const { guild } = member;
|
||||
|
||||
interaction.editReply({ content: 'Roles canceled' });
|
||||
const role = await interaction.options.getRole('role');
|
||||
|
||||
const roleExist = await shopRoles.find({
|
||||
guildId: guild.id,
|
||||
userId: member.id,
|
||||
roleId: role.id,
|
||||
});
|
||||
|
||||
if (roleExist) {
|
||||
await member.roles.remove(role.id);
|
||||
|
||||
await interaction.guild.roles
|
||||
.delete(role.id, `${interaction.member.id} canceled from shop`)
|
||||
.then(async () => {
|
||||
// Get guild object
|
||||
const guildDB = await guilds.findOne({
|
||||
guildId: interaction.member.guild.id,
|
||||
});
|
||||
|
||||
const userDB = await users.findOne({
|
||||
userId: member.id,
|
||||
guildId: guild.id,
|
||||
});
|
||||
|
||||
await shopRoles.deleteOne({
|
||||
roleId: role.id,
|
||||
userId: member.id,
|
||||
guildId: guild.id,
|
||||
});
|
||||
|
||||
const embed = {
|
||||
title: ':shopping_cart: Shop - Roles [Buy]',
|
||||
description: `You have canceled ${role.name}.`,
|
||||
color: config.colors.success,
|
||||
fields: [
|
||||
{ name: 'Your balance', value: `${creditNoun(userDB.credits)}` },
|
||||
],
|
||||
timestamp: new Date(),
|
||||
footer: { iconURL: config.footer.icon, text: config.footer.text },
|
||||
};
|
||||
return await interaction.editReply({
|
||||
embeds: [embed],
|
||||
ephemeral: true,
|
||||
});
|
||||
})
|
||||
.catch(console.error);
|
||||
}
|
||||
};
|
||||
|
|
15
src/events/guildMemberAdd.js
Normal file
15
src/events/guildMemberAdd.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
const { users } = require('../helpers/database/models');
|
||||
const logger = require('../handlers/logger');
|
||||
|
||||
module.exports = {
|
||||
name: 'guildMemberAdd',
|
||||
async execute(member) {
|
||||
await users
|
||||
.create({ userId: member.id, guildId: member.guild.id })
|
||||
.then(
|
||||
logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} created successfully`
|
||||
)
|
||||
);
|
||||
},
|
||||
};
|
15
src/events/guildMemberRemove.js
Normal file
15
src/events/guildMemberRemove.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
const { users } = require('../helpers/database/models');
|
||||
const logger = require('../handlers/logger');
|
||||
|
||||
module.exports = {
|
||||
name: 'guildMemberRemove',
|
||||
async execute(member) {
|
||||
await users
|
||||
.deleteOne({ userId: member.id, guildId: member.guild.id })
|
||||
.then(
|
||||
logger.debug(
|
||||
`Guild: ${member.guild.id} User: ${member.id} deleted successfully`
|
||||
)
|
||||
);
|
||||
},
|
||||
};
|
|
@ -1,147 +0,0 @@
|
|||
const logger = require('../handlers/logger');
|
||||
|
||||
const {
|
||||
users,
|
||||
guilds,
|
||||
experiences,
|
||||
credits,
|
||||
counters,
|
||||
timeouts,
|
||||
} = require('../helpers/database/models');
|
||||
|
||||
module.exports = {
|
||||
name: 'messageCreate',
|
||||
async execute(message) {
|
||||
// Get guild object
|
||||
const guild = await guilds.findOne({ guildId: message.guild.id });
|
||||
|
||||
// If message author is bot
|
||||
if (message.author.bot) return;
|
||||
|
||||
// Get counter object
|
||||
const counter = await counters.findOne({
|
||||
guildId: message.guild.id,
|
||||
channelId: message.channel.id,
|
||||
});
|
||||
|
||||
// If counter for the message channel
|
||||
if (counter) {
|
||||
// If message content is not strictly the same as counter word
|
||||
if (message.content !== counter.word) {
|
||||
// Delete the message
|
||||
await message.delete();
|
||||
} else {
|
||||
// Add 1 to the counter object
|
||||
await counters.findOneAndUpdate(
|
||||
{
|
||||
guildId: message.guild.id,
|
||||
channelId: message.channel.id,
|
||||
},
|
||||
{ $inc: { counter: 1 } }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Create user if not already created
|
||||
await users.findOne(
|
||||
{ userId: message.author.id },
|
||||
{ new: true, upsert: true }
|
||||
);
|
||||
|
||||
if (guild.credits && guild.points) {
|
||||
// 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,
|
||||
timeoutId: 1,
|
||||
});
|
||||
|
||||
// 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 }
|
||||
)
|
||||
|
||||
// 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 }
|
||||
)
|
||||
|
||||
// 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,
|
||||
timeoutId: 1,
|
||||
});
|
||||
|
||||
setTimeout(async () => {
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${message.guild.id} User: ${
|
||||
message.author.id
|
||||
} has not talked within last ${
|
||||
guild.credits.timeout / 1000
|
||||
} seconds, credits can be given`
|
||||
);
|
||||
|
||||
// When timeout is out, remove it from the database
|
||||
await timeouts.deleteOne({
|
||||
guildId: message.guild.id,
|
||||
userId: message.author.id,
|
||||
timeoutId: 1,
|
||||
});
|
||||
}, guild.credits.timeout);
|
||||
}
|
||||
} else {
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${message.guild.id} User: ${
|
||||
message.author.id
|
||||
} has talked within last ${
|
||||
guild.credits.timeout / 1000
|
||||
} seconds, no credits given`
|
||||
);
|
||||
}
|
||||
},
|
||||
};
|
32
src/events/messageCreate/index.js
Normal file
32
src/events/messageCreate/index.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
const { guilds, users } = require('../../helpers/database/models');
|
||||
|
||||
const { points, credits, counter } = require('./modules');
|
||||
|
||||
module.exports = {
|
||||
name: 'messageCreate',
|
||||
async execute(message) {
|
||||
const { guild, author } = message;
|
||||
|
||||
// If message author is bot
|
||||
if (author.bot) return;
|
||||
|
||||
// Get guild object
|
||||
const guildDB = await guilds.findOne({ guildId: guild.id });
|
||||
|
||||
// Get guild object
|
||||
const userDB = await users.findOne({
|
||||
guildId: guild.id,
|
||||
userId: author.id,
|
||||
});
|
||||
|
||||
// Manage credits
|
||||
|
||||
await credits(guildDB, userDB, message);
|
||||
|
||||
// Manage points
|
||||
await points(guildDB, userDB, message);
|
||||
|
||||
// Manage counter
|
||||
await counter(guildDB, userDB, message);
|
||||
},
|
||||
};
|
37
src/events/messageCreate/modules/counter.js
Normal file
37
src/events/messageCreate/modules/counter.js
Normal file
|
@ -0,0 +1,37 @@
|
|||
const logger = require('../../../handlers/logger');
|
||||
|
||||
const {
|
||||
users,
|
||||
guilds,
|
||||
experiences,
|
||||
credits,
|
||||
counters,
|
||||
timeouts,
|
||||
} = require('../../../helpers/database/models');
|
||||
module.exports = async (guildDB, userDB, message) => {
|
||||
const { guild, channel, content } = message;
|
||||
|
||||
// Get counter object
|
||||
const counter = await counters.findOne({
|
||||
guildId: guild.id,
|
||||
channelId: channel.id,
|
||||
});
|
||||
|
||||
// If counter for the message channel
|
||||
if (counter) {
|
||||
// If message content is not strictly the same as counter word
|
||||
if (content !== counter.word) {
|
||||
// Delete the message
|
||||
await message.delete();
|
||||
} else {
|
||||
// Add 1 to the counter object
|
||||
await counters.findOneAndUpdate(
|
||||
{
|
||||
guildId: guild.id,
|
||||
channelId: channel.id,
|
||||
},
|
||||
{ $inc: { counter: 1 } }
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
78
src/events/messageCreate/modules/credits.js
Normal file
78
src/events/messageCreate/modules/credits.js
Normal file
|
@ -0,0 +1,78 @@
|
|||
const logger = require('../../../handlers/logger');
|
||||
|
||||
const {
|
||||
users,
|
||||
guilds,
|
||||
experiences,
|
||||
credits,
|
||||
counters,
|
||||
timeouts,
|
||||
} = require('../../../helpers/database/models');
|
||||
|
||||
module.exports = async (guildDB, userDB, message) => {
|
||||
const { guild, author, channel, content } = message;
|
||||
|
||||
// If message length is below guild minimum length
|
||||
if (content.length < guildDB.credits.minimumLength) return;
|
||||
|
||||
// Check if user has a timeout
|
||||
const isTimeout = await timeouts.findOne({
|
||||
guildId: guild.id,
|
||||
userId: author.id,
|
||||
timeoutId: '2022-03-15-17-42',
|
||||
});
|
||||
|
||||
// If user is not on timeout
|
||||
if (!isTimeout) {
|
||||
// Add credits to user
|
||||
|
||||
userDB.credits += guildDB.credits.rate;
|
||||
|
||||
await userDB
|
||||
.save()
|
||||
.then(async () => {
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${guild.id} User: ${author.id} Channel: ${channel.id} credits add ${guildDB.credits.rate} balance: ${userDB.credits}`
|
||||
);
|
||||
})
|
||||
.catch(async (e) => {
|
||||
// Send error message
|
||||
await logger.error(e);
|
||||
});
|
||||
|
||||
// Create a timeout for the user
|
||||
await timeouts.create({
|
||||
guildId: guild.id,
|
||||
userId: author.id,
|
||||
timeoutId: '2022-03-15-17-42',
|
||||
});
|
||||
|
||||
setTimeout(async () => {
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${guild.id} User: ${author.id} Channel: ${
|
||||
channel.id
|
||||
} has not talked within last ${
|
||||
guildDB.credits.timeout / 1000
|
||||
} seconds, credits can be given`
|
||||
);
|
||||
|
||||
// When timeout is out, remove it from the database
|
||||
await timeouts.deleteOne({
|
||||
guildId: guild.id,
|
||||
userId: author.id,
|
||||
timeoutId: '2022-03-15-17-42',
|
||||
});
|
||||
}, guildDB.credits.timeout);
|
||||
} else {
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${guild.id} User: ${author.id} Channel: ${
|
||||
channel.id
|
||||
} has talked within last ${
|
||||
guildDB.credits.timeout / 1000
|
||||
} seconds, no credits given`
|
||||
);
|
||||
}
|
||||
};
|
5
src/events/messageCreate/modules/index.js
Normal file
5
src/events/messageCreate/modules/index.js
Normal file
|
@ -0,0 +1,5 @@
|
|||
const points = require('./points');
|
||||
const credits = require('./credits');
|
||||
const counter = require('./counter');
|
||||
|
||||
module.exports = { points, credits, counter };
|
70
src/events/messageCreate/modules/points.js
Normal file
70
src/events/messageCreate/modules/points.js
Normal file
|
@ -0,0 +1,70 @@
|
|||
const logger = require('../../../handlers/logger');
|
||||
|
||||
const { timeouts } = require('../../../helpers/database/models');
|
||||
|
||||
module.exports = async (guildDB, userDB, message) => {
|
||||
const { author, guild, channel, content } = message;
|
||||
|
||||
// If message length is below guild minimum length
|
||||
if (content.length < guildDB.points.minimumLength) return;
|
||||
|
||||
// Check if user has a timeout
|
||||
const isTimeout = await timeouts.findOne({
|
||||
guildId: guild.id,
|
||||
userId: author.id,
|
||||
timeoutId: '2022-03-15-17-41',
|
||||
});
|
||||
|
||||
// If user is not on timeout
|
||||
if (!isTimeout) {
|
||||
// Add points to user
|
||||
userDB.points += guildDB.points.rate;
|
||||
|
||||
await userDB
|
||||
.save()
|
||||
.then(async () => {
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${guild.id} User: ${author.id} Channel: ${channel.id} points add: ${guildDB.points.rate} balance: ${userDB.points}`
|
||||
);
|
||||
})
|
||||
.catch(async (e) => {
|
||||
// Send error message
|
||||
await logger.error(e);
|
||||
});
|
||||
|
||||
// Create a timeout for the user
|
||||
await timeouts.create({
|
||||
guildId: guild.id,
|
||||
userId: author.id,
|
||||
timeoutId: '2022-03-15-17-41',
|
||||
});
|
||||
|
||||
setTimeout(async () => {
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${guild.id} User: ${author.id} Channel: ${
|
||||
channel.id
|
||||
} has not talked within last ${
|
||||
guildDB.points.timeout / 1000
|
||||
} seconds, points can be given`
|
||||
);
|
||||
|
||||
// When timeout is out, remove it from the database
|
||||
await timeouts.deleteOne({
|
||||
guildId: guild.id,
|
||||
userId: author.id,
|
||||
timeoutId: '2022-03-15-17-41',
|
||||
});
|
||||
}, guildDB.points.timeout);
|
||||
} else {
|
||||
// Send debug message
|
||||
await logger.debug(
|
||||
`Guild: ${guild.id} User: ${author.id} Channel: ${
|
||||
channel.id
|
||||
} has talked within last ${
|
||||
guildDB.points.timeout / 1000
|
||||
} seconds, no points given`
|
||||
);
|
||||
}
|
||||
};
|
|
@ -1,6 +1,6 @@
|
|||
const logger = require('../handlers/logger');
|
||||
|
||||
const { deployCommands } = require('../helpers');
|
||||
const { deployCommands, dbGuildFix, dbMemberFix } = require('../helpers');
|
||||
|
||||
module.exports = {
|
||||
name: 'ready',
|
||||
|
@ -17,6 +17,17 @@ module.exports = {
|
|||
status: 'online',
|
||||
});
|
||||
|
||||
// const guilds = client.guilds.cache;
|
||||
// await guilds.map(async (guild) => {
|
||||
// await guild.members.fetch().then(async (members) => {
|
||||
// await members.forEach(async (member) => {
|
||||
// const { user } = member;
|
||||
// dbMemberFix(user, guild);
|
||||
// });
|
||||
// });
|
||||
// await dbGuildFix(guild);
|
||||
// });
|
||||
|
||||
await deployCommands();
|
||||
},
|
||||
};
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
const fs = require('fs'); // fs
|
||||
|
||||
module.exports = async (client) => {
|
||||
const eventFiles = fs
|
||||
.readdirSync('./src/events')
|
||||
.filter((file) => file.endsWith('.js'));
|
||||
const eventFiles = fs.readdirSync('./src/events');
|
||||
|
||||
for (const file of eventFiles) {
|
||||
const event = require(`../events/${file}`);
|
||||
|
|
|
@ -13,14 +13,14 @@ const apiSchema = new mongoose.Schema(
|
|||
required: true,
|
||||
unique: false,
|
||||
index: true,
|
||||
default: 'https://bg.zyner.org/api/',
|
||||
default: 'https://localhost/api/',
|
||||
},
|
||||
token: {
|
||||
type: mongoose.SchemaTypes.String,
|
||||
required: true,
|
||||
unique: false,
|
||||
index: true,
|
||||
default: 'your_token',
|
||||
default: 'token',
|
||||
},
|
||||
},
|
||||
{ timestamps: true }
|
||||
|
|
|
@ -11,13 +11,7 @@ const guildSchema = new mongoose.Schema(
|
|||
credits: {
|
||||
status: {
|
||||
type: mongoose.SchemaTypes.Boolean,
|
||||
default: false,
|
||||
},
|
||||
url: {
|
||||
type: mongoose.SchemaTypes.String,
|
||||
},
|
||||
token: {
|
||||
type: mongoose.SchemaTypes.String,
|
||||
default: true,
|
||||
},
|
||||
rate: {
|
||||
type: mongoose.SchemaTypes.Number,
|
||||
|
@ -42,6 +36,10 @@ const guildSchema = new mongoose.Schema(
|
|||
},
|
||||
shop: {
|
||||
roles: {
|
||||
status: {
|
||||
type: mongoose.SchemaTypes.Boolean,
|
||||
default: true,
|
||||
},
|
||||
pricePerHour: {
|
||||
type: mongoose.SchemaTypes.Number,
|
||||
default: 5,
|
||||
|
@ -53,12 +51,6 @@ const guildSchema = new mongoose.Schema(
|
|||
type: mongoose.SchemaTypes.Boolean,
|
||||
default: false,
|
||||
},
|
||||
url: {
|
||||
type: mongoose.SchemaTypes.String,
|
||||
},
|
||||
token: {
|
||||
type: mongoose.SchemaTypes.String,
|
||||
},
|
||||
rate: {
|
||||
type: mongoose.SchemaTypes.Number,
|
||||
default: 1,
|
||||
|
|
|
@ -14,7 +14,7 @@ const timeoutSchema = new mongoose.Schema(
|
|||
unique: false,
|
||||
index: true,
|
||||
},
|
||||
timeoutId: { type: mongoose.SchemaTypes.Number },
|
||||
timeoutId: { type: mongoose.SchemaTypes.String },
|
||||
},
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
|
|
@ -2,10 +2,16 @@ const mongoose = require('mongoose');
|
|||
|
||||
const userSchema = new mongoose.Schema(
|
||||
{
|
||||
guildId: {
|
||||
type: mongoose.SchemaTypes.Decimal128,
|
||||
required: true,
|
||||
unique: false,
|
||||
index: true,
|
||||
},
|
||||
userId: {
|
||||
type: mongoose.SchemaTypes.Decimal128,
|
||||
required: true,
|
||||
unique: true,
|
||||
unique: false,
|
||||
index: true,
|
||||
},
|
||||
language: {
|
||||
|
@ -13,6 +19,9 @@ const userSchema = new mongoose.Schema(
|
|||
default: 'en',
|
||||
},
|
||||
reputation: { type: mongoose.SchemaTypes.Number, default: 0 },
|
||||
credits: { type: mongoose.SchemaTypes.Number, default: 0 },
|
||||
levels: { type: mongoose.SchemaTypes.Number, default: 0 },
|
||||
points: { type: mongoose.SchemaTypes.Number, default: 0 },
|
||||
},
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
|
|
@ -5,7 +5,7 @@ const logger = require('../handlers/logger');
|
|||
|
||||
module.exports = async (guild) => {
|
||||
const api = await apis.findOne({ guildId: guild.id });
|
||||
const guildData = await guilds.find({ guildId: guild.id });
|
||||
const guildData = await guilds.findOne({ guildId: guild.id });
|
||||
if (!api) {
|
||||
apis.create({ guildId: guild.id });
|
||||
logger.debug(`Guild: ${guild.id} added api collection`);
|
||||
|
|
|
@ -4,9 +4,9 @@ const { users, experiences, credits } = require('./database/models');
|
|||
const logger = require('../handlers/logger');
|
||||
|
||||
module.exports = async (user, guild) => {
|
||||
const userData = await users.findOne({ userId: user.id });
|
||||
const userData = await users.findOne({ userId: user.id, guildId: guild.id });
|
||||
if (!userData) {
|
||||
users.create({ userId: user.id });
|
||||
users.create({ userId: user.id, guildId: guild.id });
|
||||
logger.debug(`User: ${user.id} added user collection`);
|
||||
} else {
|
||||
logger.debug(`User: ${user.id} already in user collection`);
|
||||
|
|
Loading…
Add table
Reference in a new issue