Restyled by prettier

This commit is contained in:
Restyled.io 2022-03-06 18:41:29 +00:00 committed by Axel Olausson Holtenäs
parent 820ee57844
commit 18b559a867
No known key found for this signature in database
GPG key ID: E3AE7E194AE017ED
10 changed files with 476 additions and 524 deletions

View file

@ -9,38 +9,35 @@ module.exports = async (interaction) => {
const user = await interaction.options.getUser('user');
await credits
// eslint-disable-next-line max-len
.findOne({
userId : user ? user.id : interaction.user.id,
guildId : interaction.member.guild.id
})
.then(async (data) => {
if (!data) {
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},
};
return interaction.editReply(
{embeds : [ embed ], ephemeral : true});
}
const {balance} = data;
// eslint-disable-next-line max-len
.findOne({
userId: user ? user.id : interaction.user.id,
guildId: interaction.member.guild.id,
})
.then(async (data) => {
if (!data) {
const embed = {
title : 'Balance',
description :
`${user ? `${user} has` : 'You have'} ${creditNoun(balance)}.`,
color : config.colors.success,
timestamp : new Date(),
footer : {iconURL : config.footer.icon, text : config.footer.text},
title: 'Balance',
description: `${user} has no credits.`,
color: config.colors.success,
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
return interaction.editReply({embeds : [ embed ], ephemeral : true});
})
.catch(async (err) => logger.error(err));
return interaction.editReply({ embeds: [embed], ephemeral: true });
}
const { balance } = data;
const embed = {
title: 'Balance',
description: `${user ? `${user} has` : 'You have'} ${creditNoun(balance)}.`,
color: config.colors.success,
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
return interaction.editReply({ embeds: [embed], ephemeral: true });
})
.catch(async (err) => logger.error(err));
} catch {
await logger.error();
}

View file

@ -11,59 +11,57 @@ module.exports = async (interaction) => {
const amount = await interaction.options.getInteger('amount');
const reason = await interaction.options.getString('reason');
// eslint-disable-next-line max-len
const data = await credits.findOne(
{userId : interaction.user.id, guildId : interaction.member.guild.id});
const data = await credits.findOne({
userId: interaction.user.id,
guildId: interaction.member.guild.id,
});
if (user.id === interaction.user.id) {
const embed = {
title : 'Gift failed',
description : "You can't pay yourself.",
color : 0xbb2124,
timestamp : new Date(),
footer : {iconURL : config.footer.icon, text : config.footer.text},
title: 'Gift failed',
description: "You can't pay yourself.",
color: 0xbb2124,
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
return await interaction.editReply(
{embeds : [ embed ], ephemeral : true});
return await interaction.editReply({ embeds: [embed], ephemeral: true });
}
if (amount <= 0) {
const embed = {
title : 'Gift failed',
description : "You can't pay zero or below.",
color : 0xbb2124,
timestamp : new Date(),
footer : {iconURL : config.footer.icon, text : config.footer.text},
title: 'Gift failed',
description: "You can't pay zero or below.",
color: 0xbb2124,
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
return await interaction.editReply(
{embeds : [ embed ], ephemeral : true});
return await interaction.editReply({ embeds: [embed], ephemeral: true });
}
if (data.balance < amount) {
const embed = {
title : 'Gift',
description :
`You have insufficient credits. Your balance is ${data.balance}`,
color : 0xbb2124,
timestamp : new Date(),
footer : {iconURL : config.footer.icon, text : config.footer.text},
title: 'Gift',
description: `You have insufficient credits. Your balance is ${data.balance}`,
color: 0xbb2124,
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
return await interaction.editReply(
{embeds : [ embed ], ephemeral : true});
return await interaction.editReply({ embeds: [embed], ephemeral: true });
}
// eslint-disable-next-line max-len
const fromUser = await credits.findOne(
{userId : interaction.user.id, guildId : interaction.member.guild.id});
const toUser = await credits.findOne(
{userId : user.id, guildId : interaction.member.guild.id});
const fromUser = await credits.findOne({
userId: interaction.user.id,
guildId: interaction.member.guild.id,
});
const toUser = await credits.findOne({ userId: user.id, guildId: interaction.member.guild.id });
if (!toUser) {
const embed = {
title : 'Gift',
description :
'That user has no credits, I can not gift credits to the user',
color : config.colors.error,
timestamp : new Date(),
footer : {iconURL : config.footer.icon, text : config.footer.text},
title: 'Gift',
description: 'That user has no credits, I can not gift credits to the user',
color: config.colors.error,
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
return interaction.editReply({embeds : [ embed ], ephemeral : true});
return interaction.editReply({ embeds: [embed], ephemeral: true });
}
fromUser.balance -= amount;
toUser.balance += amount;
@ -71,34 +69,27 @@ module.exports = async (interaction) => {
await saveUser(fromUser, toUser);
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},
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},
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});
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 });
} catch (e) {
await logger.error(e);
}

