Comparing version 1.1.1 to 1.2.0
{ | ||
"name": "dblposter", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"description": "A simple automatic poster for DiscordBotList", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -17,2 +17,3 @@ const request = require("snekfetch"); | ||
let DIO = false; | ||
let ERIS = false; | ||
if (client._shard) { | ||
@@ -26,6 +27,8 @@ DIO = true; | ||
// This is dirty, but w/e | ||
// TODO: | ||
// Figure out if we can get the current shard ID only (If Eris is instantiated using new Eris({lastShardID})) | ||
shardID = null; | ||
shardCount = null; | ||
shardCount = client.options.maxShards; | ||
if (client.options.firstShardID === client.options.lastShardID) { | ||
shardID = client.options.firstShardID; | ||
} else { | ||
ERIS = true; | ||
} | ||
} else if (client.shard) { | ||
@@ -40,3 +43,10 @@ shardID = client.shard.id; | ||
totalGuilds = client.servers ? Object.keys(client.servers).length : client.guilds.size; | ||
postData(shardID, shardCount, totalGuilds, token, client, false, paramName); | ||
if (!ERIS) { | ||
postData(shardID, shardCount || 1, totalGuilds, token, client, false, paramName); | ||
} else { | ||
client.shards.forEach(s => { | ||
const totalGuildsOnShard = client.guilds.filter(g => g.shard.id === s.id).length; | ||
postData(s.id, shardCount, totalGuildsOnShard, token, client, false, paramName); | ||
}); | ||
} | ||
} | ||
@@ -46,15 +56,7 @@ }; | ||
function postData (shardID, shardCount, guilds, token, client, discordIE, paramName) { | ||
if (shardID === null && shardCount === null) { | ||
request.post(API_URL.replace("{id}", client.user.id)) | ||
.set("Authorization", token) | ||
.send({ server_count: Number(guilds) }) | ||
.then(() => { client[paramName].emit("posted"); }) | ||
.catch(e => { client[paramName].emit("error", e); }); | ||
} else { | ||
request.post(API_URL.replace("{id}", discordIE ? client.User.id : client.id ? client.id : client.user.id)) | ||
.set("Authorization", token) | ||
.send({ server_count: Number(guilds), shard_id: Number(shardID), shard_count: Number(shardCount) }) | ||
.then(() => { client[paramName].emit("posted"); }) | ||
.catch(e => { client[paramName].emit("error", e); }); | ||
} | ||
request.post(API_URL.replace("{id}", discordIE ? client.User.id : client.id ? client.id : client.user.id)) | ||
.set("Authorization", token) | ||
.send({ server_count: Number(guilds), shard_id: Number(shardID), shard_count: Number(shardCount || 1) }) | ||
.then(() => { client[paramName].emit("posted"); }) | ||
.catch(e => { client[paramName].emit("error", e); }); | ||
} |
42155
130