-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
95 lines (82 loc) · 3.02 KB
/
index.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
"use strict";
const Discord = require("discord.js");
const localConfig = require("./config.json");
// eslint-disable-next-line no-unused-vars
const env = require("dotenv").config();
const client = new Discord.Client();
const { Player } = require("discord-player");
client.player = new Player(client);
const firebase = require("firebase");
const fs = require("fs");
// const tmi = require("tmi.js");
const Enmap = require("enmap");
const firebaseConfig = {
apiKey: process.env.apiKey,
authDomain: process.env.authDomain,
databaseURL: process.env.databaseURL,
projectId: process.env.projectId,
storageBucket: process.env.storageBucket,
messagingSenderId: process.env.messagingSenderId,
appId: process.env.appId,
measurementId: process.env.measurementId,
};
if (firebase.apps.length === 0) firebase.initializeApp(firebaseConfig);
client.config = localConfig;
client.logger = require("./modules/Logger");
client.player.on("trackStart", (message, track) => {
message.channel.send({
embed: {
color: "#8966FF",
author: { name: track.title },
fields: [
{ name: "Channel", value: track.author, inline: true },
{
name: "Requested by",
value: track.requestedBy.username,
inline: true,
},
{
name: "From playlist",
value: track.fromPlaylist ? "Yes" : "No",
inline: true,
},
{ name: "Views", value: track.views, inline: true },
{ name: "Duration", value: track.duration, inline: true },
],
thumbnail: { url: track.thumbnail },
timestamp: new Date(),
},
});
});
fs.readdir("./events/", (err, files) => {
if (err) return console.error(err);
files.forEach((file) => {
// If the file is not a JS file, ignore it (thanks, Apple)
if (!file.endsWith(".js")) return;
// Load the event file itself
const event = require(`./events/${file}`);
// Get just the event name from the file name
let eventName = file.split(".")[0];
// super-secret recipe to call events with all their proper arguments *after* the `client` var.
// without going into too many details, this means each event will be called with the client argument,
// followed by its "normal" arguments, like message, member, etc etc.
// This line is awesome by the way. Just sayin'.
client.on(eventName, event.bind(null, client));
delete require.cache[require.resolve(`./events/${file}`)];
});
});
client.commands = new Enmap();
fs.readdir("./commands/", (err, files) => {
if (err) return console.error(err);
files.forEach((file) => {
if (!file.endsWith(".js")) return;
// Load the command file itself
let props = require(`./commands/${file}`);
// Get just the command name from the file name
let commandName = file.split(".")[0];
client.logger.log(`Attempting to load command ${commandName}`);
// Here we simply store the whole thing in the command Enmap. We're not running it right now.
client.commands.set(commandName, props);
});
});
client.login(process.env.TOKEN);