-
-
Notifications
You must be signed in to change notification settings - Fork 128
/
replit.js
76 lines (68 loc) · 2.82 KB
/
replit.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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);