-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
218 lines (192 loc) · 5.96 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
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
const Discord = require("discord.js");
const fs = require("fs");
const mongoose = require("mongoose");
const express = require("express");
const compression = require("compression");
const bodyParser = require("body-parser");
const config = require("./config");
const dblVotes = require("./models/dblvotes");
const Users = require("./models/users");
const DblVotes = require("./models/dblvotes");
const app = express();
const port = 3020;
const client = new Discord.Client({ disableEveryone: true });
mongoose.connect(config.mongodb, {
useNewUrlParser: true,
useUnifiedTopology: true
});
client.login(config.token);
client.commands = new Discord.Collection();
client.aliases = new Discord.Collection();
client.perms = new Discord.Collection();
client.limits = new Discord.Collection();
client.events = new Discord.Collection();
client.restrictions = new Discord.Collection();
client.clean = async (client, text) => {
if (text && text.constructor.name == "Promise") text = await text;
if (typeof evaled !== "string") text = require("util").inspect(text, { depth: 0 });
text = text.replace(/`/g, "`" + String.fromCharCode(8203))
.replace(/@/g, "@" + String.fromCharCode(8203))
.replace(client.token, "Unauthorized action");
return text;
};
client.throw = async (message, errorType, errorMessage) => {
let embed = new Discord.MessageEmbed()
.setTitle(`${config.emojis.error} ${errorType}`)
.setDescription(errorMessage)
.setColor("RED")
.setTimestamp();
message.channel.send(embed);
};
client.activeUser = [];
client.save = async () => {
await client.activeUser.forEach(async (mUser) => {
let dblvote = dblVotes.findOne({
id: mUser.id
});
let user = Users.findOne({
id: mUser.id
});
let messages = mUser.messages;
if (user && user.drepPlus && user.drepPlus.active) {
messages *= 2;
}
if (dblvote && dblvote.lastVote + 43200000 > Date.now()) {
messages *= 2;
}
mUser.messages = messages;
if (mUser.messages >= 99766) {
mUser.reputation = 22; //Grand Champion
}
else if (mUser.messages >= 84461) {
mUser.reputation = 21 //Champion 3
}
else if (mUser.messages >= 75469) {
mUser.reputation = 20 //Champion 2
}
else if (mUser.messages >= 68424) {
mUser.reputation = 19 //Champion 1
}
else if (mUser.messages >= 59007) {
mUser.reputation = 18 //Diamond 3
}
else if (mUser.messages >= 54649) {
mUser.reputation = 17 //Diamond 2
}
else if (mUser.messages >= 48406) {
mUser.reputation = 16 //Diamond 1
}
else if (mUser.messages >= 42442) {
mUser.reputation = 15 //Titan 3
}
else if (mUser.messages >= 38271) {
mUser.reputation = 14 //Titan 2
}
else if (mUser.messages >= 34529) {
mUser.reputation = 13 //Titan 1
}
else if (mUser.messages >= 29128) {
mUser.reputation = 12 //Platinum 3
}
else if (mUser.messages >= 25073) {
mUser.reputation = 11 //Platinum 2
}
else if (mUser.messages >= 21794) {
mUser.reputation = 10 //Platinum 1
}
else if (mUser.messages >= 17948) {
mUser.reputation = 9 //Gold 3
}
else if (mUser.messages >= 15592) {
mUser.reputation = 8 //Gold 2
}
else if (mUser.messages >= 12421) {
mUser.reputation = 7 //Gold 1
}
else if (mUser.message >= 9619) {
mUser.reputation = 6 //Silver 3
}
else if (mUser.message >= 8029) {
mUser.reputation = 5 //Silver 2
}
else if (mUser.messages >= 4118) {
mUser.reputation = 4 //Silver 1
}
else if (mUser.message >= 2588) {
mUser.reputation = 3 //Bronze 3
}
else if (mUser.message >= 1660) {
mUser.reputation = 2 //Bronze 2
}
else if (mUser.messages >= 1045) {
mUser.reputation = 1 //Bronze 1
}
await mUser.save().catch(e => console.log(e));
});
client.activeUser = [];
}
setInterval(() => {
client.save()
}, 300000)
fs.readdir(__dirname + "/commands/", (err, files) => {
if (err) return console.log(err);
files.forEach(file => {
if (!file.endsWith(".js")) return;
let props = require(`./commands/${file}`);
let commandName = file.split(".")[0];
client.commands.set(commandName, props);
if (props.help.aliases) {
props.help.aliases.forEach(alias => client.aliases.set(alias, commandName));
};
});
});
fs.readdir(__dirname + '/events/', (err, files) => {
if (err) console.log(err);
files.forEach(file => {
let eventFunc = require(`./events/${file}`);
let eventName = file.split(".")[0];
client.on(eventName, (...args) => eventFunc.run(client, ...args));
});
});
app.use(compression());
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.get("/", (req, res) => {
res.send("It's working.");
});
//Upvoting on DiscordBots.org
app.use('/hook', async (req, res) => {
//if (req.headers.authorization != config.webhookAuth) return res.send({code: "invalid auth"});
console.log(1)
var user_id = req.body.user;
var bot = req.body.bot;
let vote = await DblVotes.findOne({ id: user_id });
if (vote) {
await DblVotes.findOne({ id: user_id }, async (err, avote) => {
avote.lastVote = Date.now();
avote.totalVotes += 1;
await avote.save().catch(e => console.log(e));
});
} else {
let newvote = new DblVotes({
id: user_id,
lastVote: Date.now(),
totalVotes: 1
});
await newvote.save().catch(e => console.log(e));
}
console.log(req.body)
let user = await client.users.fetch(user_id);
try {
if (!vote) {
return user.send("Thanks for voting to Reputation Bot, as a reward, you will receive " + config.emojis.success + " **'VERIFIED'** badge on your profile for 24 hours, and 2X XP boost for 12 hours.")
}
} catch (e) {
console.log(e);
}
res.status(200).send("ok");
});
app.listen(port, () => console.log(`Webhook listening on port ${port}!`))
module.exports = client