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

droff

v0.43.6

Published

Simple Discord client powered by RxJS and Axios

Downloads

30

Readme

Discord

Simple Discord client powered by RxJS and Axios

  • API documentation: https://tim-smart.github.io/droff/droff/

Note: Looking for a Discord library that is more functional in nature?
Check out: https://github.com/tim-smart/dfx

Goals

  • Lightweight - Simple Axios wrapper for the REST API with a lean Gateway API wrapper powered by RxJS.
  • Functional - Favour functional composition over inheritence.
  • Scalable - Every component of the library can be scaled seperately, allowing for easy horizontal distribution of your bot.

Packages

| Name | Description | | ---------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | | droff | The core Discord client library | | droff-interactions | Accompanying library for interaction based components (slash commands, buttons, menus, selects etc) | | droff-commands | Accompanying library to help implementing message based commands | | droff-helpers | A collection of helper functions to make using droff easier | | droff-redis | An implementation of a Redis powered gateway proxy, cache store and rate limit store |

Install

yarn add droff

Usage

Basic ping example. Look at droff-interactions and droff-commands for examples that work with slash commands etc.

Please note that you have to subscribe to client.effects$ for the client to function. This essentially starts the client.

import { createClient, Intents } from "droff";
import * as Rx from "rxjs";
import * as RxO from "rxjs/operators";

const client = createClient({
  token: process.env.DISCORD_BOT_TOKEN!,
  gateway: {
    intents: Intents.GUILD_MESSAGES,
  },
});

const pings$ = client.fromDispatch("MESSAGE_CREATE").pipe(
  RxO.filter((msg) => msg.content === "!ping"),
  RxO.flatMap((msg) =>
    client.createMessage(msg.channel_id, {
      message_reference: { message_id: msg.id },
      content: "Pong!",
    }),
  ),
);

// Subscribe to our side effects
Rx.merge(client.effects$, pings$).subscribe();

Gateway proxy

Larger bots may want to seperate the websocket handling from the bot logic, for zero downtime deployments.

To do this you would pipe the gateway dispatch events into a event streaming tool, like Apache Kafka or Rabbitmq, then subscribe to the events in your bot logic.

See example/gateway-proxy.ts for an example.

Also see the Redis example.

REST proxy

Larger bots may want to funnel all Discord HTTP requests through a single proxy server, to simplify rate limiting.

See example/proxy.ts for an example.

Caching

Droff will only activate the caches that you use. So by default nothing is cached.

To use a cache, you call one of the cache factory methods, optionally passing in a store implementation.

import * as Rx from "rxjs";
import { createClient, Intents } from "../src/mod";

const client = createClient({
  token: process.env.DISCORD_BOT_TOKEN!,
  gateway: {
    // You will need to enable some intents for the corresponding cache.
    intents: Intents.GUILD_EMOJIS | Intents.GUILD_MEMBERS,
  },
});

const [roleCache, roleCacheEffects$] = client.rolesCache();

// Subscribe to the cache effects if you want to populate the cache from the
// gateway events
Rx.merge(client.effects$, roleCacheEffects$).subscribe();

// You can then use the cache:
roleCache.getForParent("guild id xxx").then((map) => map.get("role id xxx"));

What's missing

Just a heads up that is a relatively new client library. You should note that:

  • There isn't much documentation
  • There isn't anything implemented for Voice channels
  • Some caches will be missing
  • No benchmarking / optimization has been done at this point

Pull requests are more than welcome :)