bfd-api-redux
Advanced tools
Comparing version 1.2.2 to 1.2.3
{ | ||
"name": "bfd-api-redux", | ||
"version": "1.2.2", | ||
"version": "1.2.3", | ||
"description": "A node.js wrapper for the Bots For Discord API", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -0,1 +1,4 @@ | ||
# Deprecation notice for <1.2.2 | ||
**IMPORTANT:** `bfd-api-redux` versions 1.2.2 and below are NO LONGER SUPPORTED for interfacing with the Discords.com Bots API. | ||
## NOTICE & INFO | ||
@@ -5,2 +8,6 @@ | ||
*The current version of the Discords.com Bot API will be depracated | ||
upon the release of the BotsV3 runtime (website rewrite). | ||
Please keep in mind that any bots using a custom wrapper for the API will need to migrate, the current version if this package will also be deprecated and an update will be required.* | ||
## Usage | ||
@@ -14,8 +21,2 @@ | ||
**NOTE:** *If you do now wish to use callbacks, then all actions must be used inside async functions with an `await`, for example:* | ||
```js | ||
async function user() { | ||
console.log(await api.getUser('254287885585350666')); | ||
} | ||
user(); | ||
``` | ||
@@ -32,35 +33,11 @@ You can easily update your Bot's guild count using this function: | ||
```js | ||
api.getVotes12().then(votes => { | ||
api.getVotes().then(votes => { | ||
console.log(votes) | ||
}) | ||
``` | ||
### Get user | ||
```js | ||
api.getUser("254287885585350666").then(user => { //Provide a user id | ||
console.log(user) | ||
}) | ||
``` | ||
// Or, if running inside an async function: | ||
### Get user bots | ||
```js | ||
api.getUserBots("254287885585350666").then(bots => { //Provide a user id | ||
console.log(bots) | ||
}) | ||
await api.getVotes() | ||
``` | ||
### Get bot | ||
```js | ||
api.getUser("621352902656524288").then(bot => { //Provide a bot id | ||
console.log(bot) | ||
}) | ||
``` | ||
### Get widget | ||
```js | ||
api.getWidget("621352902656524288").then(widget => { //Provide a bot id | ||
console.log(widget) | ||
}) | ||
``` | ||
### Cheking a vote for one specific user (including structure) | ||
@@ -67,0 +44,0 @@ ```js |
122
src/main.js
@@ -11,49 +11,7 @@ const EventEmitter = require("events"); | ||
async getUser(id) { | ||
return new Promise((resolve, reject) => { | ||
https.get(`https://discords.com/bots/api/user/${id}`, async (res) => { | ||
res.on('data', (d) => { | ||
resolve(JSON.parse(d.toString("utf-8"))); | ||
}); | ||
}).on('error', (e) => { | ||
reject(e); | ||
}) | ||
}) | ||
} | ||
async getUserBots(id) { | ||
return new Promise((resolve, reject) => { | ||
https.get(`https://discords.com/bots/api/user/${id}/bots`, async (res) => { | ||
res.on('data', (d) => { | ||
resolve(JSON.parse(d.toString("utf-8"))); | ||
}); | ||
}).on('error', (e) => { | ||
reject(e); | ||
}) | ||
}) | ||
} | ||
async getBot(id) { | ||
return new Promise((resolve, reject) => { | ||
https.get(`https://discords.com/bots/api/bot/${id}`, async (res) => { | ||
res.on('data', (d) => { | ||
resolve(JSON.parse(d.toString("utf-8"))); | ||
}); | ||
}).on('error', (e) => { | ||
reject(e); | ||
}) | ||
}) | ||
} | ||
async getVotes(id = this._id, token = this._token) { | ||
return new Promise((resolve, reject) => { | ||
reject ("This endpoint has been deprecated - please update to getVotes12()"); | ||
}) | ||
} | ||
async getVotes12(id = this._id, token = this._token) { | ||
return new Promise((resolve, reject) => { | ||
https.get({ | ||
hostname: 'discords.com', | ||
path: `/bots/api/bot/${id}/votes12h`, | ||
path: `/bots/api/bot/${id}/getvotes`, | ||
headers: { | ||
@@ -63,7 +21,14 @@ Authorization: token, | ||
}, | ||
followRedirect: true, | ||
parse: "json" | ||
}, async (res) => { | ||
let resultdata = ""; | ||
res.on('data', (d) => { | ||
resolve(JSON.parse(d.toString("utf-8"))); | ||
if (res.statusCode !== 200) { resolve(); throw new Error(d);} | ||
resultdata += d.toString(); | ||
}); | ||
res.on('end', () => { | ||
resolve(JSON.parse(resultdata)); | ||
}) | ||
}).on('error', (e) => { | ||
@@ -77,5 +42,5 @@ reject(e); | ||
return new Promise(async (resolve, reject) => { | ||
const votes = await this.getVotes12(); | ||
if (Array.isArray(votes.entries)) { | ||
resolve(votes.entries.some(vote => vote.userid === userid)) | ||
const votes = await this.getVotes(); | ||
if (Array.isArray(votes.votes)) { | ||
resolve(votes.votes.some(vote => vote.user_id === userid)) | ||
} else { | ||
@@ -89,7 +54,7 @@ resolve(false); | ||
return new Promise(async (resolve, reject) => { | ||
const votes = await this.getVotes12(); | ||
if (Array.isArray(votes.entries)) { | ||
let structure = { voted: votes.entries.some(vote => vote.userid === userid), votes: []}; | ||
votes.entries.forEach(vote => { | ||
if (vote.userid === userid) { | ||
const votes = await this.getVotes(); | ||
if (Array.isArray(votes.votes)) { | ||
let structure = { voted: votes.votes.some(vote => vote.user_id === userid), votes: []}; | ||
votes.votes.forEach(vote => { | ||
if (vote.user_id === userid) { | ||
structure.votes.push(vote) | ||
@@ -105,14 +70,2 @@ } | ||
async getWidget(id) { | ||
return new Promise((resolve, reject) => { | ||
https.get(`https://discords.com/bots/api/bot/${id}/widget`, async (res) => { | ||
res.on('data', (d) => { | ||
resolve(d.toString("utf-8")); | ||
}); | ||
}).on('error', (e) => { | ||
reject(e); | ||
}) | ||
}) | ||
} | ||
async setServers(serverCount, id = this._id, token = this._token) { | ||
@@ -127,3 +80,3 @@ return new Promise((resolve, reject) => { | ||
port: 443, | ||
path: `/bots/api/bot/${id}`, | ||
path: `/bots/api/bot/${id}/setservers`, | ||
method: 'POST', | ||
@@ -137,38 +90,9 @@ headers: { | ||
const req = https.request(options, res => { | ||
let resultdata = ""; | ||
res.on('data', d => { | ||
resolve(JSON.parse(d.toString("utf-8"))); | ||
if (res.statusCode !== 200) { resolve(); throw new Error(d);} | ||
resultdata = d.toString("utf-8"); | ||
}) | ||
}) | ||
req.on('error', error => { | ||
reject(error) | ||
}) | ||
req.write(data) | ||
req.end() | ||
}) | ||
} | ||
async updateCard(enabled, content, id = this._id, token = this._token) { | ||
return new Promise((resolve, reject) => { | ||
const data = JSON.stringify({ | ||
enabled: enabled, | ||
content: content | ||
}) | ||
const options = { | ||
hostname: 'discords.com', | ||
port: 443, | ||
path: `/bots/api/bot/${id}/card`, | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'authorization': token | ||
} | ||
} | ||
const req = https.request(options, res => { | ||
res.on('data', d => { | ||
resolve(JSON.parse(d.toString("utf-8"))); | ||
res.on('end', () => { | ||
resolve(JSON.parse(resultdata)); | ||
}) | ||
@@ -175,0 +99,0 @@ }) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5565
92
55