· 7 years ago · Jan 25, 2019, 03:44 AM
1const express = require('express')
2 ,colors = require('colors')
3 ,robloxInterpeter = require('noblox.js')
4
5const expressServer = express()
6
7const {
8 COOKIE
9 ,GROUP_ID
10 ,SECRET_KEY = '__PUBLIC__'
11 ,PORT = 3000
12} = process.env
13
14const promotionCooldown = {}
15
16async function promoteUser(req, res) {
17
18 try {
19 let { params: { userId } } = req
20
21 userId = parseInt(userId < 1 ? false : userId, 10)
22
23 if (isNaN(userId)) throw { code: 0, message: `Invalid argument(s) given: ${req.params.userId}`}
24 else {
25 if (promotionCooldown[userId]) {
26 throw { code: 1, message: `User ${userId} was already recently promoted.` }
27 } else {
28 promotionCooldown[userId] = true
29 setTimeout(() => delete promotionCooldown[userId], 1000 * 60)
30 }
31 const { newRole, oldRole } = await robloxInterpeter.promote(GROUP_ID, userId)
32 console.log(`Promoted User ${userId}`)
33 res.status(200).json({
34 success: true,
35 message: `Promoted User ${userId} from ${oldRole.Name} (${oldRole.Rank}) to ${newRole.Name} (${newRole.Rank})`
36 ,oldRank: oldRole
37 ,newRank: newRole
38 })
39 }
40 } catch({ message }) {
41 console.error(message)
42 res.status(400).json({
43 success: false
44 ,message
45 })
46 }
47
48}
49
50expressServer.get(`/promoteUser/${SECRET_KEY}/:userId`, promoteUser)
51
52async function setupServer() {
53 try {
54
55 let parsedCookie = COOKIE.startsWith('_|WARNING:-DO-NOT-SHARE-THIS.--Sharing-this-will-allow-someone-to-log-in-as-you-and-to-steal-your-ROBUX-and-items.|_') ? COOKIE : '_|WARNING:-DO-NOT-SHARE-THIS.--Sharing-this-will-allow-someone-to-log-in-as-you-and-to-steal-your-ROBUX-and-items.|_' + COOKIE
56 await robloxInterpeter.cookieLogin(parsedCookie)
57
58 console.log(`Connected to the ${colors.underline(colors.red('Roblox API'))}!`)
59
60 await new Promise((resolve, reject) => {
61 expressServer.get('/ping', (_, res) => res.status(200).json({ success: true }))
62 expressServer.all('*', (_, res) => res.sendStatus(403))
63 expressServer.listen(PORT, e => {
64 if (e) {
65 reject(e)
66 } else {
67 resolve(true)
68 }
69 })
70 })
71
72 console.log(`${colors.underline(colors.green('Successfully'))} started express server on port ${colors.underline(colors.blue(PORT))}!`)
73
74 } catch(e) {
75 console.error(colors.red(e))
76 }
77}
78
79//console.log(`Setting up server with configuration:\nPort: ${colors.bold(colors.blue(PORT))}\nGroup Id: ${colors.bold(colors.blue(GROUP_ID))}\nCookie: ${colors.bold(colors.yellow(COOKIE))}`)
80setupServer()