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

globcommands

v0.1.6

Published

GlobCommands is a new handler with some extra capabilities and features that will be expanding overtime for Discord.js v14 bots.

Downloads

11

Readme

What is GlobCommands?

GlobCommands is a new handler with some extra capabilities and features that will be expanding overtime for Discord.js v14 bots.

Important note: This handler is made entirely for TYPESCRIPT, JavaScript might not work properly.

What are the features of this handler?

  • Reload of events and commands
  • Logging
  • Database Accessing to PocketBase (It will be expanded in the future)
  • Custom methods for defining the client
  • Everything divided into files to better understanding of the code

How do I use GlobCommands?

Starting the bot

First, you will need to create a init file, could be name whatever you want, but would be the one starting the bot. In my case I'll name it as: bot.ts

bot.ts

import { GlobClient, DbEngine } from 'globcommands'
// The DBEngine is an Enum that comes with globcommands to help you define the dbengine supported by globcommands

export const client = new GlobClinet(
  YOUR_TOKEN,
  {
    intents: ['YOUR_INTENTS'],
    partials: ['YOUR_PARTIALS'],
  },
  YOUR_GUILDID[DB_ENGINE] // In case your testing // This one is not needed if you don't want to use a Database Engine of any sort
)

client.start()

With that the bot will start.

How do I create commands?

The commands have a simple sintax to use.

  1. Create a src folder
  2. Inside that src folder, create two new ones, commands and events.
  3. (Optional) You can separate the commands by categories creating them inside each folder individually.

Now, when we have this, let's create a new file inside the folder commands:

(Doesn't need to be like this, can be only ping.ts or whatever) ping.command.ts

module.exports = {
  name: 'ping', // Name of the command
  description: 'Simple ping command', // Description of the command
  // Run function
  run: async ({ interaction }) => {
    interaction.reply({ content: 'Pong!', ephemeral: true }) // Callback of the function
  },
}

This will not work until you create an event handling the interactions, so let's create the interactionCreate event.

interactionCreate.event.ts

import { CommandInteractionOptionResolver } from 'discord.js'
import { ExtendedInteraction } from 'globcommands'
import { client } from '../../bot'
module.exports = {
  event: 'interactionCreate',
  run: async (interaction) => {
    if (interaction.isCommand()) {
      const command = client.commands.get(interaction.commandName)
      if (!command) {
        return interaction.reply('This command is not found.')
      }
      if (command.developer && interaction.user.id != '372840998918684672') {
        return interaction.reply({
          content: 'You can not use this command, is a developer command.',
          ephemeral: true,
        })
      }
      command.run({
        args: interaction.options as CommandInteractionOptionResolver,
        client,
        interaction: interaction as ExtendedInteraction,
      })
    }
  },
}

and now the ready event, making use of the logger that comes with globcommands

ready.event.ts

import { logger } from 'globcommands'

module.exports = {
  event: 'ready',
  once: true, // Only run this one once, you can remove it to do it more than 1 time
  run: async () => {
    logger.info('✅ Bot is up and ready!', { service: 'Bot' })
  },
}

But Slimy, why not making a ESM as TypeScript works with that?

Well, this is interesting, during the development I encounter a thing.

We all know that ESM modules makes use of import {} from 'package', but in order to make the reloading capabilities I wanted to do in the handler, this didn't work. Why?

Let me explain: The import statement, by design, doesn't let you access the cache of each import, is unnaccesible and inmutable.

So instead I needed to use the require(), which has a function to access the cache and clean it to refresh the files imported.

That's why I don't make use of ESM modules in this case.

FAQ

I found a Bug!!

:O OH NO, Report it to me!

I want this feature in

Let me be bold as I can be, I don't take requests in this case, you will need to wait until I want to implement something else or your feature if I want to.

(This section can be expanded in the future.)