🔖 Version 2.2.0 released

This commit is contained in:
Axel Olausson Holtenäs 2022-03-06 09:54:11 +01:00
parent cf0073eced
commit cdaf1d39cd
No known key found for this signature in database
GPG key ID: E3AE7E194AE017ED
8 changed files with 182 additions and 33 deletions

View file

@ -9,7 +9,8 @@
"token": "required",
"timeout": "5000",
"rate": "1",
"minimumLength": "5"
"minimumLength": "5",
"excludedChannels": ["channel_id", "channel_id"]
},
"colors": { "success": "0x22bb33", "error": "0xbb2124", "wait": "0xf0ad4e" },
"mongodb": {

View file

@ -1,22 +1,24 @@
__basedir = __dirname;
__config = require(`${__basedir}/config.json`);
const fs = require('node:fs');
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
// __basedir = __dirname;
// __config = require(`${__basedir}/config.json`);
module.exports = async () => {
const fs = require('node:fs');
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const commands = [];
const commandFiles = fs.readdirSync(`${__basedir}/src/commands`);
const commands = [];
const commandFiles = fs.readdirSync(`${__basedir}/commands`);
for (const file of commandFiles) {
const command = require(`${__basedir}/src/commands/${file}`);
commands.push(command.data.toJSON());
}
for (const file of commandFiles) {
const command = require(`${__basedir}/commands/${file}`);
commands.push(command.data.toJSON());
}
const rest = new REST({ version: '9' }).setToken(__config.bot.token);
const rest = new REST({ version: '9' }).setToken(__config.bot.token);
rest
.put(Routes.applicationGuildCommands(__config.bot.clientId, __config.bot.guildId), {
body: commands,
})
.then(() => console.log('Successfully registered application commands.'))
.catch(console.error);
rest
.put(Routes.applicationGuildCommands(__config.bot.clientId, __config.bot.guildId), {
body: commands,
})
.then(() => console.log('Successfully registered application commands.'))
.catch(console.error);
};

View file

@ -1,6 +1,6 @@
{
"name": "xyter",
"version": "2.1.0",
"version": "2.2.0",
"description": "Earn credits while chatting! And more",
"main": "src/index.js",
"scripts": {

View file

@ -0,0 +1,38 @@
const { Permissions } = require('discord.js');
const credits = require(`${__basedir}/helpers/database/models/creditSchema`);
const logger = require(`${__basedir}/handlers/logger`);
const creditNoun = require(`${__basedir}/helpers/creditNoun`);
module.exports = async (interaction) => {
if (!interaction.member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
const embed = {
title: 'Set',
description: 'You need to have permission to manage this guild (MANAGE_GUILD)',
color: 0xbb2124,
timestamp: new Date(),
footer: { iconURL: __config.footer.icon, text: __config.footer.text },
};
return await interaction.editReply({ embeds: [embed], ephemeral: true });
}
const user = await interaction.options.getUser('user');
const amount = await interaction.options.getInteger('amount');
const toUser = await credits.findOne({ userId: user.id });
toUser.balance = amount;
await toUser.save();
const embed = {
title: 'Set',
description: `You set ${creditNoun(amount)} on ${user}.`,
color: 0x22bb33,
timestamp: new Date(),
footer: { iconURL: __config.footer.icon, text: __config.footer.text },
};
await logger.debug(
`Administrator: ${interaction.user.username} set ${
amount <= 1 ? `${amount} credit` : `${amount} credits`
} on ${user.username}`
);
return await interaction.editReply({ embeds: [embed], ephemeral: true });
};

View file

@ -0,0 +1,72 @@
const { Permissions } = require('discord.js');
const credits = require(`${__basedir}/helpers/database/models/creditSchema`);
const logger = require(`${__basedir}/handlers/logger`);
const saveUser = require(`${__basedir}/helpers/saveUser`);
const creditNoun = require(`${__basedir}/helpers/creditNoun`);
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)',
};
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');
const data = await credits.findOne({ userId: from.id });
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 },
};
return await interaction.editReply({ embeds: [embed], ephemeral: true });
} else {
if (data.balance < amount) {
const embed = {
title: 'Transfer',
description: `${from.username} has insufficient credits. ${from.username} balance is ${data.balance}`,
color: 0xbb2124,
timestamp: new Date(),
footer: { iconURL: __config.footer.icon, text: __config.footer.text },
};
return await interaction.editReply({ embeds: [embed], ephemeral: true });
} else {
const fromUser = await credits.findOne({ userId: from.id });
const toUser = await credits.findOne({ userId: to.id });
console.log(fromUser, toUser, amount);
fromUser.balance -= amount;
toUser.balance += amount;
await saveUser(fromUser, toUser);
const embed = {
title: 'Transfer',
description: `You sent ${creditNoun(amount)} from ${from} to ${to}.`,
color: 0x22bb33,
fields: [
{ name: `${from.username} Balance`, value: `${fromUser.balance}`, inline: true },
{ name: `${to.username} Balance`, value: `${toUser.balance}`, inline: true },
],
timestamp: new Date(),
footer: { iconURL: __config.footer.icon, text: __config.footer.text },
};
await logger.debug(`Gift sent from: ${interaction.user.username} to: ${to.username}`);
return await interaction.editReply({ embeds: [embed], ephemeral: true });
}
}
} catch {
async (err) => await logger.error(err);
}
};

