Skip to content
This repository has been archived by the owner on Apr 27, 2024. It is now read-only.
/ statcord-eris Public archive
forked from labdiscord/statcord.js

A simple API wrapper for statcord.com to connect your bot and get your bot stats.

License

Notifications You must be signed in to change notification settings

JustCat80/statcord-eris

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)

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

  • client Eris Client The client is passed to your function when getting the data

Returns (Promise<string>)

Sharding Handler

Sharding usage (in Statcord-Eris) isn't available yet.

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 Discord = require("eris");
const Statcord = require("statcord-eris");

const client = new Discord.Client("TOKEN");
// 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") {
        client.createMessage(message.channel.id, "say");
    } else if (command == "help") {
        client.createMessage(message.channel.id, "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.connect();

Sharding Usage

Sharding usage (in Statcord-Eris) isn't available yet.

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.:
Discord

About

A simple API wrapper for statcord.com to connect your bot and get your bot stats.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%