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

cordium.js

v0.2.2

Published

A multi-core vertically scalable library for interacting with the Discord API.

Downloads

15

Readme

About

Cordium.js is a library written in Typescript that aims to assist in the development of bots for Discord, the library has several classes, managers and interfaces to facilitate the interaction with the Discord API, in addition to being fully customizable, cordium.js is still in the alpha phase of development and is not ready to be used in production.

You can check the full documentation here

Table of Contents

Installation

npm install cordium.js

Features

  • Shard support
  • Fully customizable
  • Single dependency
  • Vertically scalable
  • Multi-core support

Examples

If you are going to copy these examples, remember to change the Discord authentication token, you can create a Bot and get its token here: Discord Developers Portal

Simple command

import { Client, Intents } from 'cordium.js';

(async () => {
  const client = new Client('MTE1NzcyMDExNDMwMTUxNzkyNA.GyqSdV.H5bxTCTKBG6kJP-B0HUaSTVIVE7FhJsk-MR8VM', {
    // Set the required intents to receive message & guild related events.
    intents: [ Intents.GUILD, Intents.GUILD_MESSAGES, Intents.GUILD_MEMBERS, Intents.MESSAGE_CONTENT ]
  });
  await client.init();

  // Subscribe to the "ready" event.
  client.events.ready.subscribe(() => {
    console.log(`I logged in as (${client.user?.username})`);
  });

  // Subscribe to the "messageCreate" event.
  client.events.messageCreate.subscribe(async (message) => {
    // Ignore the command if is exectued by a Bot.
    if(message.author.bot) return;

    if(message.content == '!ping') {
      // Send a message referencied by the author message.
      // client.shards.ping is an average of the ping of all connected shards, in this case a single shard.
      return await message.sendReference(`My ping is: \`${client.shards.ping}\`ms`);
    }
  });

Sharding

import { Client, Intents } from 'cordium.js';

(async () => {
  const client = new Client('MTE1NzcyMDExNDMwMTUxNzkyNA.GyqSdV.H5bxTCTKBG6kJP-B0HUaSTVIVE7FhJsk-MR8VM', {
    // Set the required intents to receive message & guild related events.
    intents: [ Intents.GUILD, Intents.GUILD_MESSAGES, Intents.GUILD_MEMBERS, Intents.MESSAGE_CONTENT ],
    sharding: {
      // The total number of shards that will be initialized.
      totalShards: 4
    }
  });
  await client.init();

  // Subscribe to the "ready" event.
  // ready event will be fired when all shards are connected.
  client.events.ready.subscribe(() => {
    console.log(`I logged in as (${client.user?.username})`);
  });

  // Subscribe to the "shardReady" event.
  client.events.shardReady.subscribe((shard) => {
    console.log(`Shard connected: ${shard.id}`);
  });

  // Subscribe to the "messageCreate" event.
  client.events.messageCreate.subscribe(async (message) => {
    // Ignore the command if is exectued by a Bot.
    if(message.author.bot) return;

    if(message.content == '!ping') {
      // Send a message referencied by the author message.
      // client.shards.ping is an average of the ping of all connected shards, in this case a single shard.
      return await message.sendReference(`My ping is: \`${client.shards.ping}\`ms`);
    }
  });
})();

Clusterized sharding

import { ClusterManager, Intents } from 'cordium.js';

(async () => {
  // Instead of instantiating a normal Client, we will instantiate the ClusterManager
  const manager = new ClusterManager('MTE1NzcyMDExNDMwMTUxNzkyNA.GyqSdV.H5bxTCTKBG6kJP-B0HUaSTVIVE7FhJsk-MR8VM', {
    // Set the required intents to receive message & guild related events.
    intents: [ Intents.GUILD, Intents.GUILD_MESSAGES, Intents.GUILD_MEMBERS, Intents.MESSAGE_CONTENT ],
    sharding: {
      // The total number of shards that will be initialized.
      // Must be greater than the number of workers
      totalShards: 4
    },
    clustering: {
      // The total number of workers that will be spawned.
      // Keep in mind that each worker (cluster) will have a specific number of shards and this number is measured as follows
      // (totalShards / totalWorkers) This means that the number of shards will be divided among all workers, therefore, there cannot be more workers than shards
      totalWorkers: 2
    }
  });
  await manager.init();

  // This event will be fired whenever a worker is spawned and will return an instance of ClusterClient
  // a ClusterClient is just an extended Client class that contains some new properties
  manager.events.workerSpawned.subscribe(async (client) => {
    // Subscribe to the "ready" event.
    // ready event will be fired when all shards are connected.
    client.events.ready.subscribe(() => {
      console.log(`I logged in as (${client.user?.username}) (PID=${process.pid})`);
    });

    // Subscribe to the "shardReady" event.
    client.events.shardReady.subscribe((shard) => {
      console.log(`Shard connected: ${shard.id}/PID = ${process.pid}`);
    });

    // Subscribe to the "messageCreate" event.
    client.events.messageCreate.subscribe(async (message) => {
      // Ignore the command if is exectued by a Bot.
      if(message.author.bot) return;

      if(message.content == '!ping') {
        // Send a message referencied by the author message.
        // client.shards.ping is an average of the ping of all connected shards, in this case a single shard.
        return await message.sendReference(`My ping is: \`${client.shards.ping}\`ms \nMy PID: \`${process.pid}\``);
      }
    });

    // You need to initialize the client
    await client.init();
  });
})();

Roadmap

  • [x] Support basic socket connection
  • [x] Sharding support
  • [x] Cluster support
  • [ ] Support all API classes & types
  • [ ] Support voice
  • [ ] Support HTTPS clients
  • [ ] Be zero-dependency
  • [ ] Support on browsers
  • [ ] Support plugins

Contributors