🔖 Version 2.0.0 is released

This commit is contained in:
Axel Olausson Holtenäs 2022-03-03 20:28:32 +01:00
parent 9425cab262
commit 456fcfeacd
No known key found for this signature in database
GPG key ID: E3AE7E194AE017ED
13 changed files with 124 additions and 69 deletions

View file

@ -14,5 +14,6 @@ MONGODB_URL="CONNECTION STRNIG"
SUCCESS_COLOR=0xHEX SUCCESS_COLOR=0xHEX
ERROR_COLOR=0xHEX ERROR_COLOR=0xHEX
WAIT_COLOR=0xHEX
DEBUG=FALSE DEBUG=FALSE

17
README.md Normal file
View file

@ -0,0 +1,17 @@
### Installation
Rename .env.example to .env and fill in the fields.
_Please note that MONGODB_URL needs to be inside of double quotes ("YourURL")._
You can leave any of the **FOOTER\_** fields empty, it will not impact the bot.
Then run **node deploy-commands.js** the first time then you can start the bot by **node src/index.js**
**Free MongoDB hosting**
- https://atlas.mongodb.com/
## Credits
**Please leave of some credits or if anyone ask about the bot, give them a link to the repository. Thanks!**

0
log.json Normal file
View file

View file

@ -1,10 +1,11 @@
{ {
"name": "controlpanel.gg-bot", "name": "controlpanel.gg-bot",
"version": "1.1.0", "version": "2.0.0",
"description": "Earn credits when chatting", "description": "Earn credits when chatting",
"main": "src/index.js", "main": "src/index.js",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon | pino-pretty -i pid,hostname -t yyyy-mm-dd HH:MM:s"
}, },
"keywords": [ "keywords": [
"zyner", "zyner",
@ -30,6 +31,7 @@
"discord.js": "^13.6.0", "discord.js": "^13.6.0",
"dotenv": "^16.0.0", "dotenv": "^16.0.0",
"mongoose": "^6.2.3", "mongoose": "^6.2.3",
"pino": "^7.0.0-rc.9",
"quick.db": "^7.1.3", "quick.db": "^7.1.3",
"uuid": "^8.3.2" "uuid": "^8.3.2"
} }

View file

@ -1,5 +1,5 @@
const credits = require('../../../helpers/database/models/creditSchema'); const credits = require('../../../helpers/database/models/creditSchema');
const debug = require('../../../handlers/debug'); const logger = require('../../../handlers/logger');
module.exports = async (interaction) => { module.exports = async (interaction) => {
try { try {
const user = await interaction.options.getUser('user'); const user = await interaction.options.getUser('user');
@ -29,12 +29,11 @@ module.exports = async (interaction) => {
timestamp: new Date(), timestamp: new Date(),
footer: { iconURL: process.env.FOOTER_ICON, text: process.env.FOOTER_TEXT }, footer: { iconURL: process.env.FOOTER_ICON, text: process.env.FOOTER_TEXT },
}; };
return await interaction.editReply({ embeds: [embed], ephemeral: true }); return await interaction.editReply({ embeds: [embed], ephemeral: true });
} }
}) })
.catch(async (err) => debug(err)); .catch(async (err) => logger.error(err));
} catch { } catch {
async (err) => debug(err); async (err) => logger.error(err);
} }
}; };

View file

@ -1,5 +1,5 @@
const credits = require('../../../helpers/database/models/creditSchema'); const credits = require('../../../helpers/database/models/creditSchema');
const debug = require('../../../handlers/debug'); const logger = require('../../../handlers/logger');
const saveUser = require('../../../helpers/saveUser'); const saveUser = require('../../../helpers/saveUser');
module.exports = async (interaction) => { module.exports = async (interaction) => {
@ -43,7 +43,7 @@ module.exports = async (interaction) => {
fromUser.balance -= amount; fromUser.balance -= amount;
toUser.balance += amount; toUser.balance += amount;
saveUser(fromUser, toUser); await saveUser(fromUser, toUser);
const embed = { const embed = {
title: 'Gift', title: 'Gift',
@ -54,11 +54,11 @@ module.exports = async (interaction) => {
timestamp: new Date(), timestamp: new Date(),
footer: { iconURL: process.env.FOOTER_ICON, text: process.env.FOOTER_TEXT }, footer: { iconURL: process.env.FOOTER_ICON, text: process.env.FOOTER_TEXT },
}; };
await logger.debug(`Gift sent from: ${interaction.user.username} to: ${user.username}`);
return await interaction.editReply({ embeds: [embed], ephemeral: true }); return await interaction.editReply({ embeds: [embed], ephemeral: true });
} }
} }
} catch { } catch {
async (err) => debug(err); async (err) => await logger.error(err);
} }
}; };

View file

@ -1,7 +1,7 @@
const { Permissions } = require('discord.js'); const { Permissions } = require('discord.js');
const credits = require('../../../helpers/database/models/creditSchema'); const credits = require('../../../helpers/database/models/creditSchema');
const debug = require('../../../handlers/debug'); const logger = require('../../../handlers/logger');
module.exports = async (interaction) => { module.exports = async (interaction) => {
try { try {
if (!interaction.member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) { if (!interaction.member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
@ -26,7 +26,7 @@ module.exports = async (interaction) => {
} else { } else {
const toUser = await credits.findOne({ userId: user.id }); const toUser = await credits.findOne({ userId: user.id });
toUser.balance += amount; toUser.balance += amount;
toUser.save(); await toUser.save();
const embed = { const embed = {
title: 'Give', title: 'Give',
description: `Gave ${amount <= 1 ? `${amount} credit` : `${amount} credits`} to ${user}.`, description: `Gave ${amount <= 1 ? `${amount} credit` : `${amount} credits`} to ${user}.`,
@ -34,9 +34,14 @@ module.exports = async (interaction) => {
timestamp: new Date(), timestamp: new Date(),
footer: { iconURL: process.env.FOOTER_ICON, text: process.env.FOOTER_TEXT }, footer: { iconURL: process.env.FOOTER_ICON, text: process.env.FOOTER_TEXT },
}; };
await logger.debug(
`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 { } catch {
async (err) => debug(err); async (err) => await logger.error(err);
} }
}; };

View file

@ -1,5 +1,5 @@
const credits = require('../../../helpers/database/models/creditSchema'); const credits = require('../../../helpers/database/models/creditSchema');
const debug = require('../../../handlers/debug'); const logger = require('../../../handlers/logger');
const api = require('../../../handlers/api.js'); const api = require('../../../handlers/api.js');
@ -48,9 +48,9 @@ module.exports = async (interaction) => {
}; };
return await interaction.editReply({ embeds: [embed], ephemeral: true }); return await interaction.editReply({ embeds: [embed], ephemeral: true });
} else { } else {
const code = uuidv4(); const code = await uuidv4();
api await api
.post('vouchers', { .post('vouchers', {
uses: 1, uses: 1,
code, code,
@ -77,10 +77,15 @@ module.exports = async (interaction) => {
await user.save(); await user.save();
await logger.debug(
`User: ${user.username} redeemed: ${
amount <= 1 ? `${amount} credit` : `${amount} credits`
}`
);
await interaction.editReply({ embeds: [embed], ephemeral: true }); await interaction.editReply({ embeds: [embed], ephemeral: true });
}) })
.catch(async (err) => { .catch(async (err) => {
console.log(err); await logger.error(err);
const embed = { const embed = {
title: 'Redeem', title: 'Redeem',
description: 'Something went wrong.', description: 'Something went wrong.',
@ -92,6 +97,6 @@ module.exports = async (interaction) => {
}); });
} }
} catch { } catch {
async (err) => debug(err); async (err) => await logger.error(err);
} }
}; };

View file

@ -1,7 +1,7 @@
const { Permissions } = require('discord.js'); const { Permissions } = require('discord.js');
const credits = require('../../../helpers/database/models/creditSchema'); const credits = require('../../../helpers/database/models/creditSchema');
const debug = require('../../../handlers/debug'); const logger = require('../../../handlers/logger');
module.exports = async (interaction) => { module.exports = async (interaction) => {
if (!interaction.member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) { if (!interaction.member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
const embed = { const embed = {
@ -26,17 +26,21 @@ module.exports = async (interaction) => {
}; };
return await interaction.editReply({ embeds: [embed], ephemeral: true }); return await interaction.editReply({ embeds: [embed], ephemeral: true });
} }
const toUser = await credits.findOne({ userId: user.id }); const toUser = await credits.findOne({ userId: user.id });
toUser.balance -= amount; toUser.balance -= amount;
toUser.save(); await toUser.save();
const embed = {
title: 'Take',
description: `You took ${amount <= 1 ? `${amount} credit` : `${amount} credits`} to ${user}.`,
color: 0x22bb33,
timestamp: new Date(),
footer: { iconURL: process.env.FOOTER_ICON, text: process.env.FOOTER_TEXT },
};
return await interaction.editReply({ embeds: [embed], ephemeral: true });
const embed = {
title: 'Take',
description: `You took ${amount <= 1 ? `${amount} credit` : `${amount} credits`} to ${user}.`,
color: 0x22bb33,
timestamp: new Date(),
footer: { iconURL: process.env.FOOTER_ICON, text: process.env.FOOTER_TEXT },
};
await logger.debug(
`Administrator: ${interaction.user.username} took ${
amount <= 1 ? `${amount} credit` : `${amount} credits`
} from ${user.username}`
);
return await interaction.editReply({ embeds: [embed], ephemeral: true });
}; };

View file

@ -1,6 +1,13 @@
const { SlashCommandBuilder } = require('@discordjs/builders'); const { SlashCommandBuilder } = require('@discordjs/builders');
const { MessageEmbed, Permissions } = require('discord.js'); const { MessageEmbed, Permissions } = require('discord.js');
const balance = require('./addons/balance.js');
const gift = require('./addons/gift.js');
const give = require('./addons/give.js');
const redeem = require('./addons/redeem.js');
const take = require('./addons/take.js');
const top = require('./addons/top.js');
module.exports = { module.exports = {
permissions: new Permissions([ permissions: new Permissions([
Permissions.FLAGS.MANAGE_MESSAGES, Permissions.FLAGS.MANAGE_MESSAGES,
@ -70,25 +77,18 @@ module.exports = {
subcommand.setName('top').setDescription('Check the top balance.') subcommand.setName('top').setDescription('Check the top balance.')
), ),
async execute(interaction) { async execute(interaction) {
await interaction.deferReply({ ephemeral: true });
if (interaction.options.getSubcommand() === 'balance') { if (interaction.options.getSubcommand() === 'balance') {
require('./addons/balance.js')(interaction); await balance(interaction);
} } else if (interaction.options.getSubcommand() === 'gift') {
else if (interaction.options.getSubcommand() === 'gift') { await gift(interaction);
require('./addons/gift.js')(interaction); } else if (interaction.options.getSubcommand() === 'give') {
} await give(interaction);
else if (interaction.options.getSubcommand() === 'give') { } else if (interaction.options.getSubcommand() === 'redeem') {
require('./addons/give.js')(interaction); await redeem(interaction);
} } else if (interaction.options.getSubcommand() === 'take') {
else if (interaction.options.getSubcommand() === 'redeem') { await take(interaction);
require('./addons/redeem.js')(interaction); } else if (interaction.options.getSubcommand() === 'top') {
} await top(interaction);
else if (interaction.options.getSubcommand() === 'take') {
require('./addons/take.js')(interaction);
}
else if (interaction.options.getSubcommand() === 'top') {
require('./addons/top.js')(interaction);
} }
}, },
}; };

View file

@ -1,3 +0,0 @@
module.exports = async (message) => {
if (process.env.DEBUG) console.log(message);
};

3
src/handlers/logger.js Normal file
View file

@ -0,0 +1,3 @@
const pino = require('pino');
const logger = pino({ level: process.env.DEBUG ? 'debug' : 'info' });
module.exports = logger;

View file

@ -1,14 +1,10 @@
const fs = require('node:fs');
const { Client, Collection, Intents } = require('discord.js');
require('dotenv').config(); require('dotenv').config();
require('./helpers/database')(); require('./helpers/database')();
const fs = require('node:fs');
const { Client, Collection, Intents } = require('discord.js');
const credits = require('./helpers/database/models/creditSchema'); const credits = require('./helpers/database/models/creditSchema');
const logger = require('./handlers/logger');
// const db = require('quick.db');
//
// const credits = new db.table('credits');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] }); const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
@ -20,8 +16,8 @@ for (const file of commandFiles) {
client.commands.set(command.data.name, command); client.commands.set(command.data.name, command);
} }
client.once('ready', () => { client.once('ready', async () => {
console.log('Ready!'); await logger.info('Ready!');
}); });
client.on('interactionCreate', async (interaction) => { client.on('interactionCreate', async (interaction) => {
@ -32,12 +28,40 @@ client.on('interactionCreate', async (interaction) => {
if (!command) return; if (!command) return;
try { try {
await interaction.deferReply({
embeds: [
{
author: {
name: interaction.client.user.username,
icon_url: interaction.client.user.displayAvatarURL(),
url: 'https://bot.zyner.org/',
},
title: 'Check',
description: 'Please wait...',
color: process.env.WAIT_COLOR,
timestamp: new Date(),
},
],
ephemeral: true,
});
await command.execute(interaction); await command.execute(interaction);
} await logger.debug(`Executing command: ${interaction.commandName}`);
catch (error) { } catch (err) {
console.error(error); await logger.error(err);
await interaction.reply({ await interaction.reply({
content: 'There was an error while executing this command!', embeds: [
{
author: {
name: interaction.client.user.username,
icon_url: interaction.client.user.displayAvatarURL(),
url: 'https://bot.zyner.org/',
},
title: 'Error',
description: 'There was an error while executing this command!',
color: process.env.WAIT_COLOR,
timestamp: new Date(),
},
],
ephemeral: true, ephemeral: true,
}); });
} }
@ -52,12 +76,10 @@ client.on('messageCreate', async (message) => {
{ $inc: { balance: 1 } }, { $inc: { balance: 1 } },
{ new: true, upsert: true } { new: true, upsert: true }
) )
.then(async (data) => console.log(data)) .then(async (data) => await logger.debug('Credits added:', message.author.id))
.catch(async (err) => { .catch(async (err) => {
console.log(err); await logger.error(err);
}); });
console.log(message.author, message.content);
}); });
client.login(process.env.BOT_TOKEN); client.login(process.env.BOT_TOKEN);