Made changes

This commit is contained in:
EmotionChild 2022-03-23 22:41:56 +13:00
parent 5c5fe202e7
commit 181e50e57b
7 changed files with 3690 additions and 3 deletions

18
.github/dependabot.yml vendored Normal file
View file

@ -0,0 +1,18 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
version: 2
updates:
- package-ecosystem: "npm" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "daily"
open-pull-requests-limit: 5
reviewers:
- EmotionChild
target-branch: "development"
labels:
- "npm"
- "dependencies"

1
.gitignore vendored
View file

@ -1,5 +1,4 @@
node_modules
package-lock.json
giveaways.js
config.json
giveaways.json

View file

@ -0,0 +1,18 @@
# Custom/External Database
you can use the pre-built available database example in your bot as your need. Read the following carefully to understand the Custom Databases.
## Database Setup
```md
SQL Database Setup
- Copy the code from the given file from: ./Database Examples/index4mysql.js.
- Install the mysql package: `npm i mysql`.
- Insert your DB values.
and that's it start the bot and it should work.
```
```md
MongoDB Setup
- Copy the code from the given file from: ./Database Examples/index4mongo.js.
- Install the quickmongo package: npm i quickmongo
- Add your connection string in the config file with the following variable: "mongo_url": "your-mongo-connection-string"
and that's it start the bot and it should work.
```

View file

@ -0,0 +1,159 @@
const fs = require('fs');
const { Client, Intents } = require('discord.js');
const client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MEMBERS,
Intents.FLAGS.GUILD_MESSAGE_REACTIONS
]
});
const config = require('./config.json');
client.config = config;
// Load MySQL
const MySQL = require('mysql');
const sql = MySQL.createConnection({
host: 'localhost',
user: 'Your MySQL user',
password: 'Your MySQL password',
database: 'Your MySQL database',
charset: 'utf8mb4' // In order to save emojis in the database correctly
});
sql.connect((err) => {
if (err) {
// Stop the process if we can't connect to the MySQL server
throw new Error('Impossible to connect to MySQL server. Code: ' + err.code);
} else {
console.log('[SQL] Connection to the MySQL server! Connection ID: ' + sql.threadId);
}
});
// Create giveaways table
sql.query(`
CREATE TABLE IF NOT EXISTS \`giveaways\`
(
\`id\` INT(1) NOT NULL AUTO_INCREMENT,
\`message_id\` VARCHAR(20) NOT NULL,
\`data\` JSON NOT NULL,
PRIMARY KEY (\`id\`)
);
`, (err) => {
if (err) console.error(err);
console.log('[SQL] Created table `giveaways`');
});
const { GiveawaysManager } = require('discord-giveaways');
const GiveawaysManagerWithOwnDatabase = class extends GiveawaysManager {
// This function is called when the manager needs to get all giveaways which are stored in the database
async getAllGiveaways() {
return new Promise((resolve, reject) => {
sql.query('SELECT `data` FROM `giveaways`', (err, res) => {
if (err) {
console.error(err);
return reject(err);
}
const giveaways = res.map((row) =>
JSON.parse(row.data, (_, v) => (typeof v === 'string' && /BigInt\("(-?\d+)"\)/.test(v)) ? eval(v) : v)
);
resolve(giveaways);
});
});
}
// This function is called when a giveaway needs to be saved in the database.
async saveGiveaway(messageId, giveawayData) {
return new Promise((resolve, reject) => {
sql.query(
'INSERT INTO `giveaways` (`message_id`, `data`) VALUES (?,?)',
[messageId, JSON.stringify(giveawayData, (_, v) => typeof v === 'bigint' ? `BigInt("${v}")` : v)],
(err, res) => {
if (err) {
console.error(err);
return reject(err);
}
resolve(true);
}
);
});
}
// This function is called when a giveaway needs to be edited in the database.
async editGiveaway(messageId, giveawayData) {
return new Promise((resolve, reject) => {
sql.query(
'UPDATE `giveaways` SET `data` = ? WHERE `message_id` = ?',
[JSON.stringify(giveawayData, (_, v) => typeof v === 'bigint' ? `BigInt("${v}")` : v), messageId],
(err, res) => {
if (err) {
console.error(err);
return reject(err);
}
resolve(true);
}
);
});
}
// This function is called when a giveaway needs to be deleted from the database.
async deleteGiveaway(messageId) {
return new Promise((resolve, reject) => {
sql.query('DELETE FROM `giveaways` WHERE `message_id` = ?', messageId, (err, res) => {
if (err) {
console.error(err);
return reject(err);
}
resolve(true);
});
});
}
}
// Create a new instance of your class
const manager = new GiveawaysManagerWithOwnDatabase(cclient, {
default: {
botsCanWin: false,
embedColor: '#FF0000',
embedColorEnd: '#000000',
reaction: '🎉',
}
});
// We now have a giveawaysManager property to access the manager everywhere!
client.giveawaysManager = manager;
/* Load all commands */
client.commands = new Discord.Collection();
fs.readdir('./commands/', (_err, files) => {
files.forEach((file) => {
if (!file.endsWith('.js')) return;
let props = require(`./commands/${file}`);
let commandName = file.split('.')[0];
client.commands.set(commandName, {
name: commandName,
...props
});
client.log(`👌 Command loaded: ${commandName}`);
});
syncroniseSlashCommands(client, client.commands.map((c) => ({
name: c.name,
description: c.description,
options: c.options,
type: 'CHAT_INPUT'
})), {
debug: true
});
});
/* Load all events */
fs.readdir('./events/', (_err, files) => {
files.forEach((file) => {
if (!file.endsWith('.js')) return;
const event = require(`./events/${file}`);
let eventName = file.split('.')[0];
console.log(`👌 Event loaded: ${eventName}`);
client.on(eventName, event.bind(null, client));
delete require.cache[require.resolve(`./events/${file}`)];
});
});
client.login(config.token);

