This repository has been archived by the owner on Oct 25, 2023. It is now read-only.
forked from BloxTechGroup/RocketBots
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
140 lines (135 loc) · 5.45 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
const fetch = require('node-fetch');
const api = "https://roblox-rocketapps.bloxtech.tech/roblox/bots";
function request(url, method, headers, body) {
return new Promise(function (resolve, reject) {
if (method == "GET") {
fetch(url, {
method: method,
headers: headers,
credentials: "include"
}).then(async response => {
if (response.status == 500) {
reject("Internal server error.");
} else {
response.json().then(data => {
resolve(data);
})
}
})
} else {
fetch(url, {
method: method,
headers: headers,
body: body,
credentials: "include"
}).then(async response => {
if (response.status == 500) {
setTimeout(function () {
if (retries <= 15) {
request(url, method, headers, body, cb, retries + 1)
}
}, 1000)
} else {
response.json().then(data => {
resolve(data);
})
}
})
}
});
}
function GetRank(uid, gid) {
if (typeof uid !== 'number') {
reject(`Group id should not be a string`)
}
return new Promise(function (resolve, reject) {
fetch(`https://groups.roblox.com/v2/users/${uid}/groups/roles`, {
method: "GET",
headers: {
'Content-Type': 'application/json'
},
credentials: "include"
}).then(async response => {
response.json().then(data => {
const error = data.errors && data.errors[0];
if (error) {
if (error.code === 3) {
reject("Invaild userid");
}
}
}
const rank = data.data.find((info) => gid === info.group.id);
resolve(rank.role.rank);
})
})
});
}
class RocketBot {
constructor(teamId) {
this.teamId = teamId;
}
async info() {
const response = await request(`${api}/${this.teamId}`, 'GET', {}, {});
return (response.success ? response.response : { success: false, reason: response.reason });
}
async getJoinRequests() {
const response = await request(`${api}/${this.teamId}/getjoinrequests`, 'GET', {}, {});
return (response.success ? response.response : { success: false, reason: response.reason });
}
async promote(userid, groupid) {
const rank = await GetRank(userid, groupid);
const response = await request(`${api}/${this.teamId}/rankingroup`, "POST", { "Content-Type": "application/json" }, JSON.stringify({
userId: userid,
rankId: rank + 1
}));
return (response.success ? response.response : { success: false, reason: response.reason });
}
async demote(userid, groupid) {
const rank = await GetRank(userid, groupid);
const response = await request(`${api}/${this.teamId}/rankingroup`, "POST", { "Content-Type": "application/json" }, JSON.stringify({
userId: userid,
rankId: rank - 1
}));
return (response.success ? response.response : { success: false, reason: response.reason });
}
async shout(message) {
const response = await request(`${api}/${this.teamId}/shout`, "POST", { "Content-Type": "application/json" }, JSON.stringify({
msg: message
}));
return (response.success ? response : { success: false, reason: response.reason });
}
async messageUser(userId, subject, message) {
const response = await request(`${api}/${this.teamId}/messageuser`, "POST", { "Content-Type": "application/json" }, JSON.stringify({
userId: userId,
subject: subject,
message: message
}));
return (response.success ? response : { success: false, reason: response.reason });
}
async approveJoinRequest(userId) {
const response = await request(`${api}/${this.teamId}/approvejoinrequest`, "POST", { "Content-Type": "application/json" }, JSON.stringify({
userId: userId,
}));
return (response.success ? response : { success: false, reason: response.reason });
}
async declineJoinRequest(userId) {
const response = await request(`${api}/${this.teamId}/declinejoinrequest`, "POST", { "Content-Type": "application/json" }, JSON.stringify({
userId: userId,
}));
return (response.success ? response : { success: false, reason: response.reason });
}
async rankInGroup(userId, rankId) {
const response = await request(`${api}/${this.teamId}/rankingroup`, "POST", { "Content-Type": "application/json" }, JSON.stringify({
userId: userId,
rankId: rankId
}));
return (response.success ? response : { success: false, reason: response.reason });
}
async exile(userId) {
const response = await request(`${api}/${this.teamId}/exile`, "POST", { "Content-Type": "application/json" }, JSON.stringify({
userId: userId,
}));
return (response.success ? response : { success: false, reason: response.reason });
}
}
module.exports = RocketBot