forked from scribblehounts/vortex_scribble
-
Notifications
You must be signed in to change notification settings - Fork 0
/
routes.js
420 lines (358 loc) · 11.6 KB
/
routes.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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
const roblox = require('noblox.js')
const fs = require("fs")
const editJsonFile = require('edit-json-file')
const express = require('express')
var randomString = function (len, bits)
{
bits = bits || 36;
var outStr = "", newStr;
while (outStr.length < len)
{
newStr = Math.random().toString(bits).slice(2);
outStr += newStr.slice(0, Math.min(newStr.length, (len - outStr.length)));
}
return outStr.toLowerCase();
};
var getAuthorized = function(req,res){
if (req.headers.secretcode === "quackielquackaeckfjdskfsdfndaskfndfdnfkfds"){
console.log("authorized access http;")
return true
} else {
console.log("unauthorized access http;")
res.status(403).json({
error: "You do not have permission to use this."
})
return false
}
}
var routes = function(app, db, discord) {
/*app.get("/", function(req, res) {
console.log("Received GET");
});*/
var checkBlacklisted = function(x){
var docRef = db.collection("users").doc(x);
docRef.get().then(function(doc) {
if (doc.data().blacklisted) {
console.log("blacklisted")
return true
} else {
console.log("not blacklisted")
return false
}
})
}
app.get("/products", (req,res) => {
let file = editJsonFile('./products.json').read()
res.send(file)
});
app.post("/update", function(req, res) {
if (!req.body.username || !req.body.data) {
console.log("Received incomplete POST: " + JSON.stringify(req.body));
return res.send({ status: "error", message: "missing parameter(s)" });
} else {
console.log("Received POST: " + JSON.stringify(req.body));
return res.send(req.body);
}
});
app.get("/checkproduct", function(req, res) {
if (!getAuthorized(req,res) === true){return}
if (req.query.id && req.query.product){
var user = req.query.id;
if (checkBlacklisted(user) == true){return}
var docRef = db.collection("users").doc(user);
docRef.get().then(function(doc) {
if (doc.data()[req.query.product]) {
return res.send({ success: "true" })
} else {
return res.send({ errormessage: "yes" })
}
})
}
});
app.get("/getproducts", function(req, res) {
if (!getAuthorized(req,res) === true){return}
if (req.query.id){
db.collection("users").doc(req.query.id).get().then(querySnapShot => {
if (querySnapShot.empty){
return res.send("invalid");
}
var data = querySnapShot.data();
delete data['discord']
delete data['SPECIAL']
delete data['boostednitro']
var products = []
for (var i in data) {
let file = editJsonFile('./products.json')
var item = file.get(i)
products.push(item.name)
}
return res.send(products)
})
}
});
app.get("/checkuser", function(req, res) {
if (!getAuthorized(req,res) === true){return}
if (req.query.id){
var user = req.query.id;
if (checkBlacklisted(user) == true){return}
var docRef = db.collection("users").doc(user);
docRef.get().then(function(doc) {
if (doc.data().ife) {
return res.send({ success: "true" })
} else {
return res.send({ errormessage: "yes" })
}
})
}
});
app.get("/checkverified", function(req, res) {
if (!getAuthorized(req,res) === true){return}
if (req.query.id){
var user = req.query.id;
var docRef = db.collection("users").doc(user);
docRef.get().then(function(doc) {
if (doc.exists && doc.data().discord){
return res.send({ success: "true" })
} else {
return res.send({ errormessage: "yes" })
}
})
}
});
app.get("/checkpromo", function(req, res) {
if (!getAuthorized(req,res) === true){return}
if (req.query.id){
var user = req.query.id;
var docRef = db.collection("promocodes").doc(user);
docRef.get().then(function(doc) {
if (doc.exists){
return res.send({ success: doc.data()})
} else {
return res.send({ errormessage: "no promo code found" })
}
})
}
});
app.get("/checkperms", function(req,res){
if (req.query.plr){
var doc = db.collection("users").doc(req.query.plr);
doc.get().then(function(doc){
if (doc.data().SPECIAL){
return res.send({ success: doc.data().SPECIAL})
} else {
return res.send({ success: "indiviual"})
}
})
}
})
app.get("/checkimmigration", function(req, res) {
if (!getAuthorized(req,res) === true){return}
if (req.query.id){
var user = req.query.id;
if (checkBlacklisted(user) == true){return}
var docRef = db.collection("users").doc(user);
docRef.get().then(function(doc) {
if (doc.data().immigration) {
return res.send({ success: "true" })
} else {
return res.send({ errormessage: "yes" })
}
})
}
});
app.get("/checkbagdrop", function(req, res) {
if (!getAuthorized(req,res) === true){return}
if (req.query.id){
var user = req.query.id;
if (checkBlacklisted(user) == true){return}
var docRef = db.collection("users").doc(user);
docRef.get().then(function(doc) {
if (doc.data().bagdrop) {
return res.send({ success: "true" })
} else {
return res.send({ errormessage: "yes" })
}
})
}
});
app.get("/checkstaffpanel", function(req, res) {
if (!getAuthorized(req,res) === true){return}
if (req.query.id){
var user = req.query.id;
if (checkBlacklisted(user) == true){return}
var docRef = db.collection("users").doc(user);
docRef.get().then(function(doc) {
if (doc.data().staffpanel) {
return res.send({ success: "true" })
} else {
return res.send({ errormessage: "yes" })
}
})
}
});
app.get("/verify", function(req, res) {
if (!getAuthorized(req,res) === true){return}
if (req.query.id){
var user = req.query.id;
var docRef = db.collection("verification").doc(user);
docRef.get().then(function(doc) {
if (doc.exists) {
return res.send({ code: `${doc.get("Code")}` })
} else {
var code = randomString(4)
db.collection('verification').doc(user).set({
RBLX: user,
Code: code
})
.then(function(){
console.log("created")
res.send({code: code})
});
setTimeout(function(){
db.collection('verification').doc(user).delete()
},900000);
}
})
}
});
app.get("/check", function(req, res) {
var user = req.query.id;
if (req.query.id){
db.collection('users').where('RBLX','==',user).get().then(exist => {
if (exist.empty){
console.log("empty")
return res.send({ errormessage: "yes" });
} else {
console.log("true")
return res.send({ success: "true" })
}
})
}
});
app.get("/rating", function(req, res) {
//if (!getAuthorized(req,res) === true){return}
if (req.query.rating){
var user = req.query.user
res.send({ success: "true" })
roblox.getUsernameFromId(user).then(a => {
roblox.getPlayerInfo(user).then(function(info) {
discord.channels.cache.get("674502197769404427").send({embed: {
color: 3447003,
author: {
name: info.username,
icon_url: (`https://www.roblox.com/bust-thumbnail/image?userId=${user}&width=420&height=420&format=png`)
},
title: user,
fields: [{
name: "Ratings",
value: req.query.rating + " out of 100"
}
],
timestamp: new Date(),
footer: {
text: "Vortex Purchasing"
}
}})
})
})
}
});
app.get("/addproduct", function(req, res) {
if (!getAuthorized(req,res) === true){return}
if (req.query.id){
var data = req.query.data
var user = req.query.id;
var docRef = db.collection("users").doc(user);
if (data) {
docRef.get().then(function(doc) {
if (doc.exists) {
let file = editJsonFile('./products.json')
var item = file.get(req.query.data)
console.log("1?")
console.log("the product is called " + item.name + " its price is " + item.price)
discord.users.cache.get(doc.data().discord).send({embed: {
title:("Purchase Received!"),
description: ("Thank you for purchasing the " + item.name + " you have automatically been roled to " + item.role),
fields:[{
name: "Model:",
value: `You can get the Model by clicking on this [link](${item.model}) Make sure to read the README inside it and if you have any questions, create a support ticket in #commands by doing, !support [ reason ]`,
}]
}});
if (item.setup){
discord.users.cache.get(doc.data().discord).send({embed: {
fields: [{
name: "Setup Video:",
value: `There is a setup video available for this product! To watch it press this [link](${item.setup})`
}]
}});
}
let myGuild = discord.guilds.cache.get('670903593737519104');
let member = myGuild.members.cache.get(doc.data().discord)
member.roles.add(myGuild.roles.cache.find(role => role.name === item.role));
var obj = {}
obj[item.id] = "owned"
db.collection('users').doc(`${req.query.id}`).set(obj,{merge: true});
res.send({ success: "true" })
roblox.getUsernameFromId(user).then(a => {
roblox.getPlayerInfo(user).then(function(info) {
discord.channels.cache.get("693274563961815060").send({embed: {
color: 3447003,
author: {
name: info.username,
icon_url: (`https://www.roblox.com/bust-thumbnail/image?userId=${user}&width=420&height=420&format=png`)
},
title: user,
fields: [{
name: "Purchase Received",
value: "Product: " + item.name
}
],
timestamp: new Date(),
footer: {
text: "Vortex Purchasing"
}
}})
})
})
}
})
};
}
});
app.post("/generatedevproduct",(req,res) => {
if (!getAuthorized(req,res) === true){return}
const universeId = parseInt(req.body.universeId)
const name = req.body.name
const price = parseInt(req.body.price)
const args = {
universeId: universeId,
name: name,
priceInRobux: price
}
roblox.addDeveloperProduct(args).then(function(productDetails) {
productId = productDetails.productId
console.log("["+universeId+"] Created product "+name+" for "+price+" Robux.")
return res.status(200).json({
message: "["+universeId+"] Created product "+name+" for "+price+" Robux.",
productId: parseInt(productId)
})
}).catch(function(err) {
console.log("["+universeId+"] Failed to create product "+name+" for "+price+" Robux: "+err.message)
return res.status(400).json({
error: err.message
})
})
})
app.use(function (err, req, res, next) {
console.error(err.stack)
})
var settings = require('./settings.json')
function login () {
return roblox.cookieLogin(settings.cookie)
//return roblox.cookieLogin("_|WARNING:-DO-NOT-SHARE-THIS.--Sharing-this-will-allow-someone-to-log-in-as-you-and-to-steal-your-ROBUX-and-items.|_C15757DD13BF8B862C5B366014B504E01DAFBA36EF0927EFAD24B5F5D4363EB1898FE0611817ED5C0B4DAD67862B570FA7D64647D74F41CB552A8844F1480252DFA0DB38FA9A898EC753E7FCB01457B6D4677AB5D6C03DB43DBCBAC523FD94E1B035035AB710D770985CF8C2F36DA078BCD9BB2E31B50089D04DAE9A61525D9EAF6297934F809B6BF6E3D0B9A46FA8A57F9FC52C2999CF6C3EE39674C767448B7F139BBAFB2E570BE35321F838A4F3DE365F0961A93ACD36C8A82E478321F1058228B09B82CF410F1D320B156449CF1C1F482E0285D49ABA54CD42E04198ABC012E712C00EDE0DD5B304EFDCCE42C2BB37FE53E9666E0999022F3F6E9C4A959F1E5CFA47265354ABFB91C63E6C238F6F0BEEB296FD78068F3CFAF606DF0CB0BCD98AF774")
}
login().then(function () {
console.log("logged in")
})
};
module.exports = routes;