Discordbots.org server count update endpoint
//
// Made by Tobias feld | https://github.com/TobiasFeld22
// Last change: 22-10-2017 | 20:15 (CEST)
// This notebook is licensed with the MIT license,
// full file and the full license can be found in this gist:
// https://gist.github.com/TobiasFeld22/99529f0f0aec2104dad26e0a22f57400
var express = require("@runkit/runkit/express-endpoint/1.0.0");
var app = express(exports);
app.all("/:id/:token/:servers", (req, res) => {
if (req.params.id === null || isNaN(req.params.id) === true) {
return res.send("Your <strong>Bot id</strong> is not defined correctly, use the endpoint like this:<br><br>")
} else if (req.params.token === null || req.params.token.length <= 150) {
return res.send("Your <strong>Api token</strong> is not defined correctly, use the endpoint like this:<br><br>")
} else if (req.params.servers === null || isNaN(req.params.servers) === true) {
return res.send("Your <strong>Server amount</strong> is not defined correctly, use the endpoint like this:<br><br>" + process.env.RUNKIT_ENDPOINT_URL + "<strong>:bot_id</strong>/<strong>:api_token</strong>/<strong>:server_amount</strong>/")
}
update(req.params.servers, req.params.token, req.params.id, res)
})
app.all("*", (req, res) => {
res.send("To use this endpoint, send a request (get / post (doesn't matter)) to this endpoint like this:<br><br>" + process.env.RUNKIT_ENDPOINT_URL + "<strong>:bot_id</strong>/<strong>:api_token</strong>/<strong>:server_amount</strong>/<br><br>See raw code:<br><a href=\"https://runkit.com/tobiasfeld22/59ecb6e7fc7de200125ba2b5\"> Click here </a>")
})
function update(servers, token, id, res) {
const snekfetch = require("snekfetch")
var servers = parseInt(servers)
snekfetch.post('https://discordbots.org/api/bots/' + id + '/stats').set('Authorization', token).send({
server_count: parseInt(servers)
}).then(r => {
res.sendStatus(200)
}).catch(e => {
var extra = "";
if ("" + e == "Error: 403 Forbidden") {
extra = extra + "<br><br>This error mostly happens when your id and token are not belonging together, or you mistyped either token or id. "
}
res.status(500).send("Error occurred while posting stats: \n" + e + extra)
});
}
no comments