forked from Furtsy/firebase-uptime-bot
-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
163 lines (143 loc) · 4.38 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
const Discord = require("discord.js");
const client = new Discord.Client();
const chalk = require("chalk");
const fs = require("fs");
const moment = require("moment");
require('dotenv/config');
const firebase = require('firebase/app');
const FieldValue = require('firebase-admin').firestore.FieldValue;
const admin = require('firebase-admin');
const service = require('./service.json'); //firebase service json
admin.initializeApp({
credential: admin.credential.cert(service)
});
const fetch = require("node-fetch");
const data = admin.firestore();
client.conf = {
"token": "TOKEN ",
"pref": "!",
"own": "id",
"play": "uptime play",
"status": "dnd"
}
//uptime
client.on("ready", async () => {
setInterval( async() => {
const links = data.collection('links');
const link_get = await links.get();
link_get.forEach(doc => {
var linkA = doc.data().link
try {
fetch(linkA)
} catch(e) { console.log("" + e) };
});
}, 5000)
})
//uptime
client.on("message", message => {
let client = message.client;
if (message.author.bot) return;
if (!message.content.startsWith(client.conf.pref)) return;
let command = message.content.split(" ")[0].slice(client.conf.pref.length);
let params = message.content.split(" ").slice(1);
let perms = client.yetkiler(message);
let cmd;
if (client.commands.has(command)) {
cmd = client.commands.get(command);
} else if (client.aliases.has(command)) {
cmd = client.commands.get(client.aliases.get(command));
}
if (cmd) {
if (perms < cmd.conf.permLevel) return;
cmd.run(client, message, params, perms);
}
})
client.on("ready", () => {
console.log(`All commands loaded, bot is running ...`);
console.log(`Discord account has been activated with ${client.user.username}!`);
client.user.setStatus(client.conf.status);
client.user.setActivity(client.conf.play);
console.log(`Oynuyor ayarlandı!`);
})
var prefix = client.conf.prefix;
const log = message => {
console.log(`${message}`);
};
client.commands = new Discord.Collection();
client.aliases = new Discord.Collection();
fs.readdir("./cmds/", (err, files) => {
if (err) console.error(err);
log(`${files.length} adet komut yüklenmeye hazır. Başlatılıyor...`);
files.forEach(f => {
let props = require(`./cmds/${f}`);
log(`Komut yükleniyor: ${props.help.name}'.`);
client.commands.set(props.help.name, props);
props.conf.aliases.forEach(alias => {
client.aliases.set(alias, props.help.name);
});
});
});
client.reload = command => {
return new Promise((resolve, reject) => {
try {
delete require.cache[require.resolve(`./cmds/${command}`)];
let cmd = require(`./cmds/${command}`);
client.commands.delete(command);
client.aliases.forEach((cmd, alias) => {
if (cmd === command) client.aliases.delete(alias);
});
client.commands.set(command, cmd);
cmd.conf.aliases.forEach(alias => {
client.aliases.set(alias, cmd.help.name);
});
resolve();
} catch (e) {
reject(e);
}
});
};
client.load = command => {
return new Promise((resolve, reject) => {
try {
let cmd = require(`./cmds/${command}`);
client.commands.set(command, cmd);
cmd.conf.aliases.forEach(alias => {
client.aliases.set(alias, cmd.help.name);
});
resolve();
} catch (e) {
reject(e);
}
});
};
client.unload = command => {
return new Promise((resolve, reject) => {
try {
delete require.cache[require.resolve(`./cmds/${command}`)];
let cmd = require(`./cmds/${command}`);
client.commands.delete(command);
client.aliases.forEach((cmd, alias) => {
if (cmd === command) client.aliases.delete(alias);
});
resolve();
} catch (e) {
reject(e);
}
});
};
client.yetkiler = message => {
if (!message.guild) {
return;
}
let permlvl = 0;
if(message.member.hasPermission("MANAGE_MESSAGES")) permlvl = 1;
if(message.member.hasPermission("MANAGE_ROLES")) permlvl = 2;
if(message.member.hasPermission("MANAGE_CHANNELS")) permlvl = 3;
if(message.member.hasPermission("KICK_MEMBERS")) permlvl = 4;
if(message.member.hasPermission("BAN_MEMBERS")) permlvl = 5;
if(message.member.hasPermission("ADMINISTRATOR")) permlvl = 6;
if(message.author.id === message.guild.ownerID) permlvl = 7;
if(message.author.id === client.conf.own) permlvl = 8;
return permlvl;
};
client.login(client.conf.token)