View file

@ -7,6 +7,8 @@ const give = require('./addons/give.js');
const redeem = require('./addons/redeem.js');
const take = require('./addons/take.js');
const top = require('./addons/top.js');
const transfer = require('./addons/transfer.js');
const set = require('./addons/set.js');
module.exports = {
permissions: new Permissions([
@ -21,7 +23,7 @@ module.exports = {
.addSubcommand((subcommand) =>
subcommand
.setName('give')
.setDescription('Give credits to a user.')
.setDescription('Give credits to a user. (ADMIN)')
.addUserOption((option) =>
option.setName('user').setDescription('The user you want to pay.').setRequired(true)
)
@ -32,7 +34,7 @@ module.exports = {
.addSubcommand((subcommand) =>
subcommand
.setName('take')
.setDescription('Take credits from a user.')
.setDescription('Take credits from a user. (ADMIN)')
.addUserOption((option) =>
option
.setName('user')
@ -75,25 +77,58 @@ module.exports = {
)
.addSubcommand((subcommand) =>
subcommand.setName('top').setDescription('Check the top balance.')
)
.addSubcommand((subcommand) =>
subcommand
.setName('transfer')
.setDescription('Transfer credits from a user to another user. (ADMIN)')
.addUserOption((option) =>
option
.setName('from')
.setDescription('The user you want to take credits from.')
.setRequired(true)
)
.addUserOption((option) =>
option
.setName('to')
.setDescription('The user you want to give credits to.')
.setRequired(true)
)
.addIntegerOption((option) =>
option.setName('amount').setDescription('The amount you will transfer.').setRequired(true)
)
)
.addSubcommand((subcommand) =>
subcommand
.setName('set')
.setDescription('Set credits on a user. (ADMIN)')
.addUserOption((option) =>
option
.setName('user')
.setDescription('The user you want to set credits on.')
.setRequired(true)
)
.addIntegerOption((option) =>
option.setName('amount').setDescription('The amount you will set.').setRequired(true)
)
),
async execute(interaction) {
if (interaction.options.getSubcommand() === 'balance') {
await balance(interaction);
}
else if (interaction.options.getSubcommand() === 'gift') {
} else if (interaction.options.getSubcommand() === 'gift') {
await gift(interaction);
}
else if (interaction.options.getSubcommand() === 'give') {
} else if (interaction.options.getSubcommand() === 'give') {
await give(interaction);
}
else if (interaction.options.getSubcommand() === 'redeem') {
} else if (interaction.options.getSubcommand() === 'redeem') {
await redeem(interaction);
}
else if (interaction.options.getSubcommand() === 'take') {
} else if (interaction.options.getSubcommand() === 'take') {
await take(interaction);
}
else if (interaction.options.getSubcommand() === 'top') {
} else if (interaction.options.getSubcommand() === 'top') {
await top(interaction);
} else if (interaction.options.getSubcommand() === 'transfer') {
await transfer(interaction);
} else if (interaction.options.getSubcommand() === 'set') {
await set(interaction);
}
},
};

View file

@ -9,7 +9,7 @@ module.exports = {
async execute(message) {
if (message.author.bot) return;
if (message.content.length < __config.credits.minimumLength) return;
if (__config.credits.excludedChannels.includes(message.channel.id)) return;
if (!talkedRecently.has(message.author.id)) {
await credits
.findOneAndUpdate(

View file

@ -1,5 +1,6 @@
__basedir = __dirname;
__config = require(`${__basedir}/../config.json`);
require('../deploy-commands')();
require('./helpers/database')();
const fs = require('node:fs');