@kaname-png/plugin-statcord
TypeScript icon, indicating that this package has built-in type declarations

2.3.2 • Public • Published

Neko Plugins Logo

@kaname-png/plugin-statcord

Plugin for @sapphire/framework to post and manage bot stats with Statcord.

GitHub codecov npm (scoped) npm

Description

This plugin allows the integration of Statcord with the Bot. Statcord is a web page that allows to manage statistics such as, how many commands were executed in a day, new guilds, etc.

More information about Statcord can be found on its website.

Features

  • Fully ready for TypeScript!
  • Includes ESM ready entrypoint
  • Easy to use

Installation

@kaname-png/plugin-statcord depends on the following packages. Be sure to install these along with this package!

You can use the following command to install this package, or replace npm install with your package manager of choice.

npm install @kaname-png/plugin-statcord @sapphire/framework discord.js

Usage

JavaScript

In your main or setup file, register the plugin:

require('@kaname-png/plugin-statcord/register');

It is important to add an API key provided by Statcord.

require('@kaname-png/plugin-statcord/register');

const client = new SapphireClient({
	/* your bot options */
	statcord: {
		client_id: 'YOUR_BOT_ID', // (Optional) By default it is the bot id.
		key: 'YOUR_AWESOME_API_KEY', // (Required) Statcord API key.
		autopost: false, // (Optional) Allows automatic posting of statistics.
		baseUrl: 'https://api.statcord.com/v3', // (Optional) Change the base URL of the Statcord API.
		debug: false, // (Optional) Show debug messages.
		sharding: false // (Optional) Activate the sharding mode, it is important to read the notes below.
	}
});

async function main() {
	await client.login();
}

void main();

TypeScript

In your main or setup file, register the plugin:

import '@kaname-png/plugin-statcord/register';

It is important to add an API key provided by Statcord.

import '@kaname-png/plugin-statcord/register';

const client = new SapphireClient({
	/* your bot options */
	statcord: {
		client_id: 'YOUR_BOT_ID', // (Optional) By default it is the bot id.
		key: 'YOUR_AWESOME_API_KEY', // (Required) Statcord API key.
		autopost: false, // (Optional) Allows automatic posting of statistics.
		baseUrl: 'https://api.statcord.com/v3', // (Optional) Change the base URL of the Statcord API.
		debug: false, // (Optional) Show debug messages.
		sharding: false // (Optional) Activate the sharding mode, it is important to read the notes below.
	}
});

async function main() {
	await client.login();
}

void main();

If you enable the autopost option, that's it, the plugin will collect and publish the statistics for you, you don't have to do anything else!

Bandwidth usage

To set the bandwidth usage in each statistics post the setBandwidthUsage() method is available, the data sent by this method is reset in each statistics post. This is done so that the user can choose the best way to get this data.

Javascript

const { container } = require('@sapphire/framework');

class MyAwesomeServicePostStats {
	public postBandwidth() {
		const bandwidthUsage = getBandwidthUsage(); // Use your method to get this data.
		container.statcord.setBandwidthUsage(bandwidthUsage);
	}
}

export default MyAwesomeServicePostStats;

TypeScript

import { container } from '@sapphire/framework';

export class MyAwesomeServicePostStats {
	public postBandwidth() {
		const bandwidthUsage = getBandwidthUsage(); // Use your method to get this data.
		container.statcord.setBandwidthUsage(bandwidthUsage);
	}
}

Posting statistics manually

To be able to post statistics manually, it is necessary to disable the autopost option in the statcord options, by default it is disabled.

Javascript

const client = new SapphireClient({
	/* your bot options */
	statcord: {
		key: 'YOUR_AWESOME_API_KEY',
		autopost: false
	}
});

async function main() {
	await client.login();
}

void main();

TypeScript

import '@kaname-png/plugin-statcord/register';

const client = new SapphireClient({
	/* your bot options */
	statcord: {
		key: 'YOUR_AWESOME_API_KEY',
		autopost: false
	}
});

async function main() {
	await client.login();
}

void main();

In order to be able to post statistics there is the postStats method available, by default, the statistics of used commands, popular commands, total guilds and users are managed internally by the plugin.

Remember that you can use these methods and all the Statcord plugin methods globally available anywhere in the Bot.

Javascript

const { container } = require('@sapphire/framework');

class MyAwesomeServicePostStats {
	public postStats() {
		container.statcord.postStats();
	}
}

export default MyAwesomeServicePostStats;

TypeScript

import { container } from '@sapphire/framework';

export class MyAwesomeServicePostStats {
	public postStats() {
		container.statcord.postStats();
	}
}

Get statistics

The plugin allows to get the statistics from Statcord, as it also has methods that wrapper with the Statcord API.

  1. clientStats();: Get current client statistics in Statcord.
  2. bucketStats();: Check everyone who has voted for the bot today.
  3. userVotesStats();: Check if someone has voted for the bot today.

Notes

  1. The postCommand and postStats methods are available globally so that they can be used in other ways according to the user's needs. For example, it is recommended to disable the autopost option when using the ShardingManager, as it is possible for Shards to go into Rate Limit in the Statcord API when they all perform the action of posting statistics at the same time and having these methods available allows you to devise a better way to post those statistics.
  2. If the sharding mode is used together with the autopost option it is important that the Shards have at least 1 minute of initialization between them, so that the shards have a difference of 1 minute and thus be able to send the statistics without entering Rate Limit in the Statcord API.

Contributors ✨

Thanks goes to these wonderful people (emoji key):

Kaname
Kaname

💻 🐛 📖 🚇 🚧 👀
Sebazz
Sebazz

🐛 💻
Chiko
Chiko

🐛 💻
Williams Bussat
Williams Bussat

💻 📖 🤔

This project follows the all-contributors specification. Contributions of any kind welcome!

Package Sidebar

Install

npm i @kaname-png/plugin-statcord

Weekly Downloads

152

Version

2.3.2

License

MIT

Unpacked Size

48.2 kB

Total Files

40

Last publish

Collaborators

  • kaname-png