Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dblposter

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dblposter - npm Package Compare versions

Comparing version 1.0.3 to 1.1.0

6

package.json
{
"name": "dblposter",
"version": "1.0.3",
"description": "A simple to use poster for DiscordBotList",
"version": "1.1.0",
"description": "A simple automatic poster for DiscordBotList",
"main": "src/index.js",

@@ -10,3 +10,3 @@ "repository": "https://github.com/KingDGrizzle/dblposter",

"dependencies": {
"snekfetch": "^3.6.1"
"snekfetch": "^3.6.4"
},

@@ -13,0 +13,0 @@ "keywords": [

const sendData = require("./SendData");
let DISCORDIE;
let DISCORDIE = false;
module.exports = (client, apiKey, paramName) => {
if (client.Dispatcher) DISCORDIE = true;
if (DISCORDIE) {
client.Dispatcher.on("GATEWAY_READY", () => {
sendData(client, apiKey, DISCORDIE, paramName);
});
client.Dispatcher.on("GUILD_CREATE", () => {
sendData(client, apiKey, DISCORDIE, paramName);
});
client.Dispatcher.on("GUILD_DELETE", () => {
sendData(client, apiKey, DISCORDIE, paramName);
});
} else {
client.on("ready", () => {
sendData(client, apiKey, DISCORDIE, paramName);
});
client.on("guildCreate", () => {
sendData(client, apiKey, DISCORDIE, paramName);
});
client.on("guildDelete", () => {
sendData(client, apiKey, DISCORDIE, paramName);
});
}
const interval = setInterval(() => {
sendData(client, apiKey, DISCORDIE, paramName);
}, 120000);
interval.unref();
Object.defineProperty(client[paramName], "_interval", {
value: interval,
writable: false,
enumerable: false,
});
};
const bind = require("./Bind");
const { EventEmitter } = require("events");
/**
* The DBLPoster
* @class DBLPoster
* @extends {EventEmitter}
*/
class DBLPoster extends EventEmitter {
constructor (apiKey) {
/**
* Creates an instance of DBLPoster.
* @param {string} apiKey The API Key provded by discordbots.org
* @param {DiscordJS.Client|Eris|DiscordIO.Client|DiscordIE.Client} client The client you want to bind to
* @memberof DBLPoster
*/
constructor (apiKey, client) {
super();
Object.defineProperty(this, "apiKey", {
value: apiKey,
writable: false,
enumerable: false,
});
this.client = client;
}
bind (client, paramName = "dblPoster") {
/**
* Binds the poster to the client.
* @param {string} [paramName="dblPoster"] The value that determines the accessible
* poster instance on the client
* @returns {void}
* @memberof DBLPoster
* @chainable
*/
bind (paramName = "dblPoster") {
if (this.apiKey === "" || this.apiKey === null || !this.apiKey || typeof this.apiKey !== "string") {
throw new Error(`The API key is either not specified, or is not a string.`);
}
if (!client) throw new RangeError(`You need to provide a client to bind to!`);
Object.defineProperty(client, paramName, {
value: this,
writable: false,
});
return bind(client, this.apiKey, paramName);
if (!this.client) throw new RangeError(`You need to provide a client to bind to!`);
this.paramName = paramName;
this.client[this.paramName] = this;
bind(this.client, this.apiKey, paramName);
return this;
}
/**
* Destroys the DBLPoster's interval.
* @returns {DBLPoster}
* @memberof DBLPoster
* @chainable
*/
destroy () {
if (this.client && this.client[this.paramName]) {
if (this.client[this.paramName]._interval) {
clearInterval(this.client[this.paramName]._interval);
this.client[this.paramName]._interval = null;
}
this.client[this.paramName] = null;
// Null out the param name
this.paramName = null;
}
return this;
}
}
module.exports = DBLPoster;

@@ -12,4 +12,3 @@ const request = require("snekfetch");

}
let id = client.User.id;
postData(shardID, shardCount, totalGuilds, token, client, id, paramName);
postData(shardID, shardCount, totalGuilds, token, client, true, paramName);
} else {

@@ -40,13 +39,17 @@ let totalGuilds = null;

totalGuilds = client.servers ? Object.keys(client.servers).length : client.guilds.size;
postData(shardID, shardCount, totalGuilds, token, client, client.id ? client.id : client.user.id, paramName);
postData(shardID, shardCount, totalGuilds, token, client, false, paramName);
}
};
function postData (shardID, shardCount, guilds, token, client, id, paramName) {
function postData (shardID, shardCount, guilds, token, client, discordIE, paramName) {
if (shardID === null && shardCount === null) {
request.post(API_URL.replace("{id}", id)).set("Authorization", token).send({ server_count: Number(guilds) })
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}", id)).set("Authorization", token).send({ server_count: Number(guilds), shard_id: Number(shardID), shard_count: Number(shardCount) })
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"); })

@@ -53,0 +56,0 @@ .catch(e => { client[paramName].emit("error", e); });

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc