-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
115 lines (80 loc) · 3.1 KB
/
server.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
require('dotenv').config({path: "variables.env"})
require('isomorphic-fetch');
const fs = require("fs");
let modules = JSON.parse(fs.readFileSync('lib/modules.json', 'utf8'));
let botConfig = JSON.parse(fs.readFileSync('config.json', 'utf8'));
let moduleHolder = [[], []]
for (const [ key, value ] of Object.entries(modules)) {
moduleHolder[value["name"]] = require("./lib/" + value["name"] + ".js")
}
const prefix = botConfig["prefix"]
const Discord = require("discord.js");
const client = new Discord.Client();
const firebase = require("firebase")
const http = require('http').createServer().listen(3000)
String.prototype.replaceAll = function(search, replacement) {
var target = this;
return target.replace(new RegExp(search, 'g'), replacement);
};
String.prototype.insert = function (index, string) {
if (index > 0)
return this.substring(0, index) + string + this.substring(index, this.length);
else
return string + this;
};
function getRndInteger(min, max) {
return Math.floor(Math.random() * (max - min) ) + min;
}
/*Firebase*/
const config = {
apiKey: process.env.FIREBASE_APIKEY, //process.env.FIREBASE_APIKEY
authDomain: process.env.FIREBASE_AUTHDOMAIN, //process.env.FIREBASE_AUTHDOMAIN
databaseURL: process.env.FIREBASE_DATABASEURL, //process.env.FIREBASE_DATABASEURL
storageBucket: process.env.FIREBASE_STORAGEBUCKET //process.env.FIREBASE_STORAGEBUCKET
};
firebase.initializeApp(config);
firebase.auth().signInWithEmailAndPassword(process.env.FIREBASE_INTERNALEMAIL, process.env.FIREBASE_INTERNALPASSWORD).then(function(user){
function save(path, payload, callback){
firebase.database().ref(path).set(payload, function(e){
if (e){
return callback(false);
}else{
return callback(true);
}
});
}
function load(path, callback){
firebase.database().ref(path).once('value').then(function(snapshot) {
return callback(snapshot.val())
// ...
});
}
/*=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
DISCORD FUNCTIONS
=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=*/
client.on("ready", function(){
console.log(`Logged in as ${client.user.tag}`)
client.user.setPresence({ status: 'online', game: { name: '.help to get started' } });
});
client.on("message", async function(message){
if (message.author.id != client.user.id){
if(message.content.startsWith(prefix)){
let command = message.content.replace(prefix, "").split(" ")
let command2 = message.content.replace(prefix, "").split(" ")
if (modules[command[0]]["commands"].includes(command[1]) || modules[command[0]]["commands"][0] == "*"){
if (!(modules[command[0]]["commands"][0] === "*")){
command.splice(0, 2)
moduleHolder[command2[0]].main(command.join(" "), command2[1], message)
}else{
if ((command[0]) == "help"){
command.shift()
moduleHolder[command2[0]].main(command.join(" "), command2[0], message, prefix)
}
}
}
}
}
});
});
client.login(process.env.BOT_TOKEN)
//Discord Events