View file

@ -1,24 +1,32 @@
# Giveaway-Child
## Requirements
- Nodejs v16
- Invite your bot with bot and applications scope
## Features
- Fast giveaways created using the best databases, like: mongodb, quick.db, .etc
- LAST CHANCE TO ENTER warning when a giveaway is about to end.
- Slash commands for faster giveaway creating.
Drop giveaway ability, drop giveaways anytime in your server with the drop command.
- Pause and un-Pause giveaway feature.
- Pause and un-pause giveaway feature.
## Links
- 🔗 [Invite Link](https://discord.com/api/oauth2/authorize?client_id=726333575091454002&permissions=8&scope=bot)
- [Support Server Link](https://discord.gg/SVQVzJq)
- 📑 [Commands](https://docs.emotionchild.com/coming_soon)
- 🌐 [Website](https://docs.emotionchild.com/coming_soon)
## Custom/External Database setup
- Read the [README](Database%20Examples/README.md) file and you are good to go to use custom db's.
## Setup
- `npm i`
- Pick a database from the Database Examples folder.
- Just copy and paste it into the [index file](index.js)
@ -26,4 +34,5 @@ Drop giveaway ability, drop giveaways anytime in your server with the drop comma
- Then run the bot with `npm run start`
## Credits
**Thanks to [Androz](https://github.com/Androz2091) for his package which make this bot possible [discord-giveaways](https://www.npmjs.com/package/discord-giveaways) give him a star for his work.**

3484
package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -24,7 +24,7 @@
"beautify": "^0.0.8",
"discord-giveaways": "^5.0.1",
"discord-sync-commands": "^0.3.0",
"discord.js": "^13.3.1",
"discord.js": "^13.6.0",
"fero-ms": "^2.0.7",
"ms": "^2.1.3",
"quickdb": "^1.0.5",