🔖 Version 2.0.0 is released
This commit is contained in:
parent
9425cab262
commit
456fcfeacd
13 changed files with 124 additions and 69 deletions
|
@ -14,5 +14,6 @@ MONGODB_URL="CONNECTION STRNIG"
|
|||
|
||||
SUCCESS_COLOR=0xHEX
|
||||
ERROR_COLOR=0xHEX
|
||||
WAIT_COLOR=0xHEX
|
||||
|
||||
DEBUG=FALSE
|
||||
|
|
17
README.md
Normal file
17
README.md
Normal 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
0
log.json
Normal file
|
@ -1,10 +1,11 @@
|
|||
{
|
||||
"name": "controlpanel.gg-bot",
|
||||
"version": "1.1.0",
|
||||
"version": "2.0.0",
|
||||
"description": "Earn credits when chatting",
|
||||
"main": "src/index.js",
|
||||
"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": [
|
||||
"zyner",
|
||||
|
@ -30,6 +31,7 @@
|
|||
"discord.js": "^13.6.0",
|
||||
"dotenv": "^16.0.0",
|
||||
"mongoose": "^6.2.3",
|
||||
"pino": "^7.0.0-rc.9",
|
||||
"quick.db": "^7.1.3",
|
||||
"uuid": "^8.3.2"
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const credits = require('../../../helpers/database/models/creditSchema');
|
||||
const debug = require('../../../handlers/debug');
|
||||
const logger = require('../../../handlers/logger');
|
||||
module.exports = async (interaction) => {
|
||||
try {
|
||||
const user = await interaction.options.getUser('user');
|
||||
|
@ -29,12 +29,11 @@ module.exports = async (interaction) => {
|
|||
timestamp: new Date(),
|
||||
footer: { iconURL: process.env.FOOTER_ICON, text: process.env.FOOTER_TEXT },
|
||||
};
|
||||
|
||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
})
|
||||
.catch(async (err) => debug(err));
|
||||
.catch(async (err) => logger.error(err));
|
||||
} catch {
|
||||
async (err) => debug(err);
|
||||
async (err) => logger.error(err);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const credits = require('../../../helpers/database/models/creditSchema');
|
||||
const debug = require('../../../handlers/debug');
|
||||
const logger = require('../../../handlers/logger');
|
||||
const saveUser = require('../../../helpers/saveUser');
|
||||
|
||||
module.exports = async (interaction) => {
|
||||
|
@ -43,7 +43,7 @@ module.exports = async (interaction) => {
|
|||
fromUser.balance -= amount;
|
||||
toUser.balance += amount;
|
||||
|
||||
saveUser(fromUser, toUser);
|
||||
await saveUser(fromUser, toUser);
|
||||
|
||||
const embed = {
|
||||
title: 'Gift',
|
||||
|
@ -54,11 +54,11 @@ module.exports = async (interaction) => {
|
|||
timestamp: new Date(),
|
||||
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 });
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
async (err) => debug(err);
|
||||
async (err) => await logger.error(err);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
const { Permissions } = require('discord.js');
|
||||
|
||||
const credits = require('../../../helpers/database/models/creditSchema');
|
||||
const debug = require('../../../handlers/debug');
|
||||
const logger = require('../../../handlers/logger');
|
||||
module.exports = async (interaction) => {
|
||||
try {
|
||||
if (!interaction.member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
|
@ -26,7 +26,7 @@ module.exports = async (interaction) => {
|
|||
} else {
|
||||
const toUser = await credits.findOne({ userId: user.id });
|
||||
toUser.balance += amount;
|
||||
toUser.save();
|
||||
await toUser.save();
|
||||
const embed = {
|
||||
title: 'Give',
|
||||
description: `Gave ${amount <= 1 ? `${amount} credit` : `${amount} credits`} to ${user}.`,
|
||||
|
@ -34,9 +34,14 @@ module.exports = async (interaction) => {
|
|||
timestamp: new Date(),
|
||||
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 });
|
||||
}
|
||||
} catch {
|
||||
async (err) => debug(err);
|
||||
async (err) => await logger.error(err);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const credits = require('../../../helpers/database/models/creditSchema');
|
||||
const debug = require('../../../handlers/debug');
|
||||
const logger = require('../../../handlers/logger');
|
||||
|
||||
const api = require('../../../handlers/api.js');
|
||||
|
||||
|
@ -48,9 +48,9 @@ module.exports = async (interaction) => {
|
|||
};
|
||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
} else {
|
||||
const code = uuidv4();
|
||||
const code = await uuidv4();
|
||||
|
||||
api
|
||||
await api
|
||||
.post('vouchers', {
|
||||
uses: 1,
|
||||
code,
|
||||
|
@ -77,10 +77,15 @@ module.exports = async (interaction) => {
|
|||
|
||||
await user.save();
|
||||
|
||||
await logger.debug(
|
||||
`User: ${user.username} redeemed: ${
|
||||
amount <= 1 ? `${amount} credit` : `${amount} credits`
|
||||
}`
|
||||
);
|
||||
await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
})
|
||||
.catch(async (err) => {
|
||||
console.log(err);
|
||||
await logger.error(err);
|
||||
const embed = {
|
||||
title: 'Redeem',
|
||||
description: 'Something went wrong.',
|
||||
|
@ -92,6 +97,6 @@ module.exports = async (interaction) => {
|
|||
});
|
||||
}
|
||||
} catch {
|
||||
async (err) => debug(err);
|
||||
async (err) => await logger.error(err);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
const { Permissions } = require('discord.js');
|
||||
|
||||
const credits = require('../../../helpers/database/models/creditSchema');
|
||||
const debug = require('../../../handlers/debug');
|
||||
const logger = require('../../../handlers/logger');
|
||||
module.exports = async (interaction) => {
|
||||
if (!interaction.member.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
||||
const embed = {
|
||||
|
@ -26,17 +26,21 @@ module.exports = async (interaction) => {
|
|||
};
|
||||
return await interaction.editReply({ embeds: [embed], ephemeral: true });
|
||||
}
|
||||
const toUser = await credits.findOne({ userId: user.id });
|
||||
toUser.balance -= amount;
|
||||
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 toUser = await credits.findOne({ userId: user.id });
|
||||
toUser.balance -= amount;
|
||||
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 },
|
||||
};
|
||||
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 });
|
||||
};
|
||||
|
|
|
@ -1,6 +1,13 @@
|
|||
const { SlashCommandBuilder } = require('@discordjs/builders');
|
||||
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 = {
|
||||
permissions: new Permissions([
|
||||
Permissions.FLAGS.MANAGE_MESSAGES,
|
||||
|
@ -70,25 +77,18 @@ module.exports = {
|
|||
subcommand.setName('top').setDescription('Check the top balance.')
|
||||
),
|
||||
async execute(interaction) {
|
||||
await interaction.deferReply({ ephemeral: true });
|
||||
|
||||
if (interaction.options.getSubcommand() === 'balance') {
|
||||
require('./addons/balance.js')(interaction);
|
||||
}
|
||||
else if (interaction.options.getSubcommand() === 'gift') {
|
||||
require('./addons/gift.js')(interaction);
|
||||
}
|
||||
else if (interaction.options.getSubcommand() === 'give') {
|
||||
require('./addons/give.js')(interaction);
|
||||
}
|
||||
else if (interaction.options.getSubcommand() === 'redeem') {
|
||||
require('./addons/redeem.js')(interaction);
|
||||
}
|
||||
else if (interaction.options.getSubcommand() === 'take') {
|
||||
require('./addons/take.js')(interaction);
|
||||
}
|
||||
else if (interaction.options.getSubcommand() === 'top') {
|
||||
require('./addons/top.js')(interaction);
|
||||
await balance(interaction);
|
||||
} else if (interaction.options.getSubcommand() === 'gift') {
|
||||
await gift(interaction);
|
||||
} else if (interaction.options.getSubcommand() === 'give') {
|
||||
await give(interaction);
|
||||
} else if (interaction.options.getSubcommand() === 'redeem') {
|
||||
await redeem(interaction);
|
||||
} else if (interaction.options.getSubcommand() === 'take') {
|
||||
await take(interaction);
|
||||
} else if (interaction.options.getSubcommand() === 'top') {
|
||||
await top(interaction);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
module.exports = async (message) => {
|
||||
if (process.env.DEBUG) console.log(message);
|
||||
};
|
3
src/handlers/logger.js
Normal file
3
src/handlers/logger.js
Normal file
|
@ -0,0 +1,3 @@
|
|||
const pino = require('pino');
|
||||
const logger = pino({ level: process.env.DEBUG ? 'debug' : 'info' });
|
||||
module.exports = logger;
|
56
src/index.js
56
src/index.js
|
@ -1,14 +1,10 @@
|
|||
const fs = require('node:fs');
|
||||
const { Client, Collection, Intents } = require('discord.js');
|
||||
require('dotenv').config();
|
||||
|
||||
require('./helpers/database')();
|
||||
|
||||
const fs = require('node:fs');
|
||||
const { Client, Collection, Intents } = require('discord.js');
|
||||
const credits = require('./helpers/database/models/creditSchema');
|
||||
|
||||
// const db = require('quick.db');
|
||||
//
|
||||
// const credits = new db.table('credits');
|
||||
const logger = require('./handlers/logger');
|
||||
|
||||
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.once('ready', () => {
|
||||
console.log('Ready!');
|
||||
client.once('ready', async () => {
|
||||
await logger.info('Ready!');
|
||||
});
|
||||
|
||||
client.on('interactionCreate', async (interaction) => {
|
||||
|
@ -32,12 +28,40 @@ client.on('interactionCreate', async (interaction) => {
|
|||
if (!command) return;
|
||||
|
||||
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);
|
||||
}
|
||||
catch (error) {
|
||||
console.error(error);
|
||||
await logger.debug(`Executing command: ${interaction.commandName}`);
|
||||
} catch (err) {
|
||||
await logger.error(err);
|
||||
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,
|
||||
});
|
||||
}
|
||||
|
@ -52,12 +76,10 @@ client.on('messageCreate', async (message) => {
|
|||
{ $inc: { balance: 1 } },
|
||||
{ new: true, upsert: true }
|
||||
)
|
||||
.then(async (data) => console.log(data))
|
||||
.then(async (data) => await logger.debug('Credits added:', message.author.id))
|
||||
.catch(async (err) => {
|
||||
console.log(err);
|
||||
await logger.error(err);
|
||||
});
|
||||
|
||||
console.log(message.author, message.content);
|
||||
});
|
||||
|
||||
client.login(process.env.BOT_TOKEN);
|
||||
|
|
Loading…
Add table
Reference in a new issue