Merge pull request 'Updated a lot of things.' (#1) from development into main
Reviewed-on: #1
This commit is contained in:
commit
1745ff1419
35 changed files with 2470 additions and 2746 deletions
18
.github/dependabot.yml
vendored
18
.github/dependabot.yml
vendored
|
@ -1,18 +0,0 @@
|
|||
# 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
1
.gitignore
vendored
|
@ -1,4 +1,3 @@
|
|||
node_modules
|
||||
giveaways.js
|
||||
config.json
|
||||
giveaways.json
|
|
@ -1,18 +0,0 @@
|
|||
# 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.
|
||||
```
|
|
@ -1,119 +0,0 @@
|
|||
const fs = require('fs');
|
||||
|
||||
const Discord = require('discord.js');
|
||||
const client = new Discord.Client({
|
||||
intents: [
|
||||
Discord.Intents.FLAGS.GUILDS,
|
||||
Discord.Intents.FLAGS.GUILD_MEMBERS,
|
||||
Discord.Intents.FLAGS.GUILD_MESSAGE_REACTIONS
|
||||
]
|
||||
});
|
||||
|
||||
const config = require('./config.json');
|
||||
client.config = config;
|
||||
|
||||
// Load quickmongo
|
||||
const { Database } = require('quickmongo');
|
||||
const db = new Database(config.mongodb_url);
|
||||
|
||||
// Ceck the DB when it is ready
|
||||
db.on('ready', async () => {
|
||||
if (!Array.isArray(await b.get('giveaways'))) await db.set('giveaways', []);
|
||||
// Start the manager only after the BD got checked to prevent an error
|
||||
client.giveawaysManager._init();
|
||||
console.log('SUCCESS!');
|
||||
})
|
||||
|
||||
// Init discord giveaways
|
||||
const { GiveawaysManager } = require('discord-giveaways');
|
||||
const GiveawayManagerWithOwnDatabase = class extends GiveawaysManager {
|
||||
// This function is called when the manager needs to get all giveaways which are stored in the database.
|
||||
async getAllGiveaways() {
|
||||
// Get all giveaways from the database
|
||||
return await db.get('giveaways');
|
||||
}
|
||||
|
||||
// This function is called when a giveaway needs to be saved in the database.
|
||||
async sameGiveaway(messageId, giveawayData) {
|
||||
// Add the giveaway to the database
|
||||
await db.push('giveaways', giveawayData);
|
||||
// Don't forget to return something!
|
||||
return true;
|
||||
}
|
||||
|
||||
// This function is called when a giveaway needs to be edited in the database.
|
||||
async editGiveaway(messageId, giveawayData) {
|
||||
// Get all giveaways from the database
|
||||
const giveaways = await db.get('giveaways');
|
||||
// Remove the unexisting giveaway from the array
|
||||
const newGiveawaysArray = giveaways.filter((giveaway) => giveaway.messageId !== messageId);
|
||||
// Push the edited giveaway to the array
|
||||
newGiveawaysArray.push(giveawayData);
|
||||
// Save the updated array
|
||||
await db.set('giveaways', newGiveawaysArray);
|
||||
// Don't forget to return something!
|
||||
return true;
|
||||
}
|
||||
|
||||
// This function is called when a giveaway needs to be deleted from the database.
|
||||
async deleteGiveaway(messageId) {
|
||||
// Get all giveaways from the database
|
||||
const giveaways = await db.get('giveaways');
|
||||
// Remove the unexisting giveaway from the array
|
||||
const newGiveawaysArray = giveaways.filter((giveaway) => giveaway.messageId !== messageId);
|
||||
// Save the updated array
|
||||
await db.set('giveaways', newGiveawaysArray);
|
||||
// Don't forget to return something!
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
// Create a new instance of your new class
|
||||
const manager = new GiveawayManagerWithOwnDatabase(client, {
|
||||
default: {
|
||||
botsCanWin: false,
|
||||
embedColor: '#FF0000',
|
||||
embedColorEnd: '#000000',
|
||||
reaction: '🎉',
|
||||
}
|
||||
}, false);
|
||||
|
||||
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
|
||||
});
|
||||
console.log(`👌 Command loaded: ${commandName}`);
|
||||
});
|
||||
synchronizeSlashCommands(client, client.commands.map((c) => ({
|
||||
name: c.name,
|
||||
description: c.description,
|
||||
options: c.options,
|
||||
type: 'CHAT_INPUT'
|
||||
})), {
|
||||
debug: true
|
||||
});
|
||||
});
|
||||
|
||||
/* Load all commands */
|
||||
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}`)];
|
||||
});
|
||||
});
|
||||
|
||||
// Login
|
||||
client.login(config.token);
|
|
@ -1,159 +0,0 @@
|
|||
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);
|
2
LICENSE
2
LICENSE
|
@ -186,7 +186,7 @@
|
|||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright 2023 EmotionChild
|
||||
Copyright 2023 Toastie_t0ast
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
|
50
README.md
50
README.md
|
@ -1,37 +1,45 @@
|
|||
# Giveaway-Child
|
||||
# Holana
|
||||
|
||||
## Updates
|
||||
|
||||
- Update discord.js version to v13.
|
||||
- Format the code looks more cleaner.
|
||||
- Minor bot fixes and improvements.
|
||||
|
||||
## Requirements
|
||||
|
||||
- Nodejs v16
|
||||
- Invite your bot with bot and applications scope
|
||||
- Bot needs v16 of nodejs to work
|
||||
- Invite your bot with `bot` and `applications.commands` scope
|
||||
- Bot only uses slash commands, message content no longer exists.
|
||||
- Bot currently supports v14 of discord.js.
|
||||
|
||||
## 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.
|
||||
|
||||
- Lightning fast giveaways created using best databases, like: mongodb, quick.db, etc.
|
||||
- LAST CHANCE TO ENTER warning when giveaway is about to end.
|
||||
- Slash commands for faster and simpler giveaway creating.
|
||||
- Drop giveaway ability, drop giveaway anytime in your server with drop command.
|
||||
- Pause and un-pause giveaways.
|
||||
|
||||
## 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.elliebot.net/Giveaway-Child/Commands/)
|
||||
- 🌐 [Website](https://docs.elliebot.net/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.
|
||||
- ℹ [Support Server Link](https://discord.gg/etQdZxSyEH)
|
||||
- 📑 [Commands](https://docs.elliebot.net/Giveaway-child/Commands)
|
||||
- 🌐 [Website](https://docs.elliebot.net/category/holana)
|
||||
|
||||
## Setup
|
||||
|
||||
- `npm i`
|
||||
- Pick a database from the Database Examples folder.
|
||||
- Just copy and paste it into the [index file](index.js)
|
||||
- Fill out the [config file](config.example.json) and save it as config.js.
|
||||
- Then run the bot with `npm run start`
|
||||
## Custom/External Database setup
|
||||
|
||||
- Check the example folder to get the custom database examples
|
||||
|
||||
## Manual setup on local machine
|
||||
|
||||
- Run command `npm i`
|
||||
- Pick a database from `Database Examples` folder and copy it to `index.js` file.
|
||||
- Fill the configurations.
|
||||
- Run command `npm run start`
|
||||
|
||||
## Credits
|
||||
|
||||
|
|
|
@ -1,48 +1,51 @@
|
|||
const messages = require("../utils/messages");
|
||||
const Discord = require("discord.js");
|
||||
const messages = require("../utils/messages.js");
|
||||
|
||||
module.exports = {
|
||||
|
||||
description: 'Create a drop giveaway',
|
||||
description: "Create a drop giveaway",
|
||||
|
||||
options: [
|
||||
{
|
||||
name: 'winners',
|
||||
description: 'How many winners the giveaway should have',
|
||||
type: 'INTEGER',
|
||||
required: true
|
||||
name: "winners",
|
||||
description: "How many winners the giveaway should have",
|
||||
type: Discord.ApplicationCommandOptionType.Integer,
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
name: 'prize',
|
||||
description: 'What the prize of the giveaway should be',
|
||||
type: 'STRING',
|
||||
required: true
|
||||
name: "prize",
|
||||
description: "What the prize of the giveaway should be",
|
||||
type: Discord.ApplicationCommandOptionType.String,
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
name: 'channel',
|
||||
description: 'The channel to start the giveaway in',
|
||||
type: 'CHANNEL',
|
||||
required: true
|
||||
}
|
||||
name: "channel",
|
||||
description: "The channel to start the giveaway in",
|
||||
type: Discord.ApplicationCommandOptionType.Channel,
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
|
||||
run: async (client, interaction) => {
|
||||
|
||||
// If the member doesn't have enough permissions
|
||||
if(!interaction.member.permissions.has('MANAGE_MESSAGES') && !interaction.member.roles.cache.some((r) => r.name === "Giveaways")){
|
||||
if (
|
||||
!interaction.member.permissions.has("MANAGE_MESSAGES") &&
|
||||
!interaction.member.roles.cache.some((r) => r.name === "Giveaways")
|
||||
) {
|
||||
return interaction.reply({
|
||||
content: ':x: You need to have the manage messages permissions to start giveaways.',
|
||||
ephemeral: true
|
||||
content:
|
||||
":x: You need to have the manage messages permissions to start giveaways.",
|
||||
ephemeral: true,
|
||||
});
|
||||
}
|
||||
|
||||
const giveawayChannel = interaction.options.getChannel('channel');
|
||||
const giveawayWinnerCount = interaction.options.getInteger('winners');
|
||||
const giveawayPrize = interaction.options.getString('prize');
|
||||
const giveawayChannel = interaction.options.getChannel("channel");
|
||||
const giveawayWinnerCount = interaction.options.getInteger("winners");
|
||||
const giveawayPrize = interaction.options.getString("prize");
|
||||
|
||||
if(!giveawayChannel.isText()) {
|
||||
if (!giveawayChannel.isTextBased()) {
|
||||
return interaction.reply({
|
||||
content: ':x: Selected channel is not text-based.',
|
||||
ephemeral: true
|
||||
content: ":x: Selected channel is not text-based.",
|
||||
ephemeral: true,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -57,10 +60,9 @@ module.exports = {
|
|||
// specify drop
|
||||
isDrop: true,
|
||||
// Messages
|
||||
messages
|
||||
messages,
|
||||
});
|
||||
|
||||
interaction.reply(`Giveaway started in ${giveawayChannel}!`);
|
||||
|
||||
}
|
||||
},
|
||||
};
|
|
@ -1,65 +1,71 @@
|
|||
const ms = require('ms');
|
||||
const Discord = require("discord.js");
|
||||
|
||||
module.exports = {
|
||||
|
||||
description: 'End a giveaway',
|
||||
description: "End a giveaway",
|
||||
|
||||
options: [
|
||||
{
|
||||
name: 'giveaway',
|
||||
description: 'The giveaway to end (message ID or giveaway prize)',
|
||||
type: 'STRING',
|
||||
required: true
|
||||
}
|
||||
name: "giveaway",
|
||||
description: "The giveaway to end (message ID or giveaway prize)",
|
||||
type: Discord.ApplicationCommandOptionType.String,
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
|
||||
run: async (client, interaction) => {
|
||||
|
||||
// If the member doesn't have enough permissions
|
||||
if(!interaction.member.permissions.has('MANAGE_MESSAGES') && !interaction.member.roles.cache.some((r) => r.name === "Giveaways")){
|
||||
if (
|
||||
!interaction.member.permissions.has("MANAGE_MESSAGES") &&
|
||||
!interaction.member.roles.cache.some((r) => r.name === "Giveaways")
|
||||
) {
|
||||
return interaction.reply({
|
||||
content: ':x: You need to have the manage messages permissions to end giveaways.',
|
||||
ephemeral: true
|
||||
content:
|
||||
":x: You need to have the manage messages permissions to end giveaways.",
|
||||
ephemeral: true,
|
||||
});
|
||||
}
|
||||
|
||||
const query = interaction.options.getString('giveaway');
|
||||
const query = interaction.options.getString("giveaway");
|
||||
|
||||
// try to found the giveaway with prize then with ID
|
||||
const giveaway =
|
||||
// Search with giveaway prize
|
||||
client.giveawaysManager.giveaways.find((g) => g.prize === query && g.guildId === interaction.guild.id) ||
|
||||
client.giveawaysManager.giveaways.find(
|
||||
(g) => g.prize === query && g.guildId === interaction.guild.id
|
||||
) ||
|
||||
// Search with giveaway ID
|
||||
client.giveawaysManager.giveaways.find((g) => g.messageId === query && g.guildId === interaction.guild.id);
|
||||
client.giveawaysManager.giveaways.find(
|
||||
(g) => g.messageId === query && g.guildId === interaction.guild.id
|
||||
);
|
||||
|
||||
// If no giveaway was found
|
||||
if (!giveaway) {
|
||||
return interaction.reply({
|
||||
content: 'Unable to find a giveaway for `'+ query + '`.',
|
||||
ephemeral: true
|
||||
content: "Unable to find a giveaway for `" + query + "`.",
|
||||
ephemeral: true,
|
||||
});
|
||||
}
|
||||
|
||||
if (giveaway.ended) {
|
||||
return interaction.reply({
|
||||
content: 'This giveaway is already ended.',
|
||||
ephemeral: true
|
||||
content: "This giveaway is already ended.",
|
||||
ephemeral: true,
|
||||
});
|
||||
}
|
||||
|
||||
// Edit the giveaway
|
||||
client.giveawaysManager.end(giveaway.messageId)
|
||||
client.giveawaysManager
|
||||
.end(giveaway.messageId)
|
||||
// Success message
|
||||
.then(() => {
|
||||
// Success message
|
||||
interaction.reply('Giveaway ended!');
|
||||
interaction.reply("Giveaway ended!");
|
||||
})
|
||||
.catch((e) => {
|
||||
interaction.reply({
|
||||
content: e,
|
||||
ephemeral: true
|
||||
ephemeral: true,
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
},
|
||||
};
|
|
@ -1,41 +1,44 @@
|
|||
const message = require('../utils/messages');
|
||||
const messages = require("../utils/messages");
|
||||
const {
|
||||
MessageEmbed,
|
||||
MessageActionRow,
|
||||
MessageButton
|
||||
} = require('discord.js');
|
||||
EmbedBuilder,
|
||||
ActionRowBuilder,
|
||||
ButtonBuilder,
|
||||
ButtonStyle,
|
||||
} = require("discord.js");
|
||||
|
||||
module.exports = {
|
||||
name: "help",
|
||||
description: "Get all Bot Commands",
|
||||
run: async (client, interaction) => {
|
||||
|
||||
let helpembed = new MessageEmbed()
|
||||
helpembed.setColor("RANDOM")
|
||||
helpembed.setAuthor(
|
||||
`Commands of ${client.user.username}`
|
||||
)
|
||||
helpembed.setColor("#2f3136")
|
||||
helpembed.setThumbnail("https://cdn.discordapp.com/avatars/608119997713350679/d71c7cbb2ba132867367ed47261aea6d.png")
|
||||
let helpembed = new EmbedBuilder();
|
||||
helpembed.setAuthor({ name: `Commands of ${client.user.username}` });
|
||||
helpembed.setColor("#2f3136");
|
||||
helpembed.setThumbnail(
|
||||
"https://cdn.discordapp.com/attachments/765441543100170271/837111290265993246/196270_IDaqfU3u.png"
|
||||
);
|
||||
client.commands.map((cmd) => {
|
||||
helpembed.addField(
|
||||
`\`${cmd.name}\``,
|
||||
`${cmd.description}`,
|
||||
true
|
||||
);
|
||||
})
|
||||
helpembed.setTimestamp()
|
||||
helpembed.setFooter(`© EmotionChild | Have a nice day!`);
|
||||
helpembed.addFields({
|
||||
name: `\`${cmd.name}\``,
|
||||
value: `${cmd.description}`,
|
||||
});
|
||||
});
|
||||
helpembed.setTimestamp();
|
||||
helpembed.setFooter({ text: `© Holana | Have a nice day!` });
|
||||
|
||||
const row = new MessageActionRow()
|
||||
.addComponents(
|
||||
new MessageButton()
|
||||
.setEmoji('865572290065072128')
|
||||
const row = new ActionRowBuilder().addComponents(
|
||||
new ButtonBuilder()
|
||||
.setEmoji("865572290065072128")
|
||||
.setLabel(`Invite ${client.user.username}`)
|
||||
.setURL(`https://discord.com/api/oauth2/authorize?client_id=726333575091454002&permissions=8&scope=bot%20applications.commands`)
|
||||
.setStyle('LINK'),
|
||||
.setURL(
|
||||
`https://discord.com/api/oauth2/authorize?client_id=726333575091454002&permissions=8&scope=bot%20applications.commands`
|
||||
)
|
||||
.setStyle(ButtonStyle.Link)
|
||||
);
|
||||
|
||||
await interaction.reply({ embeds: [helpembed],components: [row], ephemeral: true });
|
||||
await interaction.reply({
|
||||
embeds: [helpembed],
|
||||
components: [row],
|
||||
ephemeral: true,
|
||||
});
|
||||
},
|
||||
};
|
|
@ -1,29 +1,35 @@
|
|||
const messages = require('../utils/messages');
|
||||
const messages = require("../utils/messages");
|
||||
const {
|
||||
MessageEmbed,
|
||||
MessageActionRow,
|
||||
MessageButton
|
||||
} = require('discord.js');
|
||||
EmbedBuilder,
|
||||
ActionRowBuilder,
|
||||
ButtonBuilder,
|
||||
ButtonStyle,
|
||||
} = require("discord.js");
|
||||
|
||||
module.exports = {
|
||||
name: "invite",
|
||||
description: "Get Invite Link for Holana",
|
||||
run: async (client, interaction) => {
|
||||
|
||||
let invite = new MessageEmbed()
|
||||
.setAuthor(`Invite of ${client.user.username}`, `${client.user.displayAvatarURL({ format: 'png' })}`)
|
||||
let invite = new EmbedBuilder()
|
||||
.setTitle(`${interaction.user.tag}`)
|
||||
.setDescription("You can invite the bot by clicking on the below button.")
|
||||
.setColor("#2f3136")
|
||||
.setFooter(`© EmotionChild | Have a nice day!`);
|
||||
.setFooter({ text: `© Holana | Have a nice day!` });
|
||||
|
||||
const row = new MessageActionRow()
|
||||
.addComponents(
|
||||
new MessageButton()
|
||||
.setEmoji('865572290065072128')
|
||||
const row = new ActionRowBuilder().addComponents(
|
||||
new ButtonBuilder()
|
||||
.setEmoji("865572290065072128")
|
||||
.setLabel(`Invite ${client.user.username}`)
|
||||
.setURL(`https://discord.com/api/oauth2/authorize?client_id=726333575091454002&permissions=8&scope=bot%20applications.commands`)
|
||||
.setStyle('LINK'),
|
||||
.setURL(
|
||||
`https://discord.com/api/oauth2/authorize?client_id=726333575091454002&permissions=8&scope=bot%20applications.commands`
|
||||
)
|
||||
.setStyle(ButtonStyle.Link)
|
||||
);
|
||||
|
||||
await interaction.reply({ embeds: [invite],components: [row], ephemeral: true });
|
||||
await interaction.reply({
|
||||
embeds: [invite],
|
||||
components: [row],
|
||||
ephemeral: true,
|
||||
});
|
||||
},
|
||||
};
|
71
commands/pause.js
Normal file
71
commands/pause.js
Normal file
|
@ -0,0 +1,71 @@
|
|||
const Discord = require("discord.js");
|
||||
|
||||
module.exports = {
|
||||
description: "Pause a giveaway",
|
||||
|
||||
options: [
|
||||
{
|
||||
name: "giveaway",
|
||||
description: "The giveaway to pause (message ID or giveaway prize)",
|
||||
type: Discord.ApplicationCommandOptionType.String,
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
|
||||
run: async (client, interaction) => {
|
||||
// If the member doesn't have enough permissions
|
||||
if (
|
||||
!interaction.member.permissions.has("MANAGE_MESSAGES") &&
|
||||
!interaction.member.roles.cache.some((r) => r.name === "Giveaways")
|
||||
) {
|
||||
return interaction.reply({
|
||||
content:
|
||||
":x: You need to have the manage messages permissions to pause giveaways.",
|
||||
ephemeral: true,
|
||||
});
|
||||
}
|
||||
|
||||
const query = interaction.options.getString("giveaway");
|
||||
|
||||
// try to found the giveaway with prize then with ID
|
||||
const giveaway =
|
||||
// Search with giveaway prize
|
||||
client.giveawaysManager.giveaways.find(
|
||||
(g) => g.prize === query && g.guildId === interaction.guild.id
|
||||
) ||
|
||||
// Search with giveaway ID
|
||||
client.giveawaysManager.giveaways.find(
|
||||
(g) => g.messageId === query && g.guildId === interaction.guild.id
|
||||
);
|
||||
|
||||
// If no giveaway was found
|
||||
if (!giveaway) {
|
||||
return interaction.reply({
|
||||
content: "Unable to find a giveaway for `" + query + "`.",
|
||||
ephemeral: true,
|
||||
});
|
||||
}
|
||||
|
||||
if (giveaway.pauseOptions.isPaused) {
|
||||
return interaction.reply({
|
||||
content: "This giveaway is already paused.",
|
||||
ephemeral: true,
|
||||
});
|
||||
}
|
||||
|
||||
// Edit the giveaway
|
||||
client.giveawaysManager
|
||||
.pause(giveaway.messageId)
|
||||
// Success message
|
||||
.then(() => {
|
||||
// Success message
|
||||
interaction.reply("Giveaway paused!");
|
||||
})
|
||||
.catch((e) => {
|
||||
interaction.reply({
|
||||
content: e,
|
||||
ephemeral: true,
|
||||
});
|
||||
});
|
||||
},
|
||||
};
|
|
@ -1,9 +1,9 @@
|
|||
const messages = require('../utils/messages');
|
||||
const { MessageEmbed } = require("discord.js");
|
||||
const messages = require("../utils/messages");
|
||||
const { EmbedBuilder } = require("discord.js");
|
||||
|
||||
module.exports = {
|
||||
name: "ping",
|
||||
description: "Tells the bot's latency,",
|
||||
description: "Tells a bot latency,",
|
||||
run: async (client, interaction) => {
|
||||
// If the member doesn't have enough permissions
|
||||
if (!interaction.member.permissions.has("SEND_MESSAGES")) {
|
||||
|
@ -15,16 +15,16 @@ module.exports = {
|
|||
}
|
||||
|
||||
let circles = {
|
||||
green: "<:online:885049752297824276>",
|
||||
yellow: "<:idle:885049726460899339>",
|
||||
red: "<:offline:885049312877346817>",
|
||||
green: "<:online:903711513183940669>",
|
||||
yellow: "<:idle:903711513490112512> ",
|
||||
red: "<:dnd:903711513066487851>",
|
||||
};
|
||||
|
||||
let botping = new MessageEmbed()
|
||||
.setTitle(`${client.user.name} Ping`)
|
||||
let botping = new EmbedBuilder()
|
||||
.setTitle(`${client.user.username} Ping`)
|
||||
.setColor("2f3136")
|
||||
.addFields({
|
||||
name: "<:link:911514727375577088> Bot Ping:",
|
||||
name: "<:connection2:896715171454677013> Bot Ping:",
|
||||
value: `${
|
||||
client.ws?.ping <= 200
|
||||
? circles.green
|
||||
|
|
|
@ -1,62 +1,70 @@
|
|||
module.exports = {
|
||||
const Discord = require("discord.js");
|
||||
|
||||
description: 'Reroll a giveaway',
|
||||
module.exports = {
|
||||
description: "Reroll a giveaway",
|
||||
|
||||
options: [
|
||||
{
|
||||
name: 'giveaway',
|
||||
description: 'The giveaway to reroll (message ID or prize)',
|
||||
type: 'STRING',
|
||||
required: true
|
||||
}
|
||||
name: "giveaway",
|
||||
description: "The giveaway to reroll (message ID or prize)",
|
||||
type: Discord.ApplicationCommandOptionType.String,
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
|
||||
run: async (client, interaction) => {
|
||||
|
||||
// If the member doesn't have enough permissions
|
||||
if(!interaction.member.permissions.has('MANAGE_MESSAGES') && !interaction.member.roles.cache.some((r) => r.name === "Giveaways")){
|
||||
if (
|
||||
!interaction.member.permissions.has("MANAGE_MESSAGES") &&
|
||||
!interaction.member.roles.cache.some((r) => r.name === "Giveaways")
|
||||
) {
|
||||
return interaction.reply({
|
||||
content: ':x: You need to have the manage messages permissions to reroll giveaways.',
|
||||
ephemeral: true
|
||||
content:
|
||||
":x: You need to have the manage messages permissions to reroll giveaways.",
|
||||
ephemeral: true,
|
||||
});
|
||||
}
|
||||
|
||||
const query = interaction.options.getString('giveaway');
|
||||
const query = interaction.options.getString("giveaway");
|
||||
|
||||
// try to found the giveaway with prize then with ID
|
||||
const giveaway =
|
||||
// Search with giveaway prize
|
||||
client.giveawaysManager.giveaways.find((g) => g.prize === query && g.guildId === interaction.guild.id) ||
|
||||
client.giveawaysManager.giveaways.find(
|
||||
(g) => g.prize === query && g.guildId === interaction.guild.id
|
||||
) ||
|
||||
// Search with giveaway ID
|
||||
client.giveawaysManager.giveaways.find((g) => g.messageId === query && g.guildId === interaction.guild.id);
|
||||
client.giveawaysManager.giveaways.find(
|
||||
(g) => g.messageId === query && g.guildId === interaction.guild.id
|
||||
);
|
||||
|
||||
// If no giveaway was found
|
||||
if (!giveaway) {
|
||||
return interaction.reply({
|
||||
content: 'Unable to find a giveaway for `'+ query +'`.',
|
||||
ephemeral: true
|
||||
content: "Unable to find a giveaway for `" + query + "`.",
|
||||
ephemeral: true,
|
||||
});
|
||||
}
|
||||
|
||||
if (!giveaway.ended) {
|
||||
return interaction.reply({
|
||||
content: 'The giveaway is not ended yet.',
|
||||
ephemeral: true
|
||||
content: "The giveaway is not ended yet.",
|
||||
ephemeral: true,
|
||||
});
|
||||
}
|
||||
|
||||
// Reroll the giveaway
|
||||
client.giveawaysManager.reroll(giveaway.messageId)
|
||||
client.giveawaysManager
|
||||
.reroll(giveaway.messageId)
|
||||
.then(() => {
|
||||
// Success message
|
||||
interaction.reply('Giveaway rerolled!');
|
||||
interaction.reply("Giveaway rerolled!");
|
||||
})
|
||||
.catch((e) => {
|
||||
interaction.reply({
|
||||
content: e,
|
||||
ephemeral: true
|
||||
ephemeral: true,
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
},
|
||||
};
|
|
@ -1,56 +1,60 @@
|
|||
const ms = require('ms');
|
||||
const Discord = require("discord.js");
|
||||
const ms = require("ms");
|
||||
const messages = require("../utils/messages");
|
||||
|
||||
module.exports = {
|
||||
|
||||
description: 'Start a giveaway',
|
||||
description: "Start a giveaway",
|
||||
|
||||
options: [
|
||||
{
|
||||
name: 'duration',
|
||||
description: 'How long the giveaway should last for. Example values: 1m, 1h, 1d',
|
||||
type: 'STRING',
|
||||
required: true
|
||||
name: "duration",
|
||||
description:
|
||||
"How long the giveaway should last for. Example values: 1m, 1h, 1d",
|
||||
type: Discord.ApplicationCommandOptionType.String,
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
name: 'winners',
|
||||
description: 'How many winners the giveaway should have',
|
||||
type: 'INTEGER',
|
||||
required: true
|
||||
name: "winners",
|
||||
description: "How many winners the giveaway should have",
|
||||
type: Discord.ApplicationCommandOptionType.Integer,
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
name: 'prize',
|
||||
description: 'What the prize of the giveaway should be',
|
||||
type: 'STRING',
|
||||
required: true
|
||||
name: "prize",
|
||||
description: "What the prize of the giveaway should be",
|
||||
type: Discord.ApplicationCommandOptionType.String,
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
name: 'channel',
|
||||
description: 'The channel to start the giveaway in',
|
||||
type: 'CHANNEL',
|
||||
required: true
|
||||
}
|
||||
name: "channel",
|
||||
description: "The channel to start the giveaway in",
|
||||
type: Discord.ApplicationCommandOptionType.Channel,
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
|
||||
run: async (client, interaction) => {
|
||||
|
||||
// If the member doesn't have enough permissions
|
||||
if(!interaction.member.permissions.has('MANAGE_MESSAGES') && !interaction.member.roles.cache.some((r) => r.name === "Giveaways")){
|
||||
if (
|
||||
!interaction.member.permissions.has("MANAGE_MESSAGES") &&
|
||||
!interaction.member.roles.cache.some((r) => r.name === "Giveaways")
|
||||
) {
|
||||
return interaction.reply({
|
||||
content: ':x: You need to have the manage messages permissions to start giveaways.',
|
||||
ephemeral: true
|
||||
content:
|
||||
":x: You need to have the manage messages permissions to start giveaways.",
|
||||
ephemeral: true,
|
||||
});
|
||||
}
|
||||
|
||||
const giveawayChannel = interaction.options.getChannel('channel');
|
||||
const giveawayDuration = interaction.options.getString('duration');
|
||||
const giveawayWinnerCount = interaction.options.getInteger('winners');
|
||||
const giveawayPrize = interaction.options.getString('prize');
|
||||
const giveawayChannel = interaction.options.getChannel("channel");
|
||||
const giveawayDuration = interaction.options.getString("duration");
|
||||
const giveawayWinnerCount = interaction.options.getInteger("winners");
|
||||
const giveawayPrize = interaction.options.getString("prize");
|
||||
|
||||
if(!giveawayChannel.isText()) {
|
||||
if (!giveawayChannel.isTextBased()) {
|
||||
return interaction.reply({
|
||||
content: ':x: Selected channel is not text-based.',
|
||||
ephemeral: true
|
||||
content: ":x: Selected channel is not text-based.",
|
||||
ephemeral: true,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -65,11 +69,9 @@ module.exports = {
|
|||
// Who hosts this giveaway
|
||||
hostedBy: client.config.hostedBy ? interaction.user : null,
|
||||
// Messages
|
||||
messages
|
||||
messages,
|
||||
});
|
||||
|
||||
interaction.reply(`Giveaway started in ${giveawayChannel}!`);
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
};
|
|
@ -1,10 +1,10 @@
|
|||
const os = require('os');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const feroms = require('fero-ms');
|
||||
const os = require("os");
|
||||
const { EmbedBuilder } = require("discord.js");
|
||||
const feroms = require("fero-ms");
|
||||
|
||||
module.exports = {
|
||||
name: 'stats',
|
||||
description: 'Sends bot physical statistics',
|
||||
name: "stats",
|
||||
description: "Sends bot physical statistics",
|
||||
run: async (client, interaction) => {
|
||||
let uptime = client.uptime;
|
||||
let shortUptime = feroms.ms(uptime);
|
||||
|
@ -12,74 +12,76 @@ module.exports = {
|
|||
let cores = os.cpus().length;
|
||||
let platform = os.platform();
|
||||
let nodejs = process.version;
|
||||
let djs = require('discord.js').version;
|
||||
let botversion = require('../package.json').version;
|
||||
let djs = require("discord.js").version;
|
||||
let botversion = require("../package.json").version;
|
||||
let server = client.guilds.cache.size;
|
||||
let user = client.users.cache.size;
|
||||
let channel = client.channels.cache.size;
|
||||
|
||||
let statsembed = new MessageEmbed()
|
||||
let statsembed = new EmbedBuilder()
|
||||
.addFields(
|
||||
{
|
||||
name: '<:live2:896715171882500106> I have been online for?',
|
||||
value: `\`\`\`${shortUptime}\`\`\``
|
||||
name: "<:live2:896715171882500106> I have been online for?",
|
||||
value: `\`\`\`${shortUptime}\`\`\``,
|
||||
},
|
||||
{
|
||||
name: '<:globe:896718155416760340> Guilds',
|
||||
name: "<:globe:896718155416760340> Guilds",
|
||||
value: `\`${server}\``,
|
||||
inline: true
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: '<:mention:896718358672707584> Users',
|
||||
name: "<:mention:896718358672707584> Users",
|
||||
value: `\`${user}\``,
|
||||
inline: true
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: '<:channel:896717996326809641> Channels',
|
||||
name: "<:channel:896717996326809641> Channels",
|
||||
value: `\`${channel}\``,
|
||||
inline: true
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: 'Bot Version',
|
||||
name: "Bot Version",
|
||||
value: `\`v${botversion}\``,
|
||||
inline: true
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: '<:prime:896718399776886816> Arch',
|
||||
name: "<:prime:896718399776886816> Arch",
|
||||
value: `\`${os.arch()}\``,
|
||||
inline: true
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: '<:info:896718244461826140> Platform',
|
||||
name: "<:info:896718244461826140> Platform",
|
||||
value: `\`${platform}\``,
|
||||
inline: true
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: '<:desktop:896718080821047346> Cores',
|
||||
name: "<:desktop:896718080821047346> Cores",
|
||||
value: `\`${cores}\``,
|
||||
inline: true
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: '<a:Discord:896723328277024819> Discord.js Version',
|
||||
name: "<a:Discord:896723328277024819> Discord.js Version",
|
||||
value: `\`v${djs}\``,
|
||||
inline: true
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: '<:jss:896718571491704852> Node.js Version',
|
||||
name: "<:jss:896718571491704852> Node.js Version",
|
||||
value: `\`${nodejs}\``,
|
||||
inline: true
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: '<:ram:896715172029276180> Ram Usage',
|
||||
value: `\`${(process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2)}MB/ ${(os.totalmem() / 1024 / 1024).toFixed(2)}MB\``,
|
||||
inline: true
|
||||
name: "<:ram:896715172029276180> Ram Usage",
|
||||
value: `\`${(process.memoryUsage().heapUsed / 1024 / 1024).toFixed(
|
||||
2
|
||||
)}MB/ ${(os.totalmem() / 1024 / 1024).toFixed(2)}MB\``,
|
||||
inline: true,
|
||||
},
|
||||
{
|
||||
name: '<:desktop:896718080821047346> CPU Model',
|
||||
value: `\`\`\`${model}\`\`\``
|
||||
name: "<:desktop:896718080821047346> CPU Model",
|
||||
value: `\`\`\`${model}\`\`\``,
|
||||
}
|
||||
)
|
||||
.setTimestamp()
|
||||
.setTimestamp();
|
||||
await interaction.reply({ embeds: [statsembed] });
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
71
commands/unpause.js
Normal file
71
commands/unpause.js
Normal file
|
@ -0,0 +1,71 @@
|
|||
const Discord = require("discord.js");
|
||||
|
||||
module.exports = {
|
||||
description: "Unpause a giveaway",
|
||||
|
||||
options: [
|
||||
{
|
||||
name: "giveaway",
|
||||
description: "The giveaway to unpause (message ID or giveaway prize)",
|
||||
type: Discord.ApplicationCommandOptionType.String,
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
|
||||
run: async (client, interaction) => {
|
||||
// If the member doesn't have enough permissions
|
||||
if (
|
||||
!interaction.member.permissions.has("MANAGE_MESSAGES") &&
|
||||
!interaction.member.roles.cache.some((r) => r.name === "Giveaways")
|
||||
) {
|
||||
return interaction.reply({
|
||||
content:
|
||||
":x: You need to have the manage messages permissions to unpause giveaways.",
|
||||
ephemeral: true,
|
||||
});
|
||||
}
|
||||
|
||||
const query = interaction.options.getString("giveaway");
|
||||
|
||||
// try to found the giveaway with prize then with ID
|
||||
const giveaway =
|
||||
// Search with giveaway prize
|
||||
client.giveawaysManager.giveaways.find(
|
||||
(g) => g.prize === query && g.guildId === interaction.guild.id
|
||||
) ||
|
||||
// Search with giveaway ID
|
||||
client.giveawaysManager.giveaways.find(
|
||||
(g) => g.messageId === query && g.guildId === interaction.guild.id
|
||||
);
|
||||
|
||||
// If no giveaway was found
|
||||
if (!giveaway) {
|
||||
return interaction.reply({
|
||||
content: "Unable to find a giveaway for `" + query + "`.",
|
||||
ephemeral: true,
|
||||
});
|
||||
}
|
||||
|
||||
if (!giveaway.pauseOptions.isPaused) {
|
||||
return interaction.reply({
|
||||
content: "This giveaway is not paused.",
|
||||
ephemeral: true,
|
||||
});
|
||||
}
|
||||
|
||||
// Edit the giveaway
|
||||
client.giveawaysManager
|
||||
.unpause(giveaway.messageId)
|
||||
// Success message
|
||||
.then(() => {
|
||||
// Success message
|
||||
interaction.reply("Giveaway unpaused!");
|
||||
})
|
||||
.catch((e) => {
|
||||
interaction.reply({
|
||||
content: e,
|
||||
ephemeral: true,
|
||||
});
|
||||
});
|
||||
},
|
||||
};
|
|
@ -1,13 +1,13 @@
|
|||
module.exports = (client, interaction) => {
|
||||
|
||||
if (!interaction.isCommand()) return;
|
||||
if (!interaction.isChatInputCommand()) return;
|
||||
|
||||
const command = client.commands.get(interaction.commandName);
|
||||
|
||||
if (!command) return void interaction.reply({
|
||||
if (!command)
|
||||
return void interaction.reply({
|
||||
content: `Command \`${interaction.commandName}\` not found.`,
|
||||
ephemeral: true
|
||||
ephemeral: true,
|
||||
});
|
||||
|
||||
command.run(client, interaction);
|
||||
};
|
||||
}
|
|
@ -1,12 +1,21 @@
|
|||
const { ActivityType } = require("discord.js");
|
||||
|
||||
module.exports = (client) => {
|
||||
console.log(
|
||||
`Ready to server in ${client.channels.cache.size} channels on ${client.guilds.cache.size} servers, for a total of ${client.users.cache.size} users.`
|
||||
`Ready to serve in ${client.channels.cache.size} channels on ${client.guilds.cache.size} servers, for a total of ${client.users.cache.size} users.`
|
||||
);
|
||||
|
||||
const activities = [`Giveaways in ${client.guilds.cache.size} guilds`,`over ${client.users.cache.size} users!`];
|
||||
const activities = [
|
||||
`Giveaways in ${client.guilds.cache.size} guilds`,
|
||||
"/help",
|
||||
`over ${client.users.cache.size} users!`,
|
||||
`${
|
||||
client.giveawaysManager.giveaways.filter((g) => !g.ended).length
|
||||
} active giveaways!`,
|
||||
];
|
||||
|
||||
setInterval(() => {
|
||||
let activity = activities[Math.floor(Math.random() * activities.length)];
|
||||
client.user.setActivity(activity, { type: "WATCHING" });
|
||||
client.user.setActivity(activity, { type: ActivityType.Watching });
|
||||
}, 20000);
|
||||
|
||||
};
|
5
examples/custom-databases/.eslintrc.json
Normal file
5
examples/custom-databases/.eslintrc.json
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"rules": {
|
||||
"no-restricted-globals": "off"
|
||||
}
|
||||
}
|
64
examples/custom-databases/enmap.js
Normal file
64
examples/custom-databases/enmap.js
Normal file
|
@ -0,0 +1,64 @@
|
|||
const Discord = require("discord.js");
|
||||
const client = new Discord.Client({
|
||||
intents: [
|
||||
Discord.IntentsBitField.Flags.Guilds,
|
||||
Discord.IntentsBitField.Flags.GuildMessageReactions,
|
||||
],
|
||||
});
|
||||
|
||||
// Load Enmap
|
||||
const Enmap = require("enmap");
|
||||
|
||||
// Create giveaways table
|
||||
const giveawayDB = new Enmap({ name: "giveaways" });
|
||||
|
||||
const { GiveawaysManager } = require("discord-giveaways");
|
||||
const GiveawayManagerWithOwnDatabase = class extends GiveawaysManager {
|
||||
// This function is called when the manager needs to get all giveaways which are stored in the database.
|
||||
async getAllGiveaways() {
|
||||
// Get all giveaways from the database
|
||||
return giveawayDB.fetchEverything().array();
|
||||
}
|
||||
|
||||
// This function is called when a giveaway needs to be saved in the database.
|
||||
async saveGiveaway(messageId, giveawayData) {
|
||||
// Add the new giveaway to the database
|
||||
giveawayDB.set(messageId, giveawayData);
|
||||
// Don't forget to return something!
|
||||
return true;
|
||||
}
|
||||
|
||||
// This function is called when a giveaway needs to be edited in the database.
|
||||
async editGiveaway(messageId, giveawayData) {
|
||||
// Replace the unedited giveaway with the edited giveaway
|
||||
giveawayDB.set(messageId, giveawayData);
|
||||
// Don't forget to return something!
|
||||
return true;
|
||||
}
|
||||
|
||||
// This function is called when a giveaway needs to be deleted from the database.
|
||||
async deleteGiveaway(messageId) {
|
||||
// Remove the giveaway from the database
|
||||
giveawayDB.delete(messageId);
|
||||
// Don't forget to return something!
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
// Create a new instance of your new class
|
||||
const manager = new GiveawayManagerWithOwnDatabase(client, {
|
||||
default: {
|
||||
botsCanWin: false,
|
||||
embedColor: "#FF0000",
|
||||
embedColorEnd: "#000000",
|
||||
reaction: "🎉",
|
||||
},
|
||||
});
|
||||
// We now have a giveawaysManager property to access the manager everywhere!
|
||||
client.giveawaysManager = manager;
|
||||
|
||||
client.on("ready", () => {
|
||||
console.log("Bot is ready!");
|
||||
});
|
||||
|
||||
client.login(process.env.DISCORD_BOT_TOKEN);
|
133
examples/custom-databases/mongoose.js
Normal file
133
examples/custom-databases/mongoose.js
Normal file
|
@ -0,0 +1,133 @@
|
|||
const Discord = require("discord.js");
|
||||
const client = new Discord.Client({
|
||||
intents: [
|
||||
Discord.IntentsBitField.Flags.Guilds,
|
||||
Discord.IntentsBitField.Flags.GuildMessageReactions,
|
||||
],
|
||||
});
|
||||
|
||||
// Connect to the database
|
||||
const mongoose = require("mongoose");
|
||||
mongoose.connect("mongodb://localhost/database");
|
||||
const db = mongoose.connection;
|
||||
|
||||
// Check the connection
|
||||
db.on("error", console.error.bind(console, "Connection error:"));
|
||||
db.once("open", () => {
|
||||
console.log("Connected to MongoDB.");
|
||||
});
|
||||
|
||||
// Create the schema for giveaways
|
||||
const giveawaySchema = new mongoose.Schema(
|
||||
{
|
||||
messageId: String,
|
||||
channelId: String,
|
||||
guildId: String,
|
||||
startAt: Number,
|
||||
endAt: Number,
|
||||
ended: Boolean,
|
||||
winnerCount: Number,
|
||||
prize: String,
|
||||
messages: {
|
||||
giveaway: String,
|
||||
giveawayEnded: String,
|
||||
title: String,
|
||||
inviteToParticipate: String,
|
||||
drawing: String,
|
||||
dropMessage: String,
|
||||
winMessage: mongoose.Mixed,
|
||||
embedFooter: mongoose.Mixed,
|
||||
noWinner: String,
|
||||
winners: String,
|
||||
endedAt: String,
|
||||
hostedBy: String,
|
||||
},
|
||||
thumbnail: String,
|
||||
image: String,
|
||||
hostedBy: String,
|
||||
winnerIds: { type: [String], default: undefined },
|
||||
reaction: mongoose.Mixed,
|
||||
botsCanWin: Boolean,
|
||||
embedColor: mongoose.Mixed,
|
||||
embedColorEnd: mongoose.Mixed,
|
||||
exemptPermissions: { type: [], default: undefined },
|
||||
exemptMembers: String,
|
||||
bonusEntries: String,
|
||||
extraData: mongoose.Mixed,
|
||||
lastChance: {
|
||||
enabled: Boolean,
|
||||
content: String,
|
||||
threshold: Number,
|
||||
embedColor: mongoose.Mixed,
|
||||
},
|
||||
pauseOptions: {
|
||||
isPaused: Boolean,
|
||||
content: String,
|
||||
unPauseAfter: Number,
|
||||
embedColor: mongoose.Mixed,
|
||||
durationAfterPause: Number,
|
||||
infiniteDurationText: String,
|
||||
},
|
||||
isDrop: Boolean,
|
||||
allowedMentions: {
|
||||
parse: { type: [String], default: undefined },
|
||||
users: { type: [String], default: undefined },
|
||||
roles: { type: [String], default: undefined },
|
||||
},
|
||||
},
|
||||
{ id: false }
|
||||
);
|
||||
|
||||
// Create the model
|
||||
const giveawayModel = mongoose.model("giveaways", giveawaySchema);
|
||||
|
||||
const { GiveawaysManager } = require("discord-giveaways");
|
||||
const GiveawayManagerWithOwnDatabase = class extends GiveawaysManager {
|
||||
// This function is called when the manager needs to get all giveaways which are stored in the database.
|
||||
async getAllGiveaways() {
|
||||
// Get all giveaways from the database. We fetch all documents by passing an empty condition.
|
||||
return await giveawayModel.find().lean().exec();
|
||||
}
|
||||
|
||||
// This function is called when a giveaway needs to be saved in the database.
|
||||
async saveGiveaway(messageId, giveawayData) {
|
||||
// Add the new giveaway to the database
|
||||
await giveawayModel.create(giveawayData);
|
||||
// Don't forget to return something!
|
||||
return true;
|
||||
}
|
||||
|
||||
// This function is called when a giveaway needs to be edited in the database.
|
||||
async editGiveaway(messageId, giveawayData) {
|
||||
// Find by messageId and update it
|
||||
await giveawayModel.updateOne({ messageId }, giveawayData).exec();
|
||||
// Don't forget to return something!
|
||||
return true;
|
||||
}
|
||||
|
||||
// This function is called when a giveaway needs to be deleted from the database.
|
||||
async deleteGiveaway(messageId) {
|
||||
// Find by messageId and delete it
|
||||
await giveawayModel.deleteOne({ messageId }).exec();
|
||||
// Don't forget to return something!
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
// Create a new instance of your new class
|
||||
const manager = new GiveawayManagerWithOwnDatabase(client, {
|
||||
default: {
|
||||
botsCanWin: false,
|
||||
embedColor: "#FF0000",
|
||||
embedColorEnd: "#000000",
|
||||
reaction: "🎉",
|
||||
},
|
||||
});
|
||||
// We now have a giveawaysManager property to access the manager everywhere!
|
||||
client.giveawaysManager = manager;
|
||||
|
||||
client.on("ready", () => {
|
||||
console.log("Bot is ready!");
|
||||
});
|
||||
|
||||
client.login(process.env.DISCORD_BOT_TOKEN);
|
144
examples/custom-databases/mysql.js
Normal file
144
examples/custom-databases/mysql.js
Normal file
|
@ -0,0 +1,144 @@
|
|||
const Discord = require("discord.js");
|
||||
const client = new Discord.Client({
|
||||
intents: [
|
||||
Discord.IntentsBitField.Flags.Guilds,
|
||||
Discord.IntentsBitField.Flags.GuildMessageReactions,
|
||||
],
|
||||
});
|
||||
|
||||
// Load mysql
|
||||
const MySQL = require("mysql");
|
||||
const sql = MySQL.createConnection({
|
||||
host: "localhost",
|
||||
user: "Your MySQL user",
|
||||
password: "Your MySQL password",
|
||||
database: "Your MySQL database name",
|
||||
charset: "utf8mb4", // In order to save emojis 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] Connected 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 GiveawayManagerWithOwnDatabase = 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 new class
|
||||
const manager = new GiveawayManagerWithOwnDatabase(client, {
|
||||
default: {
|
||||
botsCanWin: false,
|
||||
embedColor: "#FF0000",
|
||||
embedColorEnd: "#000000",
|
||||
reaction: "🎉",
|
||||
},
|
||||
});
|
||||
// We now have a giveawaysManager property to access the manager everywhere!
|
||||
client.giveawaysManager = manager;
|
||||
|
||||
client.on("ready", () => {
|
||||
console.log("Bot is ready!");
|
||||
});
|
||||
|
||||
client.login(process.env.DISCORD_BOT_TOKEN);
|
81
examples/custom-databases/nano.js
Normal file
81
examples/custom-databases/nano.js
Normal file
|
@ -0,0 +1,81 @@
|
|||
const Discord = require("discord.js");
|
||||
const client = new Discord.Client({
|
||||
intents: [
|
||||
Discord.IntentsBitField.Flags.Guilds,
|
||||
Discord.IntentsBitField.Flags.GuildMessageReactions,
|
||||
],
|
||||
});
|
||||
|
||||
// Load nano
|
||||
const nano = require("nano")("http://admin:mypassword@localhost:5984");
|
||||
let giveawayDB;
|
||||
|
||||
// Check the DB
|
||||
(async () => {
|
||||
if (!(await nano.db.list()).includes("giveaways"))
|
||||
await nano.db.create("giveaways");
|
||||
giveawayDB = nano.use("giveaways");
|
||||
// Start the manager only after the DB got checked to prevent an error
|
||||
client.giveawaysManager._init();
|
||||
})();
|
||||
|
||||
const { GiveawaysManager } = require("discord-giveaways");
|
||||
const GiveawayManagerWithOwnDatabase = class extends GiveawaysManager {
|
||||
// This function is called when the manager needs to get all giveaways which are stored in the database.
|
||||
async getAllGiveaways() {
|
||||
// Get all giveaways from the database
|
||||
return (await giveawayDB.list({ include_docs: true })).rows.map(
|
||||
(r) => r.doc
|
||||
);
|
||||
}
|
||||
|
||||
// This function is called when a giveaway needs to be saved in the database.
|
||||
async saveGiveaway(messageId, giveawayData) {
|
||||
// Add the new giveaway to the database
|
||||
await giveawayDB.insert(giveawayData, messageId);
|
||||
// Don't forget to return something!
|
||||
return true;
|
||||
}
|
||||
|
||||
// This function is called when a giveaway needs to be edited in the database.
|
||||
async editGiveaway(messageId, giveawayData) {
|
||||
// Get the unedited giveaway from the database
|
||||
const giveaway = await giveawayDB.get(messageId);
|
||||
// Edit the giveaway
|
||||
await giveawayDB.insert({ ...giveaway, ...giveawayData });
|
||||
// Don't forget to return something!
|
||||
return true;
|
||||
}
|
||||
|
||||
// This function is called when a giveaway needs to be deleted from the database.
|
||||
async deleteGiveaway(messageId) {
|
||||
// Get the giveaway from the database
|
||||
const giveaway = await giveawayDB.get(messageId);
|
||||
// Remove the giveaway from the database
|
||||
await giveawayDB.destroy(messageId, giveaway._rev);
|
||||
// Don't forget to return something!
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
// Create a new instance of your new class
|
||||
const manager = new GiveawayManagerWithOwnDatabase(
|
||||
client,
|
||||
{
|
||||
default: {
|
||||
botsCanWin: false,
|
||||
embedColor: "#FF0000",
|
||||
embedColorEnd: "#000000",
|
||||
reaction: "🎉",
|
||||
},
|
||||
},
|
||||
false
|
||||
); // ATTENTION: Add "false" in order to not start the manager until the DB got checked, see below
|
||||
// We now have a giveawaysManager property to access the manager everywhere!
|
||||
client.giveawaysManager = manager;
|
||||
|
||||
client.on("ready", () => {
|
||||
console.log("Bot is ready!");
|
||||
});
|
||||
|
||||
client.login(process.env.DISCORD_BOT_TOKEN);
|
76
examples/custom-databases/quick.db.js
Normal file
76
examples/custom-databases/quick.db.js
Normal file
|
@ -0,0 +1,76 @@
|
|||
const Discord = require("discord.js");
|
||||
const client = new Discord.Client({
|
||||
intents: [
|
||||
Discord.IntentsBitField.Flags.Guilds,
|
||||
Discord.IntentsBitField.Flags.GuildMessageReactions,
|
||||
],
|
||||
});
|
||||
|
||||
// Load quick.db
|
||||
const db = require("quick.db");
|
||||
if (!Array.isArray(db.get("giveaways"))) db.set("giveaways", []);
|
||||
|
||||
const { GiveawaysManager } = require("discord-giveaways");
|
||||
const GiveawayManagerWithOwnDatabase = class extends GiveawaysManager {
|
||||
// This function is called when the manager needs to get all giveaways which are stored in the database.
|
||||
async getAllGiveaways() {
|
||||
// Get all giveaways from the database
|
||||
return db.get("giveaways");
|
||||
}
|
||||
|
||||
// This function is called when a giveaway needs to be saved in the database.
|
||||
async saveGiveaway(messageId, giveawayData) {
|
||||
// Add the new giveaway to the database
|
||||
db.push("giveaways", giveawayData);
|
||||
// Don't forget to return something!
|
||||
return true;
|
||||
}
|
||||
|
||||
// This function is called when a giveaway needs to be edited in the database.
|
||||
async editGiveaway(messageId, giveawayData) {
|
||||
// Get all giveaways from the database
|
||||
const giveaways = db.get("giveaways");
|
||||
// Remove the unedited giveaway from the array
|
||||
const newGiveawaysArray = giveaways.filter(
|
||||
(giveaway) => giveaway.messageId !== messageId
|
||||
);
|
||||
// Push the edited giveaway into the array
|
||||
newGiveawaysArray.push(giveawayData);
|
||||
// Save the updated array
|
||||
db.set("giveaways", newGiveawaysArray);
|
||||
// Don't forget to return something!
|
||||
return true;
|
||||
}
|
||||
|
||||
// This function is called when a giveaway needs to be deleted from the database.
|
||||
async deleteGiveaway(messageId) {
|
||||
// Get all giveaways from the database
|
||||
const giveaways = db.get("giveaways");
|
||||
// Remove the giveaway from the array
|
||||
const newGiveawaysArray = giveaways.filter(
|
||||
(giveaway) => giveaway.messageId !== messageId
|
||||
);
|
||||
// Save the updated array
|
||||
db.set("giveaways", newGiveawaysArray);
|
||||
// Don't forget to return something!
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
// Create a new instance of your new class
|
||||
const manager = new GiveawayManagerWithOwnDatabase(client, {
|
||||
default: {
|
||||
botsCanWin: false,
|
||||
embedColor: "#FF0000",
|
||||
embedColorEnd: "#000000",
|
||||
reaction: "🎉",
|
||||
},
|
||||
});
|
||||
// We now have a giveawaysManager property to access the manager everywhere!
|
||||
client.giveawaysManager = manager;
|
||||
|
||||
client.on("ready", () => {
|
||||
console.log("Bot is ready!");
|
||||
});
|
||||
|
||||
client.login(process.env.DISCORD_BOT_TOKEN);
|
87
examples/custom-databases/quick.replit.js
Normal file
87
examples/custom-databases/quick.replit.js
Normal file
|
@ -0,0 +1,87 @@
|
|||
const Discord = require("discord.js");
|
||||
const client = new Discord.Client({
|
||||
intents: [
|
||||
Discord.IntentsBitField.Flags.Guilds,
|
||||
Discord.IntentsBitField.Flags.GuildMessageReactions,
|
||||
],
|
||||
});
|
||||
|
||||
// Load quick.replit
|
||||
const { Database } = require("quick.replit");
|
||||
const db = new Database();
|
||||
|
||||
// Check the DB when it is ready
|
||||
db.once("ready", async () => {
|
||||
if (!Array.isArray(await db.get("giveaways"))) await db.set("giveaways", []);
|
||||
// Start the manager only after the DB got checked to prevent an error
|
||||
client.giveawaysManager._init();
|
||||
});
|
||||
|
||||
const { GiveawaysManager } = require("discord-giveaways");
|
||||
const GiveawayManagerWithOwnDatabase = class extends GiveawaysManager {
|
||||
// This function is called when the manager needs to get all giveaways which are stored in the database.
|
||||
async getAllGiveaways() {
|
||||
// Get all giveaways from the database
|
||||
return await db.get("giveaways");
|
||||
}
|
||||
|
||||
// This function is called when a giveaway needs to be saved in the database.
|
||||
async saveGiveaway(messageId, giveawayData) {
|
||||
// Add the new giveaway to the database
|
||||
await db.push("giveaways", giveawayData);
|
||||
// Don't forget to return something!
|
||||
return true;
|
||||
}
|
||||
|
||||
// This function is called when a giveaway needs to be edited in the database.
|
||||
async editGiveaway(messageId, giveawayData) {
|
||||
// Get all giveaways from the database
|
||||
const giveaways = await db.get("giveaways");
|
||||
// Remove the unedited giveaway from the array
|
||||
const newGiveawaysArray = giveaways.filter(
|
||||
(giveaway) => giveaway.messageId !== messageId
|
||||
);
|
||||
// Push the edited giveaway into the array
|
||||
newGiveawaysArray.push(giveawayData);
|
||||
// Save the updated array
|
||||
await db.set("giveaways", newGiveawaysArray);
|
||||
// Don't forget to return something!
|
||||
return true;
|
||||
}
|
||||
|
||||
// This function is called when a giveaway needs to be deleted from the database.
|
||||
async deleteGiveaway(messageId) {
|
||||
// Get all giveaways from the database
|
||||
const giveaways = await db.get("giveaways");
|
||||
// Remove the giveaway from the array
|
||||
const newGiveawaysArray = giveaways.filter(
|
||||
(giveaway) => giveaway.messageId !== messageId
|
||||
);
|
||||
// Save the updated array
|
||||
await db.set("giveaways", newGiveawaysArray);
|
||||
// Don't forget to return something!
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
// Create a new instance of your new class
|
||||
const manager = new GiveawayManagerWithOwnDatabase(
|
||||
client,
|
||||
{
|
||||
default: {
|
||||
botsCanWin: false,
|
||||
embedColor: "#FF0000",
|
||||
embedColorEnd: "#000000",
|
||||
reaction: "🎉",
|
||||
},
|
||||
},
|
||||
false
|
||||
); // ATTENTION: Add "false" in order to not start the manager until the DB got checked, see below
|
||||
// We now have a giveawaysManager property to access the manager everywhere!
|
||||
client.giveawaysManager = manager;
|
||||
|
||||
client.on("ready", () => {
|
||||
console.log("Bot is ready!");
|
||||
});
|
||||
|
||||
client.login(process.env.DISCORD_BOT_TOKEN);
|
71
examples/custom-databases/quickmongo.js
Normal file
71
examples/custom-databases/quickmongo.js
Normal file
|
@ -0,0 +1,71 @@
|
|||
const Discord = require("discord.js");
|
||||
const client = new Discord.Client({
|
||||
intents: [
|
||||
Discord.IntentsBitField.Flags.Guilds,
|
||||
Discord.IntentsBitField.Flags.GuildMessageReactions,
|
||||
],
|
||||
});
|
||||
|
||||
// Load quickmongo
|
||||
const { Database } = require("quickmongo");
|
||||
const giveawayDB = new Database("mongodb://localhost/database", {
|
||||
collectionName: "giveaways",
|
||||
});
|
||||
|
||||
// Start the manager only after the DB turned ready to prevent an error
|
||||
giveawayDB.once("ready", () => client.giveawaysManager._init());
|
||||
|
||||
const { GiveawaysManager } = require("discord-giveaways");
|
||||
const GiveawayManagerWithOwnDatabase = class extends GiveawaysManager {
|
||||
// This function is called when the manager needs to get all giveaways which are stored in the database.
|
||||
async getAllGiveaways() {
|
||||
// Get all giveaways from the database
|
||||
return (await giveawayDB.all()).map((element) => element.data);
|
||||
}
|
||||
|
||||
// This function is called when a giveaway needs to be saved in the database.
|
||||
async saveGiveaway(messageId, giveawayData) {
|
||||
// Add the new giveaway to the database
|
||||
await giveawayDB.set(messageId, giveawayData);
|
||||
// Don't forget to return something!
|
||||
return true;
|
||||
}
|
||||
|
||||
// This function is called when a giveaway needs to be edited in the database.
|
||||
async editGiveaway(messageId, giveawayData) {
|
||||
// Replace the unedited giveaway with the edited giveaway
|
||||
await giveawayDB.set(messageId, giveawayData);
|
||||
// Don't forget to return something!
|
||||
return true;
|
||||
}
|
||||
|
||||
// This function is called when a giveaway needs to be deleted from the database.
|
||||
async deleteGiveaway(messageId) {
|
||||
// Remove the giveaway from the database
|
||||
await giveawayDB.delete(messageId);
|
||||
// Don't forget to return something!
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
// Create a new instance of your new class
|
||||
const manager = new GiveawayManagerWithOwnDatabase(
|
||||
client,
|
||||
{
|
||||
default: {
|
||||
botsCanWin: false,
|
||||
embedColor: "#FF0000",
|
||||
embedColorEnd: "#000000",
|
||||
reaction: "🎉",
|
||||
},
|
||||
},
|
||||
false
|
||||
); // ATTENTION: Add "false" in order to not start the manager until the DB got checked, see below
|
||||
// We now have a giveawaysManager property to access the manager everywhere!
|
||||
client.giveawaysManager = manager;
|
||||
|
||||
client.on("ready", () => {
|
||||
console.log("Bot is ready!");
|
||||
});
|
||||
|
||||
client.login(process.env.DISCORD_BOT_TOKEN);
|
83
examples/custom-databases/replit.js
Normal file
83
examples/custom-databases/replit.js
Normal file
|
@ -0,0 +1,83 @@
|
|||
const Discord = require("discord.js");
|
||||
const client = new Discord.Client({
|
||||
intents: [
|
||||
Discord.IntentsBitField.Flags.Guilds,
|
||||
Discord.IntentsBitField.Flags.GuildMessageReactions,
|
||||
],
|
||||
});
|
||||
|
||||
// Load Replit Database
|
||||
const Database = require("@replit/database");
|
||||
const db = new Database();
|
||||
(async () => {
|
||||
if (!Array.isArray(await db.get("giveaways"))) await db.set("giveaways", []);
|
||||
})();
|
||||
|
||||
const { GiveawaysManager } = require("discord-giveaways");
|
||||
const GiveawayManagerWithOwnDatabase = class extends GiveawaysManager {
|
||||
// This function is called when the manager needs to get all giveaways which are stored in the database.
|
||||
async getAllGiveaways() {
|
||||
// Get all giveaways from the database
|
||||
return await db.get("giveaways");
|
||||
}
|
||||
|
||||
// This function is called when a giveaway needs to be saved in the database.
|
||||
async saveGiveaway(messageId, giveawayData) {
|
||||
// Get all giveaways from the database
|
||||
const giveawaysArray = await db.get("giveaways");
|
||||
// Push the new giveaway into the array
|
||||
giveawaysArray.push(giveawayData);
|
||||
// Save the updated array
|
||||
await db.set("giveaways", giveawaysArray);
|
||||
// Don't forget to return something!
|
||||
return true;
|
||||
}
|
||||
|
||||
// This function is called when a giveaway needs to be edited in the database.
|
||||
async editGiveaway(messageId, giveawayData) {
|
||||
// Get all giveaways from the database
|
||||
const giveaways = await db.get("giveaways");
|
||||
// Remove the unedited giveaway from the array
|
||||
const newGiveawaysArray = giveaways.filter(
|
||||
(giveaway) => giveaway.messageId !== messageId
|
||||
);
|
||||
// Push the edited giveaway into the array
|
||||
newGiveawaysArray.push(giveawayData);
|
||||
// Save the updated array
|
||||
await db.set("giveaways", newGiveawaysArray);
|
||||
// Don't forget to return something!
|
||||
return true;
|
||||
}
|
||||
|
||||
// This function is called when a giveaway needs to be deleted from the database.
|
||||
async deleteGiveaway(messageId) {
|
||||
// Get all giveaways from the database
|
||||
const giveaways = await db.get("giveaways");
|
||||
// Remove the giveaway from the array
|
||||
const newGiveawaysArray = giveaways.filter(
|
||||
(giveaway) => giveaway.messageId !== messageId
|
||||
);
|
||||
// Save the updated array
|
||||
await db.set("giveaways", newGiveawaysArray);
|
||||
// Don't forget to return something!
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
// Create a new instance of your new class
|
||||
const manager = new GiveawayManagerWithOwnDatabase(client, {
|
||||
default: {
|
||||
botsCanWin: false,
|
||||
embedColor: "#FF0000",
|
||||
embedColorEnd: "#000000",
|
||||
reaction: "🎉",
|
||||
},
|
||||
});
|
||||
// We now have a giveawaysManager property to access the manager everywhere!
|
||||
client.giveawaysManager = manager;
|
||||
|
||||
client.on("ready", () => {
|
||||
console.log("Bot is ready!");
|
||||
});
|
||||
|
||||
client.login(process.env.DISCORD_BOT_TOKEN);
|
1
examples/simple.js
Normal file
1
examples/simple.js
Normal file
|
@ -0,0 +1 @@
|
|||
// Example bot available on https://toastielab.dev/toastie_t0ast/Holana
|
1
giveaways.json
Normal file
1
giveaways.json
Normal file
|
@ -0,0 +1 @@
|
|||
[{"messageId":"1178260749441830943","channelId":"553759294953357314","guildId":"553759294953357312","startAt":1700989652527,"endAt":1700989652557,"ended":true,"winnerCount":1,"prize":"test","messages":{"giveaway":"🎉🎉 **GIVEAWAY** 🎉🎉","giveawayEnded":"🎉🎉 **GIVEAWAY ENDED** 🎉🎉","title":"{this.prize}","inviteToParticipate":"React with 🎉 to participate!","winMessage":"Congratulations, {winners}! You won **{this.prize}**!","drawing":"Drawing: {timestamp}","dropMessage":"Be the first to react with 🎉 !","embedFooter":"Giveaways","noWinner":"Giveaway cancelled, no valid participations.","winners":"winner(s)","endedAt":"Ended at","hostedBy":"Hosted by: {this.hostedBy}"},"hostedBy":"<@234542843732033537>"},{"messageId":"1178260884200620084","channelId":"553759294953357314","guildId":"553759294953357312","startAt":1700989684632,"endAt":1700989724632,"ended":true,"winnerCount":1,"prize":"test","messages":{"giveaway":"🎉🎉 **GIVEAWAY** 🎉🎉","giveawayEnded":"🎉🎉 **GIVEAWAY ENDED** 🎉🎉","title":"{this.prize}","inviteToParticipate":"React with 🎉 to participate!","winMessage":"Congratulations, {winners}! You won **{this.prize}**!","drawing":"Drawing: {timestamp}","dropMessage":"Be the first to react with 🎉 !","embedFooter":"Giveaways","noWinner":"Giveaway cancelled, no valid participations.","winners":"winner(s)","endedAt":"Ended at","hostedBy":"Hosted by: {this.hostedBy}"},"hostedBy":"<@234542843732033537>","winnerIds":["234542843732033537"]}]
|
12
index.js
12
index.js
|
@ -1,13 +1,13 @@
|
|||
process.title = 'Giveaway Child';
|
||||
process.title = 'Holana';
|
||||
|
||||
const fs = require("fs");
|
||||
|
||||
const Discord = require("discord.js");
|
||||
const client = new Discord.Client({
|
||||
intents: [
|
||||
Discord.Intents.FLAGS.GUILDS,
|
||||
Discord.Intents.FLAGS.GUILD_MEMBERS,
|
||||
Discord.Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
|
||||
Discord.GatewayIntentBits.Guilds,
|
||||
Discord.GatewayIntentBits.GuildMembers,
|
||||
Discord.GatewayIntentBits.GuildMessageReactions,
|
||||
],
|
||||
});
|
||||
|
||||
|
@ -27,7 +27,7 @@ client.giveawaysManager = new GiveawaysManager(client, {
|
|||
lastChance: {
|
||||
enabled: true,
|
||||
content: "⚠️ **LAST CHANCE TO ENTER !** ⚠️",
|
||||
threshold: 5000,
|
||||
threshold: 10000,
|
||||
embedColor: "#FF0000",
|
||||
},
|
||||
},
|
||||
|
@ -79,7 +79,7 @@ fs.readdir("./commands/", (_err, files) => {
|
|||
name: c.name,
|
||||
description: c.description,
|
||||
options: c.options,
|
||||
type: "CHAT_INPUT",
|
||||
type: Discord.ApplicationCommandType.ChatInput,
|
||||
})),
|
||||
{
|
||||
debug: true,
|
||||
|
|
1952
package-lock.json
generated
1952
package-lock.json
generated
File diff suppressed because it is too large
Load diff
21
package.json
21
package.json
|
@ -1,36 +1,33 @@
|
|||
{
|
||||
"name": "giveaway-child",
|
||||
"version": "2.1.1",
|
||||
"version": "3.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"start": "node index.js",
|
||||
"dev": "nodemon index.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": "16.x"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/EmotionChild/Giveaway-Child.git"
|
||||
"url": "git+https://toastielab.dev/toastie_t0ast/Holana.git"
|
||||
},
|
||||
"author": "EmotionChild",
|
||||
"license": "GPL-3.0-or-later",
|
||||
"author": "Toastie",
|
||||
"license": "Apache-2.0",
|
||||
"bugs": {
|
||||
"url": "https://github.com/EmotionChild/Giveaway-Child/issues"
|
||||
"url": "https://toastielab.dev/toastie_t0ast/Holana/issues"
|
||||
},
|
||||
"homepage": "https://github.com/EmotionChild/Giveaway-Child#readme",
|
||||
"homepage": "https://toastielab.dev/toastie_t0ast/Holana#readme",
|
||||
"dependencies": {
|
||||
"beautify": "0.0.8",
|
||||
"discord-giveaways": "^5.0.1",
|
||||
"discord-giveaways": "^6.0.1",
|
||||
"discord-sync-commands": "0.3.0",
|
||||
"discord.js": "^13.14.0",
|
||||
"discord.js": "^14.9.0",
|
||||
"fero-ms": "^2.0.7",
|
||||
"ms": "^2.1.3",
|
||||
"quickdb": "1.0.5",
|
||||
"quickmongo": "4.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"nodemon": "^2.0.20"
|
||||
"nodemon": "^2.0.22"
|
||||
}
|
||||
}
|
1060
pnpm-lock.yaml
Normal file
1060
pnpm-lock.yaml
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue