npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dblposter

v1.3.1

Published

A simple automatic poster for DiscordBotList

Downloads

85

Readme

DBLPoster

A simple to use poster for DiscordBotList stats, when you just want to post stats without much fussing around!

Getting Started

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!

First, you have to install the module. So...

npm i dblposter

# Or if you are using yarn

yarn add dblposter

After that's done, all you have to do is:

  • 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:
// 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);

// This will bind the poster to your client and start posting automatically.
poster.bind();
  • That's it! No, seriously!

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.

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 containing more informations. |

To access it, it's as easy as:

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);
});

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)) |