View file

@ -1,4 +1,4 @@
const {Permissions} = require('discord.js');
const { Permissions } = require('discord.js');
const config = require('../../../../config.json');
const logger = require('../../../handlers/logger');
@ -10,56 +10,51 @@ module.exports = async (interaction) => {
try {
if (!interaction.member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
const embed = {
title : 'Give failed',
description :
'You need to have permission to manage this guild (MANAGE_GUILD)',
title: 'Give failed',
description: 'You need to have permission to manage this guild (MANAGE_GUILD)',
};
return await interaction.editReply(
{embeds : [ embed ], ephemeral : true});
return await interaction.editReply({ embeds: [embed], ephemeral: true });
}
const user = await interaction.options.getUser('user');
const amount = await interaction.options.getInteger('amount');
if (amount <= 0) {
const embed = {
title : 'Give',
description : "You can't give zero or below.",
color : 0xbb2124,
timestamp : new Date(),
footer : {iconURL : config.footer.icon, text : config.footer.text},
title: 'Give',
description: "You can't give zero or below.",
color: 0xbb2124,
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
return await interaction.editReply(
{embeds : [ embed ], ephemeral : true});
return await interaction.editReply({ embeds: [embed], ephemeral: true });
}
const toUser = await credits.findOne(
{userId : user.id, guildId : interaction.member.guild.id});
const toUser = await credits.findOne({ userId: user.id, guildId: interaction.member.guild.id });
if (!toUser) {
const embed = {
title : 'Give',
description :
'That user has no credits, I can not give credits to the user',
color : config.colors.error,
timestamp : new Date(),
footer : {iconURL : config.footer.icon, text : config.footer.text},
title: 'Give',
description: 'That user has no credits, I can not give credits to the user',
color: config.colors.error,
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
return interaction.editReply({embeds : [ embed ], ephemeral : true});
return interaction.editReply({ embeds: [embed], ephemeral: true });
}
toUser.balance += amount;
await toUser.save();
const embed = {
title : 'Give',
description : `Gave ${creditNoun(amount)} to ${user}.`,
color : 0x22bb33,
timestamp : new Date(),
footer : {iconURL : config.footer.icon, text : config.footer.text},
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}`,
`Administrator: ${interaction.user.username} gave ${
amount <= 1 ? `${amount} credit` : `${amount} credits`
} to ${user.username}`
);
return await interaction.editReply({embeds : [ embed ], ephemeral : true});
return await interaction.editReply({ embeds: [embed], ephemeral: true });
} catch (e) {
await logger.error(e);
}

View file

@ -1,4 +1,4 @@
const {v4 : uuidv4} = require('uuid');
const { v4: uuidv4 } = require('uuid');
const axios = require('axios');
const config = require('../../../../config.json');
const logger = require('../../../handlers/logger');
@ -13,120 +13,111 @@ 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},
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});
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);
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},
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});
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},
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});
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},
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});
return await interaction.editReply({ embeds: [embed], ephemeral: true });
}
const code = uuidv4();
const guild = await guilds.findOne({guildId : interaction.member.guild.id});
const guild = await guilds.findOne({ guildId: interaction.member.guild.id });
const api = axios.create({
baseURL : guild.credits.url,
headers : {Authorization : `Bearer ${guild.credits.token}`},
baseURL: guild.credits.url,
headers: { Authorization: `Bearer ${guild.credits.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;
.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 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});
});
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);
}

View file

@ -15,51 +15,51 @@ module.exports = async (interaction) => {
const workRate = await interaction.options.getNumber('work-rate');
const workTimeout = await interaction.options.getNumber('work-timeout');
const guild = await guilds.findOne({guildId : interaction.member.guild.id});
const guild = await guilds.findOne({ guildId: interaction.member.guild.id });
guild.credits.status = status !== null ? status : guild.credits.status;
guild.credits.url = url !== null ? url : guild.credits.url;
guild.credits.token = token !== null ? token : guild.credits.token;
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.workRate = workRate !== null ? workRate : guild.credits.workRate;
// eslint-disable-next-line max-len
guild.credits.workTimeout =
workTimeout !== null ? workTimeout : guild.credits.workTimeout;
guild.credits.workTimeout = workTimeout !== null ? workTimeout : guild.credits.workTimeout;
// eslint-disable-next-line max-len
guild.credits.minimumLength =
minimumLength !== null ? minimumLength : guild.credits.minimumLength;
minimumLength !== null ? minimumLength : guild.credits.minimumLength;
await guild.save();
const embed = {
title : 'Credits',
description : 'Following settings is set',
color : config.colors.success,
fields : [
{name : 'Status', value : `${guild.credits.status}`, inline : true},
{name : 'URL', value : `${guild.credits.url}`, inline : true},
{name : 'Token', value : `${guild.credits.token}`},
{name : 'Rate', value : `${guild.credits.rate}`, inline : true}, {
name : 'Minimum Length',
value : `${guild.credits.minimumLength}`,
inline : true
title: 'Credits',
description: 'Following settings is set',
color: config.colors.success,
fields: [
{ name: 'Status', value: `${guild.credits.status}`, inline: true },
{ name: 'URL', value: `${guild.credits.url}`, inline: true },
{ name: 'Token', value: `${guild.credits.token}` },
{ name: 'Rate', value: `${guild.credits.rate}`, inline: true },
{
name: 'Minimum Length',
value: `${guild.credits.minimumLength}`,
inline: true,
},
{name : 'Timeout', value : `${guild.credits.timeout}`, inline : true}, {
name : 'Work Rate',
value : `${guild.credits.workRate}`,
inline : true
{ name: 'Timeout', value: `${guild.credits.timeout}`, inline: true },
{
name: 'Work Rate',
value: `${guild.credits.workRate}`,
inline: true,
},
{
name : 'Work Timeout',
value : `${guild.credits.workTimeout}`,
inline : true
}
name: 'Work Timeout',
value: `${guild.credits.workTimeout}`,
inline: true,
},
],
timestamp : new Date(),
footer : {iconURL : config.footer.icon, text : config.footer.text},
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
return interaction.editReply({embeds : [ embed ], ephemeral : true});
return interaction.editReply({ embeds: [embed], ephemeral: true });
} catch (e) {
logger.error(e);
}

View file

@ -1,4 +1,4 @@
const {Permissions} = require('discord.js');
const { Permissions } = require('discord.js');
const config = require('../../../../config.json');
const logger = require('../../../handlers/logger');
@ -11,69 +11,63 @@ module.exports = async (interaction) => {
try {
if (!interaction.member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
const embed = {
title : 'Transfer failed',
description :
'You need to have permission to manage this guild (MANAGE_GUILD)',
title: 'Transfer failed',
description: 'You need to have permission to manage this guild (MANAGE_GUILD)',
};
return await interaction.editReply(
{embeds : [ embed ], ephemeral : true});
return await interaction.editReply({ embeds: [embed], ephemeral: true });
}
const from = await interaction.options.getUser('from');
const to = await interaction.options.getUser('to');
const amount = await interaction.options.getInteger('amount');
// eslint-disable-next-line max-len
const fromUser = await credits.findOne(
{userId : from.id, guildId : interaction.member.guild.id});
const toUser = await credits.findOne(
{userId : to.id, guildId : interaction.member.guild.id});
const fromUser = await credits.findOne({
userId: from.id,
guildId: interaction.member.guild.id,
});
const toUser = await credits.findOne({ userId: to.id, guildId: interaction.member.guild.id });
if (!fromUser) {
const embed = {
title : 'Transfer',
description :
'That user has no credits, I can not transfer credits from the user',
color : config.colors.error,
timestamp : new Date(),
footer : {iconURL : config.footer.icon, text : config.footer.text},
title: 'Transfer',
description: 'That user has no credits, I can not transfer credits from the user',
color: config.colors.error,
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
return interaction.editReply({embeds : [ embed ], ephemeral : true});
return interaction.editReply({ embeds: [embed], ephemeral: true });
}
if (!toUser) {
const embed = {
title : 'Transfer',
description :
'That user has no credits, I can not transfer credits to the user',
color : config.colors.error,
timestamp : new Date(),
footer : {iconURL : config.footer.icon, text : config.footer.text},
title: 'Transfer',
description: 'That user has no credits, I can not transfer credits to the user',
color: config.colors.error,
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
return interaction.editReply({embeds : [ embed ], ephemeral : true});
return interaction.editReply({ embeds: [embed], ephemeral: true });
}
if (amount <= 0) {
const embed = {
title : 'Transfer failed',
description : "You can't transfer zero or below.",
color : 0xbb2124,
timestamp : new Date(),
footer : {iconURL : config.footer.icon, text : config.footer.text},
title: 'Transfer failed',
description: "You can't transfer zero or below.",
color: 0xbb2124,
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
return await interaction.editReply(
{embeds : [ embed ], ephemeral : true});
return await interaction.editReply({ embeds: [embed], ephemeral: true });
}
if (fromUser.balance < amount) {
const embed = {
title : 'Transfer',
description : `${from.username} has insufficient credits. ${
from.username} balance is ${fromUser.balance}`,
color : 0xbb2124,
timestamp : new Date(),
footer : {iconURL : config.footer.icon, text : config.footer.text},
title: 'Transfer',
description: `${from.username} has insufficient credits. ${from.username} balance is ${fromUser.balance}`,
color: 0xbb2124,
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
return await interaction.editReply(
{embeds : [ embed ], ephemeral : true});
return await interaction.editReply({ embeds: [embed], ephemeral: true });
}
fromUser.balance -= amount;
@ -82,28 +76,27 @@ module.exports = async (interaction) => {
await saveUser(fromUser, toUser);
const embed = {
title : 'Transfer',
description : `You sent ${creditNoun(amount)} from ${from} to ${to}.`,
color : 0x22bb33,
fields : [
title: 'Transfer',
description: `You sent ${creditNoun(amount)} from ${from} to ${to}.`,
color: 0x22bb33,
fields: [
{
name : `${from.username} Balance`,
value : `${fromUser.balance}`,
inline : true
name: `${from.username} Balance`,
value: `${fromUser.balance}`,
inline: true,
},
{
name : `${to.username} Balance`,
value : `${toUser.balance}`,
inline : true
name: `${to.username} Balance`,
value: `${toUser.balance}`,
inline: true,
},
],
timestamp : new Date(),
footer : {iconURL : config.footer.icon, text : config.footer.text},
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
await logger.debug(
`Gift sent from: ${interaction.user.username} to: ${to.username}`);
return await interaction.editReply({embeds : [ embed ], ephemeral : true});
await logger.debug(`Gift sent from: ${interaction.user.username} to: ${to.username}`);
return await interaction.editReply({ embeds: [embed], ephemeral: true });
} catch (e) {
logger.error(e);
}

View file

@ -9,57 +9,60 @@ const workedRecently = new Set();
// eslint-disable-next-line consistent-return
module.exports = async (interaction) => {
try {
const guild = await guilds.findOne({guildId : interaction.member.guild.id});
const guild = await guilds.findOne({ guildId: interaction.member.guild.id });
if (!workedRecently.has(interaction.member.id)) {
const creditsEarned = Math.floor(Math.random() * guild.credits.workRate);
await credits
.findOneAndUpdate(
{
userId : interaction.member.id,
guildId : interaction.member.guild.id
},
{$inc : {balance : creditsEarned}},
{new : true, upsert : true},
)
.then(async () => {
logger.debug(`Credits added to user: ${interaction.member.id}`);
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},
};
.findOneAndUpdate(
{
userId: interaction.member.id,
guildId: interaction.member.guild.id,
},
{ $inc: { balance: creditsEarned } },
{ new: true, upsert: true }
)
.then(async () => {
logger.debug(`Credits added to user: ${interaction.member.id}`);
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 },
};
return interaction.editReply(
{embeds : [ embed ], ephemeral : true});
})
.catch(async (err) => { await logger.error(err); });
return interaction.editReply({ embeds: [embed], ephemeral: true });
})
.catch(async (err) => {
await logger.error(err);
});
workedRecently.add(interaction.member.id);
setTimeout(() => {
logger.debug(
`User: ${interaction.member.id} has not worked within last ${
guild.credits.workTimeout / 1000} seconds, work can be runned`,
`User: ${interaction.member.id} has not worked within last ${
guild.credits.workTimeout / 1000
} seconds, work can be runned`
);
workedRecently.delete(interaction.member.id);
}, guild.credits.timeout);
} else {
logger.debug(
`User: ${interaction.member.id} has already worked within last ${
guild.credits.workTimeout / 1000} seconds, no work is runned`,
`User: ${interaction.member.id} has already worked within last ${
guild.credits.workTimeout / 1000
} seconds, no work is runned`
);
const embed = {
title : 'Work',
description : `You can not work now, wait ${
guild.credits.workTimeout / 1000} seconds until timeout is out.`,
color : config.colors.error,
timestamp : new Date(),
footer : {iconURL : config.footer.icon, text : config.footer.text},
title: 'Work',
description: `You can not work now, wait ${
guild.credits.workTimeout / 1000
} seconds until timeout is out.`,
color: config.colors.error,
timestamp: new Date(),
footer: { iconURL: config.footer.icon, text: config.footer.text },
};
return interaction.editReply({embeds : [ embed ], ephemeral : true});
return interaction.editReply({ embeds: [embed], ephemeral: true });
}
} catch (e) {
await logger.error(e);

View file

@ -1,5 +1,5 @@
const {SlashCommandBuilder} = require('@discordjs/builders');
const {Permissions} = require('discord.js');
const { SlashCommandBuilder } = require('@discordjs/builders');
const { Permissions } = require('discord.js');
const config = require('../../../config.json');
const guilds = require('../../helpers/database/models/guildSchema');
@ -16,170 +16,150 @@ const settings = require('./addons/settings');
const work = require('./addons/work');
module.exports = {
permissions : new Permissions([
permissions: new Permissions([
Permissions.FLAGS.MANAGE_MESSAGES,
Permissions.FLAGS.ADMINISTRATOR,
]),
guildOnly : true,
botAdminOnly : false,
data :
new SlashCommandBuilder()
.setName('credits')
.setDescription('Manage your credits.')
.addSubcommand(
(subcommand) =>
subcommand.setName('give')
.setDescription('Give credits to a user. (ADMIN)')
.addUserOption(
(option) =>
option.setName('user')
.setDescription('The user you want to pay.')
.setRequired(true))
.addIntegerOption(
(option) =>
option.setName('amount')
.setDescription('The amount you will pay.')
.setRequired(true)))
.addSubcommand(
(subcommand) =>
subcommand.setName('take')
.setDescription('Take credits from a user. (ADMIN)')
.addUserOption(
(option) =>
option.setName('user')
.setDescription(
'The user you want to take credits from.')
.setRequired(true))
.addIntegerOption(
(option) =>
option.setName('amount')
.setDescription('The amount you will take.')
.setRequired(true)))
.addSubcommand(
(subcommand) =>
subcommand.setName('balance')
.setDescription("Check a user's balance.")
.addUserOption(
(option) =>
option.setName('user')
.setDescription(
'The user whose balance you want to check.')
.setRequired(false)))
.addSubcommand(
(subcommand) =>
subcommand.setName('redeem')
.setDescription('Redeem your credits.')
.addIntegerOption(
(option) => option.setName('amount').setDescription(
'How much credit you want to withdraw.')))
.addSubcommand(
(subcommand) =>
subcommand.setName('gift')
.setDescription('Gift someone credits from your credits.')
.addUserOption(
(option) =>
option.setName('user')
.setDescription('The user you want to pay.')
.setRequired(true))
.addIntegerOption(
(option) =>
option.setName('amount')
.setDescription('The amount you will pay.')
.setRequired(true))
.addStringOption(
(option) => option.setName('reason').setDescription(
'Your reason.')))
.addSubcommand((subcommand) =>
subcommand.setName('top').setDescription(
'Check the top balance.'))
.addSubcommand(
(subcommand) =>
subcommand.setName('transfer')
.setDescription(
'Transfer credits from a user to another user. (ADMIN)')
.addUserOption(
(option) =>
option.setName('from')
.setDescription(
'The user you want to take credits from.')
.setRequired(true))
.addUserOption(
(option) =>
option.setName('to')
.setDescription(
'The user you want to give credits to.')
.setRequired(true))
.addIntegerOption(
(option) => option.setName('amount')
.setDescription(
'The amount you will transfer.')
.setRequired(true)))
.addSubcommand(
(subcommand) =>
subcommand.setName('set')
.setDescription('Set credits on a user. (ADMIN)')
.addUserOption(
(option) =>
option.setName('user')
.setDescription(
'The user you want to set credits on.')
.setRequired(true))
.addIntegerOption(
(option) =>
option.setName('amount')
.setDescription('The amount you will set.')
.setRequired(true)))
.addSubcommand(
(subcommand) =>
subcommand.setName('settings')
.setDescription('Manage credit settings. (ADMIN)')
.addBooleanOption(
(option) => option.setName('status').setDescription(
'Toggle credits.'))
.addStringOption((option) =>
option.setName('url').setDescription(
'Controlpanel.gg URL.'))
.addStringOption(
(option) => option.setName('token').setDescription(
'Controlpanel.gg token.'))
.addNumberOption(
(option) => option.setName('rate').setDescription(
'Credits rate.'))
.addNumberOption(
(option) => option.setName('minimum-length')
.setDescription(
'Minimum length for credits.'))
.addNumberOption(
(option) => option.setName('work-rate')
.setDescription('Work rate (rate).'))
.addNumberOption(
(option) =>
option.setName('work-timeout')
.setDescription(
'Timeout between working for credits (milliseconds).'))
.addNumberOption(
(option) => option.setName('timeout').setDescription(
'Timeout between credits (milliseconds).')))
.addSubcommand((subcommand) =>
subcommand.setName('work').setDescription(
'Work for credits.')),
guildOnly: true,
botAdminOnly: false,
data: new SlashCommandBuilder()
.setName('credits')
.setDescription('Manage your credits.')
.addSubcommand((subcommand) =>
subcommand
.setName('give')
.setDescription('Give credits to a user. (ADMIN)')
.addUserOption((option) =>
option.setName('user').setDescription('The user you want to pay.').setRequired(true)
)
.addIntegerOption((option) =>
option.setName('amount').setDescription('The amount you will pay.').setRequired(true)
)
)
.addSubcommand((subcommand) =>
subcommand
.setName('take')
.setDescription('Take credits from a user. (ADMIN)')
.addUserOption((option) =>
option
.setName('user')
.setDescription('The user you want to take credits from.')
.setRequired(true)
)
.addIntegerOption((option) =>
option.setName('amount').setDescription('The amount you will take.').setRequired(true)
)
)
.addSubcommand((subcommand) =>
subcommand
.setName('balance')
.setDescription("Check a user's balance.")
.addUserOption((option) =>
option
.setName('user')
.setDescription('The user whose balance you want to check.')
.setRequired(false)
)
)
.addSubcommand((subcommand) =>
subcommand
.setName('redeem')
.setDescription('Redeem your credits.')
.addIntegerOption((option) =>
option.setName('amount').setDescription('How much credit you want to withdraw.')
)
)
.addSubcommand((subcommand) =>
subcommand
.setName('gift')
.setDescription('Gift someone credits from your credits.')
.addUserOption((option) =>
option.setName('user').setDescription('The user you want to pay.').setRequired(true)
)
.addIntegerOption((option) =>
option.setName('amount').setDescription('The amount you will pay.').setRequired(true)
)
.addStringOption((option) => option.setName('reason').setDescription('Your reason.'))
)
.addSubcommand((subcommand) =>
subcommand.setName('top').setDescription('Check the top balance.')
)
.addSubcommand((subcommand) =>
subcommand
.setName('transfer')
.setDescription('Transfer credits from a user to another user. (ADMIN)')
.addUserOption((option) =>
option
.setName('from')
.setDescription('The user you want to take credits from.')
.setRequired(true)
)
.addUserOption((option) =>
option
.setName('to')
.setDescription('The user you want to give credits to.')
.setRequired(true)
)
.addIntegerOption((option) =>
option.setName('amount').setDescription('The amount you will transfer.').setRequired(true)
)
)
.addSubcommand((subcommand) =>
subcommand
.setName('set')
.setDescription('Set credits on a user. (ADMIN)')
.addUserOption((option) =>
option
.setName('user')
.setDescription('The user you want to set credits on.')
.setRequired(true)
)
.addIntegerOption((option) =>
option.setName('amount').setDescription('The amount you will set.').setRequired(true)
)
)
.addSubcommand((subcommand) =>
subcommand
.setName('settings')
.setDescription('Manage credit settings. (ADMIN)')
.addBooleanOption((option) => option.setName('status').setDescription('Toggle credits.'))
.addStringOption((option) => option.setName('url').setDescription('Controlpanel.gg URL.'))
.addStringOption((option) =>
option.setName('token').setDescription('Controlpanel.gg token.')
)
.addNumberOption((option) => option.setName('rate').setDescription('Credits rate.'))
.addNumberOption((option) =>
option.setName('minimum-length').setDescription('Minimum length for credits.')
)
.addNumberOption((option) =>
option.setName('work-rate').setDescription('Work rate (rate).')
)
.addNumberOption((option) =>
option
.setName('work-timeout')
.setDescription('Timeout between working for credits (milliseconds).')
)
.addNumberOption((option) =>
option.setName('timeout').setDescription('Timeout between credits (milliseconds).')
)
)
.addSubcommand((subcommand) => subcommand.setName('work').setDescription('Work for credits.')),
async execute(interaction) {
const guild = await guilds.findOne({guildId : interaction.member.guild.id});
const guild = await guilds.findOne({ guildId: interaction.member.guild.id });
if (interaction.options.getSubcommand() === 'settings') {
await settings(interaction);
}
if (guild.credits.status === false &&
interaction.options.getSubcommand() !== 'settings') {
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},
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});
return interaction.editReply({ embeds: [embed], ephemeral: true });
}
if (interaction.options.getSubcommand() === 'balance') {

View file

@ -3,16 +3,18 @@ const logger = require('../handlers/logger');
const guilds = require('../helpers/database/models/guildSchema');
module.exports = {
name : 'interactionCreate',
name: 'interactionCreate',
async execute(guild) {
const guildExist = await guilds.findOne({guildId : guild.id})
.then(logger.debug(`Found guild: ${guild.id}`))
.catch(logger.error);
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));
await guilds
.create({ guildId: guild.id })
.then(() => logger.debug(`Create guild: ${guild.id} was success`))
.catch((e) => logger.error(e));
}
},
};

View file

@ -1,47 +1,47 @@
const mongoose = require('mongoose');
const guildSchema = new mongoose.Schema(
{
guildId : {
type : mongoose.SchemaTypes.Decimal128,
required : true,
unique : true,
index : true,
{
guildId: {
type: mongoose.SchemaTypes.Decimal128,
required: true,
unique: true,
index: true,
},
credits: {
status: {
type: mongoose.SchemaTypes.Boolean,
default: false,
},
credits : {
status : {
type : mongoose.SchemaTypes.Boolean,
default : false,
},
url : {
type : mongoose.SchemaTypes.String,
},
token : {
type : mongoose.SchemaTypes.String,
},
rate : {
type : mongoose.SchemaTypes.Number,
default : 1,
},
minimumLength : {
type : mongoose.SchemaTypes.Number,
default : 5,
},
timeout : {
type : mongoose.SchemaTypes.Number,
default : 5000,
},
workRate : {
type : mongoose.SchemaTypes.Number,
default : 15,
},
workTimeout : {
type : mongoose.SchemaTypes.Number,
default : 900000,
},
url: {
type: mongoose.SchemaTypes.String,
},
token: {
type: mongoose.SchemaTypes.String,
},
rate: {
type: mongoose.SchemaTypes.Number,
default: 1,
},
minimumLength: {
type: mongoose.SchemaTypes.Number,
default: 5,
},
timeout: {
type: mongoose.SchemaTypes.Number,
default: 5000,
},
workRate: {
type: mongoose.SchemaTypes.Number,
default: 15,
},
workTimeout: {
type: mongoose.SchemaTypes.Number,
default: 900000,
},
},
{timestamps : true},
},
{ timestamps: true }
);
module.exports = mongoose.model('guild', guildSchema);