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

statcord.js-beta

v3.4.0

Published

Upload Statcord info to the official API!

Downloads

38

Readme

Table of Contents

Statcord

post

Manual posting

Emits the post event

autopost

Auto posting

Emits the autopost-start event

postCommand

Post stats about a command

Parameters

  • command_name string The name of the command that was run
  • author_id string The id of the user that ran the command

registerCustomFieldHandler

Register the function to get the values for posting

Parameters

  • customFieldNumber (1 | 2) Whether the handler is for customField1 or customField2
  • handler Normal Handler

Returns (Error | null)

ShardingClient

registerCustomFieldHandler

Register the function to get the values for posting

Parameters

  • customFieldNumber (1 | 2) Whether the handler is for customField1 or customField2
  • handler Sharding Handler

Returns (Error | null)

postCommand

Post stats about a command

Parameters

  • command_name string The name of the command that was run
  • author_id string The id of the user that ran the command
  • client any The discord client this command is being posted for

post

Post all current stats to statcord

Emits the post event

Handlers

Normal Handler

Asynchronous function

Parameters

Returns (Promise<string>)

Sharding Handler

Asynchronous function

Parameters

Returns (Promise<string>)

Events

post event

"post" - Emitted whenever a post to the api takes place

Parameters

status - (false | Error | string)

autopost-start event

"autopost-start" - Emitted when autopost is started

Examples

Normal Usage

const Statcord = require("statcord.js");
const Discord = require("discord.js");

const client = new Discord.Client();
// Create statcord client
const statcord = new Statcord.Client({
    key: "statcord.com-APIKEY",
    client,
    postCpuStatistics: false, /* Whether to post CPU statistics or not, defaults to true */
    postMemStatistics: false, /* Whether to post memory statistics or not, defaults to true */
    postNetworkStatistics: false /* Whether to post network statistics or not, defaults to true */
});

/* Register custom fields handlers (these are optional, you are not required to use this function)
 * These functions are automatically run when posting
*/

// Handler for custom value 1
statcord.registerCustomFieldHandler(1, async (client) => {
    // Get and return your data as a string
});

// Handler for custom value 2
statcord.registerCustomFieldHandler(2, async (client) => {
    // Get and return your data as a string
});

// Client prefix
const prefix = "cs!";

client.on("ready", async () => {
    console.log("ready");

    // Start auto posting
    statcord.autopost();
});


client.on("message", async (message) => {
    if (message.author.bot) return;
    if (message.channel.type !== "text") return;

    if (!message.content.startsWith(prefix)) return;

    let command = message.content.split(" ")[0].toLowerCase().substr(prefix.length);

    // Post command
    statcord.postCommand(command, message.author.id);

    if (command == "say") {
        message.channel.send("say");
    } else if (command == "help") {
        message.channel.send("help");
    } else if (command == "post") {
        // Only owner runs this command
        if (message.author.id !== "bot_owner_id") return;

        // Example of manual posting
        statcord.post();
    }
});

statcord.on("autopost-start", () => {
    // Emitted when statcord autopost starts
    console.log("Started autopost");
});

statcord.on("post", status => {
    // status = false if the post was successful
    // status = "Error message" or status = Error if there was an error
    if (!status) console.log("Successful post");
    else console.error(status);
});

client.login("TOKEN");

Sharding Usage

sharder.js

    const Discord = require("discord.js");
    const Statcord = require("statcord.js");

    const manager = new Discord.ShardingManager('./bot.js', { token: "TOKEN"});
    // Create statcord sharding client
    const statcord = new Statcord.ShardingClient({
        key: "statcord.com-APIKEY",
        manager,
        postCpuStatistics: false, /* Whether to post CPU statistics or not, defaults to true */
        postMemStatistics: false, /* Whether to post memory statistics or not, defaults to true */
        postNetworkStatistics: false, /* Whether to post network statistics or not, defaults to true */
        autopost: false /* Whether to auto post or not, defaults to true */
    });

    /* Register custom fields handlers (these are optional, you are not required to use this function)
    * These functions are automatically run when posting
    */

    // Handler for custom value 1
    statcord.registerCustomFieldHandler(1, async (manager) => {
        // Get and return your data as a string
    });

    // Handler for custom value 2
    statcord.registerCustomFieldHandler(2, async (manager) => {
        // Get and return your data as a string
    });

    // Spawn shards, statcord works with both auto and a set amount of shards
    manager.spawn();

    // Normal shardCreate event
    manager.on("shardCreate", (shard) => {
        console.log(`Spawned shard ${shard.id}`);
    });

    statcord.on("autopost-start", () => {
        // Emitted when statcord autopost starts
        console.log("Started autopost");
    });

    statcord.on("post", status => {
        // status = false if the post was successful
        // status = "Error message" or status = Error if there was an error
        if (!status) console.log("successful post");
        else console.error(status);
    });

bot.js

const Discord = require("discord.js");
const Statcord = require("statcord.js");

const client = new Discord.Client();
/* There is no need to create a statcord client in the bot script,
because it has already been made in the sharding script
*/

// Client prefix
const prefix = "cs!";

client.on("ready", async () => {
    console.log("ready");
});

client.on("message", async (message) => {
    if (message.author.bot) return;
    if (message.channel.type !== "text") return;

    if (!message.content.startsWith(prefix)) return;

    let command = message.content.split(" ")[0].toLowerCase().substr(prefix.length);

    // Post command
    Statcord.ShardingClient.postCommand(command, message.author.id, client);

    if (command == "say") {
        message.channel.send("say");
    } else if (command == "help") {
        message.channel.send("help");
    } else if (command == "post") {
        // Only owner runs this command
        if (message.author.id !== "bot_owner_id") return;

        // Example of manual posting
        Statcord.ShardingClient.post(client);

        // Errors on the sharding client will be sent to the console straight away
    }
});

client.login("TOKEN");

Contributing

Contributions are always welcome!
Take a look at any existing issues on this repository for starting places to help contribute towards, or simply create your own new contribution to the project.

When you are ready, simply create a pull request for your contribution and we will review it whenever we can!

Donating

You can also help me and the project out by sponsoring me through a donation on PayPal.

Discussion, Support and Issues

Need support with this project, have found an issue or want to chat with others about contributing to the project?

Please check the project's issues page first for support & bugs!

Not found what you need here?

  • If you have an issue, please create a GitHub issue here to report it, include as much detail as you can.
  • Alternatively, You can join our Discord server to discuss any issue or to get support for the project.: