-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.js
76 lines (64 loc) · 2.15 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
// Load in all packages and configuration files
const Discord = require("discord.js");
const Enmap = require("enmap");
const admin = require("firebase-admin");
const rblxFunctions = require("noblox.js");
const cron = require('node-cron');
const fs = require("fs");
var serviceAccount = require("./settings/serviceAccountKey.json");
const config = require("./settings/config.json");
// Setup so that you know if the bot is logged in. Mainly used to keep cookie validation running properly.
var loggedIn = false
// Set a variable for the bot (in this instance, client)
const client = new Discord.Client();
// Implement config to the client so the config is valid everywhere
client.config = config;
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: `${config.firebase_url}`
});
function rblx_login(){
rblxFunctions.setCookie(config.rblx_cookie).then(function() {
loggedIn = true
console.log("logged in");
})
.catch(function(error) {
console.log("There was an error when attempting to log in. " + error)
})
}
rblx_login();
// Events to be loaded in (message, memebrAdd, etc)
fs.readdir("./events/", (err, files) => {
files.forEach(file => {
const event = require(`./events/${file}`);
let eventName = file.split(".")[0];
client.on(eventName, event.bind(null, client));
});
});
// All valid commands
client.commands = new Enmap();
// Commands to be loaded in (ping, verify, etc)
fs.readdir("./commands/", (err, files) => {
files.forEach(file => {
if (!file.endsWith(".js")) return;
let props = require(`./commands/${file}`);
for (var e=0; e<props.info.names.length; e++) {
client.commands.set(props.info.names[e], props);
}
let commandName = file.split(".")[0];
console.log(`Loaded command: ${commandName}`)
});
});
// Client login
client.login(config.bot_token);
// Initiate Cookie Refresh checking
cron.schedule('* * 1 * *', () => {
if (loggedIn == true) {
loggedIn = false
rblxFunctions.refreshCookie().then(function(newCookie) {
config.rblx_cookie = newCookie
rblx_login();
console.log("Cookie refreshed, validated and relogged in.")
})
}
});