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

discbot-factory

v2.2.0

Published

Discord chat bot pre-builded core.

Downloads

8

Readme

DISCBOT-FACTORY

A helper tool to create discord bots with discord.js.

Pre builded modules like queue and voice. Simple implementations ways.

Creating a instance

// src/index.ts

import { Core } from "discbot-factory";

const bot: Core = new Core("<bot-name>", "<prefix>", {});

bot.authClient("<token>");

Creating commands

// src/commands/HelloWorldCommand.ts

import { ICommand, Command } from "discbot-factory";

export default class HelloWorldCommand implements ICommand {
  public readonly name: string = "hello"; // execute with <prefix>hello "!hello"
  public readonly description: string = "The hello world command";

  public execute(command: Command): void { 
    const author: string = command.message.author.username;

    command.message.channel.send(`Hello world, ${author}!`);
  }
}

Registering commands

// src/index.ts

import { Core } from "discbot-factory";

import HelloWorldCommand from "./commands/HelloWorldCommand";

const bot: Core = new Core("<bot-name>", "<prefix>", {
  commands: [new HelloWorldCommand()],
  middlewares: [],
  events: [],
});

bot.authClient("<token>");

Modules

Voice

A pre-builded voice module for create voice channel interactions.

import { Voice } from "discbot-factory";

const voice: Voice = new Voice("youtube"); // local or youtuber player.

async function playMusic(voiceChannel: VoiceChannel): Promise<void> {
  await voice.connect(voiceChannel);
  // if you are using local player, just pass the sound path.
  await voice.play("https://www.youtube.com/watch?v=mH_z5vAkf2c");

  voice.onEnd((): void => {
    console.log("Finished!");
  });
}

Queue

A queue module, nice to use with voice module and to create cool experiences like mini-games.

import { Queue } from "discbot-factory";

const queue: Queue<string> = new Queue<string>();

queue.putOnTop("hello");
queue.putOnBottom("oh no, I'm the last");

// get the first item
console.log(queue.get()) // hello

queue.removeHead();

console.log(queue.get()) // oh no, I'm the last

queue.clear();

console.log(queue.getAll()); // []

Public events

Equivalent to a client.on("event", callback) implementation.

import { IEvent, PublicEvent } from "discbot-factory";

import { Message } from "discord.js";

export default class MessageDeleteEvent implements IEvent<Message, {}, {}> {
  public readonly name: PublicEvent = PublicEvent.MESSAGE_DELETE;
  public readonly description: string = "On message delete event";

  public execute(message: Message): void {
    console.log(message.content);
  }
}

Using Middlewares

import IMiddleware from "../Core/IMiddleware";
import { Command } from "../Core/ICommand";

export default class AdminMiddleware implements IMiddleware {
  constructor(public readonly forCommands: Array<string>) {}

  public middle(command: Command): boolean {
    const username: string = command.message.author.username;

    if (username === "another dan") {
      return true;
    }

    command.message.react("🚫");
    return false;
  }
}