|
1 | | -require ('dotenv').config() |
2 | | -const Discord = require('discord.js'); |
3 | | -const { readdirSync } = require("fs"); |
4 | | -const handleEvents = require("./events"); |
5 | | - |
6 | | -const config = process.env; |
7 | | -const bot = new Discord.Client({disableEveryone: true}); |
8 | | - |
9 | | -handleEvents(bot); |
10 | | - |
11 | | -bot.commands = new Discord.Collection(); |
12 | | -bot.aliases = new Discord.Collection(); |
13 | | - |
14 | | -try |
15 | | -{ |
16 | | - let files = readdirSync("./commands/"); |
17 | | - let jsfiles = files.filter(f => f.split(".").pop() === "js") |
18 | | - if(jsfiles.length <= 0) { |
19 | | - return console.log("[LOGS] Couldn't Find Commands!"); |
20 | | - } |
21 | | - |
22 | | - jsfiles.forEach(f => { |
23 | | - let pull = require(`./commands/${f}`); |
24 | | - bot.commands.set(pull.config.name, pull); |
25 | | - pull.config.aliases.forEach(alias => { |
26 | | - bot.aliases.set(alias, pull.config.name) |
27 | | - }); |
28 | | - }); |
29 | | - |
30 | | - bot.on("message", message => { |
31 | | - if(message.author.bot || message.channel.type === "dm") return; |
32 | | - |
33 | | - let { content } = message; |
34 | | - let { prefix } = config; |
35 | | - if(!content.startsWith(prefix)) return; |
36 | | - |
37 | | - let [ cmd, args ] = content.split(/\s(.+)/); |
38 | | - cmd = cmd.slice(prefix.length); |
39 | | - |
40 | | - let commandfile = bot.commands.get(cmd) || bot.commands.get(bot.aliases.get(cmd)) |
41 | | - if(commandfile) commandfile.run(bot, message, args) |
42 | | - }) |
43 | | - |
44 | | - bot.login(process.env.TOKEN); |
45 | | -} |
46 | | -catch(error) |
47 | | -{ |
48 | | - console.log("Cannot load command files"); |
49 | | - console.log(error); |
50 | | -} |
| 1 | +require("dotenv").config(); |
| 2 | +const config = require("./config/config.json"); |
| 3 | +const Enmap = require("enmap"); |
| 4 | +const Discord = require("discord.js"); |
| 5 | + |
| 6 | +const client = new Discord.Client({ |
| 7 | + partials: ["MESSAGE", "USER", "REACTION"], |
| 8 | + disableMentions: "everyone" |
| 9 | +}); |
| 10 | +const DisTube = require("distube"); |
| 11 | + |
| 12 | +client.config = config; |
| 13 | +global.client = client; |
| 14 | +client.login(process.env.TOKEN); |
| 15 | +global.nowyear = new Date().getFullYear(); |
| 16 | +global.emojis = require("./config/emoji.json"); |
| 17 | + |
| 18 | +const db = require("quick.db"); |
| 19 | +const { GiveawaysManager } = require("discord-giveaways"); |
| 20 | + |
| 21 | +const nz_date_string = new Date().toLocaleString("en-US", { |
| 22 | + timeZone: "Asia/Hong_Kong" |
| 23 | +}); |
| 24 | + |
| 25 | +client.commands = new Discord.Collection(); |
| 26 | +client.slcommands = new Discord.Collection(); |
| 27 | +client.aliases = new Discord.Collection(); |
| 28 | +client.emotes = emojis; |
| 29 | +client.colors = client.config.colors; |
| 30 | +client.snipes = new Map(); |
| 31 | +client.mapss = new Map(); |
| 32 | +client.mapss.set("uptimedate", nz_date_string); |
| 33 | + |
| 34 | +["command", "event", "music"].forEach(x => |
| 35 | + require(`./handlers/${x}.js`)(client) |
| 36 | +); |
| 37 | +["alwaysOn", "http"].forEach(x => require(`./server/${x}`)()); |
| 38 | + |
| 39 | +client.settings = new Enmap({ |
| 40 | + name: "settings", |
| 41 | + fetchAll: false, |
| 42 | + autoFetch: true, |
| 43 | + cloneLevel: "deep" |
| 44 | +}); |
| 45 | + |
| 46 | +client.moderationdb = new Enmap("moderation"); |
| 47 | + |
| 48 | +client.distube = new DisTube(client, { |
| 49 | + leaveOnFinish: true, |
| 50 | + leaveOnEmpty: true, |
| 51 | + leaveOnStop: true, |
| 52 | + youtubeDL: true, |
| 53 | + updateYouTubeDL: true, |
| 54 | + youtubeCookie: |
| 55 | + "GPS=1; YSC=w5dGoHzqQRI; VISITOR_INFO1_LIVE=B4ElBqxSDv4; PREF=tz=Asia.Hong_Kong" |
| 56 | +}); |
| 57 | + |
| 58 | +if (!db.get("giveaways")) db.set("giveaways", []); |
| 59 | + |
| 60 | +const GiveawayManagerWithOwnDatabase = class extends GiveawaysManager { |
| 61 | + async getAllGiveaways() { |
| 62 | + return db.get("giveaways"); |
| 63 | + } |
| 64 | + |
| 65 | + async saveGiveaway(messageID, giveawayData) { |
| 66 | + db.push("giveaways", giveawayData); |
| 67 | + return true; |
| 68 | + } |
| 69 | + |
| 70 | + async editGiveaway(messageID, giveawayData) { |
| 71 | + const giveaways = db.get("giveaways"); |
| 72 | + const newGiveawaysArray = giveaways.filter( |
| 73 | + giveaway => giveaway.messageID !== messageID |
| 74 | + ); |
| 75 | + newGiveawaysArray.push(giveawayData); |
| 76 | + db.set("giveaways", newGiveawaysArray); |
| 77 | + return true; |
| 78 | + } |
| 79 | + |
| 80 | + async deleteGiveaway(messageID) { |
| 81 | + const newGiveawaysArray = db |
| 82 | + .get("giveaways") |
| 83 | + .filter(giveaway => giveaway.messageID !== messageID); |
| 84 | + db.set("giveaways", newGiveawaysArray); |
| 85 | + return true; |
| 86 | + } |
| 87 | +}; |
| 88 | + |
| 89 | +client.giveawaysManager = new GiveawayManagerWithOwnDatabase(client, { |
| 90 | + storage: false, |
| 91 | + updateCountdownEvery: 10000, |
| 92 | + endedGiveawaysLifetime: 30000, |
| 93 | + hasGuildMembersIntent: false, |
| 94 | + default: { |
| 95 | + botsCanWin: false, |
| 96 | + exemptPermissions: ["MANAGE_MESSAGES", "ADMINISTRATOR"], |
| 97 | + embedColor: "#ff6969", |
| 98 | + embedColorEnd: "#505050", |
| 99 | + reaction: "🎉" |
| 100 | + } |
| 101 | +}); |
| 102 | + |
| 103 | +client.status = queue => |
| 104 | + `Volume: \`${queue.volume}%\` | Filter: \`${ |
| 105 | + queue.filter || "Off" |
| 106 | + }\` | Loop: \`${ |
| 107 | + queue.repeatMode |
| 108 | + ? queue.repeatMode == 2 |
| 109 | + ? "All Queue" |
| 110 | + : "This Song" |
| 111 | + : "Off" |
| 112 | + }\` | Autoplay: \`${queue.autoplay ? "On" : "Off"}\``; |
| 113 | + |
| 114 | +client.ws.on("INTERACTION_CREATE", async interaction => { |
| 115 | + if (!client.slcommands.has(interaction.data.name)) return; |
| 116 | + try { |
| 117 | + client.slcommands.get(interaction.data.name).execute(interaction); |
| 118 | + } catch (error) { |
| 119 | + console.log( |
| 120 | + `Error from command ${interaction.data.name} : ${error.message}` |
| 121 | + ); |
| 122 | + console.log(`${error.stack}\n`); |
| 123 | + client.api.interactions(interaction.id, interaction.token).callback.post({ |
| 124 | + data: { |
| 125 | + type: 4, |
| 126 | + data: { |
| 127 | + content: "Sorry, error occurred when running this command!" |
| 128 | + } |
| 129 | + } |
| 130 | + }); |
| 131 | + } |
| 132 | +}); |
0 commit comments