dblapi.js
Advanced tools
Comparing version 2.2.0 to 2.3.0
{ | ||
"name": "dblapi.js", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"description": "An official module for interacting with the discordbots.org API", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -78,7 +78,6 @@ const EventEmitter = require('events'); | ||
* @param {Object} [data] Data to send with the request. | ||
* @param {boolean} [auth] Boolean indicating if auth is needed. | ||
* @private | ||
* @returns {Promise<Object>} | ||
*/ | ||
_request(method, endpoint, data, auth) { | ||
_request(method, endpoint, data) { | ||
return new Promise((resolve, reject) => { | ||
@@ -99,3 +98,7 @@ const response = { | ||
if (auth) options.headers.authorization = this.token; | ||
if (this.token) { | ||
options.headers.authorization = this.token; | ||
} else { | ||
console.warn('[dblapi.js] Warning: No DBL token has been provided.'); // eslint-disable-line no-console | ||
} | ||
if (data && method === 'post') options.headers['content-type'] = 'application/json'; | ||
@@ -141,3 +144,2 @@ if (data && method === 'get') options.path += `?${qs.encode(data)}`; | ||
async postStats(serverCount, shardId, shardCount) { | ||
if (!this.token) throw new Error('This function requires a token to be set'); | ||
if (!serverCount && !this.client) throw new Error('postStats requires 1 argument'); | ||
@@ -212,3 +214,2 @@ const data = {}; | ||
async getVotes() { | ||
if (!this.token) throw new Error('This function requires a token to be set'); | ||
const response = await this._request('get', 'bots/votes', undefined, true); | ||
@@ -224,3 +225,2 @@ return response.body; | ||
async hasVoted(id) { | ||
if (!this.token) throw new Error('This function requires a token to be set'); | ||
if (!id) throw new Error('hasVoted requires id as argument'); | ||
@@ -227,0 +227,0 @@ const response = await this._request('get', 'bots/check', { userId: id }, true); |
const EventEmitter = require('events'); | ||
const http = require('http'); | ||
const { Server, createServer } = require('http'); | ||
const querystring = require('querystring'); | ||
@@ -23,3 +23,3 @@ | ||
if (server && !(server instanceof http.Server)) throw Error('Server provided is not a http server'); | ||
if (server && !(server instanceof Server)) throw Error('The server is not an instance of http.Server'); | ||
if (server) { | ||
@@ -35,3 +35,3 @@ this._attachWebhook(server); | ||
* Event to notify that the webhook is listening | ||
* @event ready | ||
* @event DBLWebhook#ready | ||
* @param {string} hostname The hostname of the webhook server | ||
@@ -46,3 +46,3 @@ * @param {number} port The port the webhook server is running on | ||
_startWebhook() { | ||
this._server = http.createServer(this._handleRequest.bind(this)); | ||
this._server = createServer(this._handleRequest.bind(this)); | ||
this._server.listen(this.port, this._emitListening.bind(this)); | ||
@@ -79,3 +79,3 @@ } | ||
* Event that fires when the webhook has received a vote. | ||
* @event vote | ||
* @event DBLWehook#vote | ||
* @param {string} bot Id of the bot that was voted for. | ||
@@ -82,0 +82,0 @@ * @param {string} user Id of the user that voted. |
@@ -19,3 +19,3 @@ export = DBLAPI; | ||
private _request(method: string, endpoint: string, data?: object, auth?: boolean): Promise<object> | ||
private _request(method: string, endpoint: string, data?: object): Promise<object> | ||
@@ -22,0 +22,0 @@ public on(event: 'posted', listener: () => void): this; |
33164