-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
165 lines (138 loc) · 5.17 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
let https = require('axios').default
let key;
function sendError(err){
return {"error": true, "reason": err}
}
function sendSuccess(){
return {"error": false}
}
function request(path, trufalse, extraquere){
return new Promise((res, rej) => {
let resp;
let extra;
if(trufalse == true){
if(extraquere){
extra = extraquere + "&key="+ key
}else{
extra = "?key=" + key
}
}else{
if(extraquere){
extra = extraquere + "?key="+ key
}else{
extra = "?key=" + key
}
}
https.get(`https://api.hypixel.net${path}${extra}`).then(res => {
if(res.data){
resp = res.data
}
}).catch(err => {
rej(sendError(`Request failed`))
}).finally(function () {
res(resp)
});
})
}
function setKey(key1){
if(!key1) return sendError("Please give an api key to set to!")
key = key1
return sendSuccess()
}
async function getWatchdogStats(){
return request("/watchdogstats", false)
}
async function boosters(){
return request('/boosters', false)
}
async function findGuild(method, nameoruuid){
let methods = ["name", 'uuid']
if(!method || !methods.includes(method.toLowerCase())) return sendError("Couldn't find that method! Methods are " + methods.join(', '))
if(!nameoruuid) return sendError(`No name or uuid provided!`)
if(method.toLowerCase() === "name"){
return request(`/findGuild`, true, `?byName=${nameoruuid}`)
}else{
return request('/findGuild', true, `?byUuid=${nameoruuid}`)
}
}
async function friends(uuid){
if(!uuid) return sendError(`You must supply a UUID to search for!`)
return request('/friends', true, `?uuid=${uuid}`)
}
async function gameCounts(){
return request(`/gameCounts`, false)
}
async function guild(method, param){
let methods = ["id", "name", "player"]
if(!method || !methods.includes(method.toLowerCase())) return sendError("Couldn't find that method! Methods are " + methods.join(', '))
if(!param) return sendError(`No name or uuid or id provided!`)
if(method.toLowerCase() === "name"){
return request('/guild', true, `?name=${param}`)
}else if(method.toLowerCase() === "player"){
return request('/guild', true, `?player=${param}`)
}else{
return request('/guild', true, `?id=${param}`)
}
}
async function keyInfo(){
return request('/key', false)
}
async function leaderboards(){
return request('/leaderboards', false)
}
async function player(param){
if(!param) return sendError(`Please provide a UUID to search!`)
return request("/player", true, `?uuid=${param}`)
}
async function playerCount(){
return request("/playerCount", false)
}
async function recentGames(param){
if(!param) return sendError(`Please provide a UUID to search!`)
return request("/recentGames", true, `?uuid=${param}`)
}
async function resources(param){
let options = ["achievements", "challenges", "quests", "guilds/achievements", "guilds/permissions", "skyblock/collections", "skyblock/skills"]
if(!param || !options.includes(param.toLowerCase())) return sendError(`Please provide a reasource to find! Options: ${options.join(', ')}`)
return request(`/resources`, false, `/${param}`)
}
async function status(param){
if(!param) return sendError(`Please provide a UUID to search!`)
return request("/status", true, `?uuid=${param}`)
}
async function auction(method, param){
let methods = ["uuid", "auction_id", "player"]
if(!method || !methods.includes(method.toLowerCase())) return sendError(`Please provide a method to use! Options: ${methods.join(', ')}`)
if(!param) return sendError(`Please provide an UUID, auction_id, or player to search!`)
if(method.toLowerCase() === "uuid"){
return request('/skyblock/auction', true, `?uuid=${param}`)
}else if(method.toLowerCase() === "player"){
return request(`/skyblock/auction`, true, `?player=${param}`)
}else{
return request('/skyblock/auction', true, `?profile=${param}`)
}
}
async function auctions(page){
if(!page) return request(`/skyblock/auctions`, false)
return request('/skyblock/auctions', true, `?page=${page}`)
}
async function bazaar(){
return request('/skyblock/bazaar', false)
}
async function news(){
return request('/skyblock/news', false)
}
async function profile(param){
if(!param) return sendError(`Please provide a profile to search!`)
return request('/skyblock/profile', true, `?profile=${param}`)
}
async function profiles(param){
if(!param) return sendError(`Please provide a UUID to search!`)
return request('/skyblock/profiles', true, `?uuid=${param}`)
}
module.exports.skyblock = {
auction, auctions, bazaar, news, profiles
}
module.exports = {
status, resources, recentGames, playerCount, player, leaderboards, keyInfo, guild, gameCounts, friends, findGuild, boosters, setKey, getWatchdogStats
}