Comparing version 1.3.0 to 1.3.1
{ | ||
"name": "dblposter", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "A simple automatic poster for DiscordBotList", | ||
@@ -10,3 +10,3 @@ "main": "src/index.js", | ||
"dependencies": { | ||
"snekfetch": "^3.6.4" | ||
"snekfetch": "^4.0.0" | ||
}, | ||
@@ -13,0 +13,0 @@ "keywords": [ |
@@ -14,32 +14,92 @@ <div> | ||
# DBLPoster | ||
A simple to use poster for DiscordBotList stats. | ||
A simple to use poster for DiscordBotList stats, when you just want to post stats without much fussing around! | ||
## How to use | ||
## Getting Started | ||
```js | ||
const dbl = require("dblposter"); | ||
It's super easy to get started with dblposter! Let's guide you through the steps you need to do to be sending stats automatically in no time! | ||
// Then, whatever your client is (Discordie, Discord.JS, Eris or Discord.io) | ||
const dblPoster = new dbl(`API KEY GOES HERE`, client); | ||
First, you have to install the module. So... | ||
```bash | ||
npm i dblposter | ||
// Then somewhere in your code, like in READY | ||
dblPoster.bind(); | ||
# Or if you are using yarn | ||
yarn add dblposter | ||
``` | ||
That will bind the poster to your client automatically and handle the stat posting on ready, guild create or delete. | ||
After that's done, all you have to do is: | ||
That function also adds the poster to the client, with the default name of `dblPoster` (accessible using `client.dblPoster`). That is an instance of EventEmitter, and it can emit 2 events: | ||
- Add `const dbl = require("dblposter")` in your main client class above everything | ||
- Keep in mind this has to be your main file in which you create the client, not the file you run if you have them split, or are sharding. | ||
- Also, dblposter will handle shard posting of all kinds for you. Just remember to attach it to each shard client. (or to the main Eris client if you're using Eris and its internal sharding) | ||
- After creating the client via `new Client` (or whichever method is used by your chosen library), add the following code: | ||
```js | ||
// Assuming client is your variable name for the client, | ||
// otherwise just change it as fit. | ||
const poster = new dbl("DBL_API_KEY_GOES_HERE", client); | ||
- posted | ||
- Means the stat posting for the shard was successful | ||
- Returns nothing | ||
- error | ||
- Means there was an error at post. | ||
- Returns the snekfetch error object. | ||
// This will bind the poster to your client and start posting automatically. | ||
poster.bind(); | ||
``` | ||
- That's it! No, seriously! | ||
If for any reason you want to change the name of the newly added property, it's as easy as: | ||
## In-Depth Details | ||
Ok, if you've reached this point, you're probably curios about exactly what this library can do. | ||
First, let's talk about the `bind` function above. It takes two parameters: | ||
| Parameter Name | Type | Default | Description | | ||
|:--------------:|:-------------------------------------------------------:|-------------|--------------------------------------------------------------------------------------| | ||
| paramName | String | dblPoster | The property which will get attached to the client in order to handle timers. | | ||
| client | DiscordJS.Client or Eris or DiscordIO.Client or DiscordIE.Client | this.client | The client to bind to, defaulting to the client provided in the constructor, if any. | | ||
Say you don't want to have that property name because it is easy to guess. You could run `bind("myParamName")` and dblposter would attach it using `myParamName` | ||
If you didn't pass in a client in the `new dbl` constructor, you can pass it in bind too! Just remember, if you don't want the paramName to be changed, you'll have to do something like `bind(null, client)`. | ||
### Please note! | ||
While dblposter does add a property to the client, all the property has is your cached API Key, and the interval used to send the statistics. Nothing else is added, and no data is received from your client. I understand why some might be concerned, but [here are the lines that handle the bind.](https://github.com/KingDGrizzle/dblposter/blob/master/src/index.js#L34-L44) | ||
## Other Details | ||
We send stats every **30 minutes**, since that's what DiscordBots require for automatic libraries. | ||
dblposter also has a `post` method, which, as it's name suggests, does a post for you. | ||
> Note that this will reset the internal interval. | ||
If you ever want to destroy dblposter (clear the internal interval, for shutdown or just to stop posting stats all together), there is the `destroy` function. Run it and, voila. The interval gets stopped, dblposter removes itself from your client, nulls the paramName (meaning you'll have to re-add it in `bind` should you call it after destroying) | ||
> Inside Reveal: We use the destroy function ourselves when you run the `post` function, but we save the paramName before hand. | ||
And in the end, dblposter extends EventEmitter, and has 2 possible events: | ||
| Event Name | Event Params | Description | | ||
|:----------:|:---------------:|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ||
| posted | | The post was successfully done. Use this event if you want to log that the post was successful. | | ||
| error | Snekfetch.Response | The post couldn't finish. The returned property from the event is a [Snekfetch Response Object](https://snekfetch.js.org/?api=snekfetch#Snekfetch.SnekfetchResponse) containing more informations. | | ||
To access it, it's as easy as: | ||
```js | ||
dblPoster.bind("mySpecialVariableName"); | ||
client.dblPoster.on("posted", () => { | ||
console.log("Woop! My stats were posted"); | ||
}); | ||
client.dblPoster.on("error", err => { | ||
// We recommend you check what the error was. | ||
// Access the status, and body property from the err object. | ||
console.log("Oh noes! I got an error!", err); | ||
}); | ||
``` | ||
Then, access it with `client.mySpecialVariableName` | ||
If you provided a different paramName in `bind`, just replace `dblPoster` from that snippet above with your param name. | ||
## Error Message Explaining | ||
When running `bind`, if something isn't right, you will receive an error. | ||
| Message | Meaning | | ||
|:--------------------------------------------------------------------------------------------------------:|:-----------------------------------------------------------------------------------------------------------------------------------------:| | ||
| The API key is either not specified, or is not a string. | Where you constructed dblposter using `new poster`, you didn't provide an API Key or it wasn't a string. Double check and try again. | | ||
| You need to provide a client to bind to, either in the constructor of dblposter or in the bind function! | You didn't provide a client in the dblposter constructor (`new poster("API_KEY", client)`) or in the bind function (`bind(null, client)`) | |
const sendData = require("./SendData"); | ||
let DISCORDIE = false; | ||
let ALREADY_READY = false; | ||
module.exports = (client, paramName) => { | ||
if (client.Dispatcher) DISCORDIE = true; | ||
if (ALREADY_READY) { | ||
onReady(client, paramName); | ||
} else if (client.Dispatcher) { | ||
DISCORDIE = true; | ||
client.Dispatcher.once("GATEWAY_READY", () => onReady(client, paramName)); | ||
} else { | ||
client.once("ready", () => onReady(client, paramName)); | ||
} | ||
}; | ||
function onReady (client, paramName) { | ||
ALREADY_READY = true; | ||
sendData.send(client, paramName, DISCORDIE); | ||
@@ -17,2 +29,2 @@ const interval = setInterval(() => { | ||
}); | ||
}; | ||
} |
@@ -29,3 +29,3 @@ const bind = require("./Bind"); | ||
* poster instance on the client | ||
* @param {DiscordJS.Client|Eris|DiscordIO.Client|DiscordIE.Client} [client] Optional client to bind to, | ||
* @param {DiscordJS.Client|Eris|DiscordIO.Client|DiscordIE.Client} [client=this.client] Optional client to bind to, | ||
* if you haven't added it in the constructor | ||
@@ -32,0 +32,0 @@ * @memberof DBLPoster |
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
31819
202
105
+ Addedsnekfetch@4.0.4(transitive)
- Removedsnekfetch@3.6.4(transitive)
Updatedsnekfetch@^4.0.0