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

discordial

v1.0.5

Published

A Discord framework using IoC architecture.

Downloads

8

Readme

Discordial

Discordial is a framework for building Discord bots. It makes use of the advantages of TypeScript and combines elements of OOP (Object Oriented Programming) and FP (Functional Programming).

Discordial is built uisin the IoC (Inversion of Control) design pattern, and focus on modularity and ease of use. Adding functionality to your bot is as easy as downloading a packaging and writing a single line of code.

Example

Discordial works by registering plugins during your Discordial configuration. Therefore, adding more functionality is as easy as registering more plugins.

import { Discordial } from "discordial";
import { PrefixPlugin } from "./prefix/prefix.plugin";

const token = "your discord bot token";
const discordial = new Discordial(token, {
  plugins: [PrefixPlugin] // <= PrefixPlugin is now registered.
});

Now let's take a look at what PrefixPlugin looks like. A Discordial Plugin is the controller which maps discord events to functions using the @BindEvent() decorator. A Discordial Plugin takes the @DiscordialPlugin() decorator at the top.

// src/prefix/prefix.plugin.ts
import { Message } from "discord.js";
import { DiscordialPlugin, BindEvent, DiscordEvents, Inject, Message, SyntheticMessage } from "discordial";
import { PrefixService } from "./prefix.service";

@DiscordialPlugin()
export class PrefixPlugin {
  constructor(
    // Discordial will instantiate and manage your services for you.
    @Inject(PrefixService) private readonly prefixService: PrefixService,
  ) {}

  // `replyWithPong()` will be called on every new message.
  @BindEvent(DiscordEvents.MESSAGE)
  public replyWithPong(
    // You can inject synthetic objects with the help of decorators:
    @Message() syntheticMessage: SyntheticMessage,
    // Or simply get the default parameters from the listener:
    message: Message,
  ) {
    this.prefixService.replyWithPong(syntheticMessage);
  }
}

Services can be used to separate concerns and create scalable applications. To declare a service, use the @Injectable() decorator. Let's take a look at our PrefixService.

import { Injectable, SyntheticMessage } from "discordial";

@Injectable()
export class PrefixService {
  private readonly _prefix = "!";

  private isValid(message: SyntheticMessage, command: string): boolean {
    if (!message.content.startsWith(this._prefix + command))
      return false;
    return !message.author.bot;
  }

  public replyWithPong(message: SyntheticMessage): void {
    if (!this.isValid(message, "ping"))
      return;
    message.reply("pong");
  }
}

Features

  • Built using the IoC design pattern.

  • Shares similarities with AngularJS and NestJS. If you have experience with any of those frameworks, Discordial becomes that much easier to use.

  • Synthetic objects: Discordial offers custom interfaces for manipulating the event parameters with improved functionality. Synthetic objects can also be replaced by awesome community made creations. ~~Well, not yet... but that's the plan! :)~~