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

bot-cmd

v1.4.1

Published

Discord Bot Boilerplate

Downloads

12

Readme

What it does

It's a discord and firebase boilerplate (the base code) combined with a really cool command handler and a few extra features

How to setup

let bot = require("bot-cmd")(TOKEN, FIREBASE_TOKEN, OPTIONS)
//no need for bot.on("message", ...)
bot.set({
  prefix: "p!", //supports regex
  pingHint: "Message to say when bot gets pinged",
  errorHint: "Message to say when error occurs"
})

Basic Usage

bot.cmd("ping", function(msg){ //Use bot.cmd for commands with prefix
  msg.reply("Pong!")
}
bot.cmd("say :str", function(msg, string){ //parameter
  msg.channel.send(string)
})
bot.cmd("xp", function(msg){
  msg.channel.send("Level of user: "+this.user.level)
  //"this" is an object containing useful data such as user data
  // and guild data
})
bot.cmd("avatar :user", function(msg, user){
  //automatically converts parameter to a user object
  if(user){
    msg.channel.send(user.avatarURL({size:256}))
  }else{
    msg.channel.send("Couldn't find user")
  }
})
bot.cmd("total ::int",function(msg, nums){
  //:: means a spread parameter (the rest of parameters)
  //so "p!total 1 2 3" will make "nums" be [1,2,3]
  msg.reply(`The total is ${nums.reduce( (a,b)=>a+b )}`)
}
bot.cmd(":", function(msg, a){ //: is wildcard: it means any type
  //note that wildcards work like the ::
  //you can't have anything else after it

  //we can use this as a fallback for an invalid command
  msg.reply("Invalid command lol")
})
bot.msg(":int", function(msg, num){ //bot.msg = prefix-less command
  //counting command, I'll let you code it yourself!
  return true; //returning true will allow other commands to run
  //(if there are any other matching commands)
})
/*
Note: handlers run top-to-bottom,
by default, only the first applicable handler runs per message. Make a handler "transparent" (won't block other handlers) by returning true
bot.cmd("...", function(...){
  ...
  return true;
})
You can add your own types using this function:
bot.type(/regexToMatch/, (string, msg) => parseType(string))
*/

this

this refers to an object which contains user, the userdata (from firebase), guild (the guilddata from firebase) and member (guild-specific user data) any modifications to this is tied to the message (it will be available to all other handlers for this specific message). This feature can be used to calculate data before a command is ran, instead of calculating it for every command. Example:

bot.msg(":", function(msg){ //for every command used
  this.userLevel = this.user.xp / 1000
  this.authorIsAdmin = (msg.author.id == "123456789123456789")
  return true //If you don't return true no other command handler can run after this one
})
...
bot.cmd("ban :user", function(msg, user){ //example command
  if(this.authorIsAdmin){
    //ban the user
  }
})

To install firebase (for user/guild data), run npx bot-i after having installed this module

Supported types

:int - an integer (series of digits)

:num - any number, including decimals

:str - string (text)

Note: to have spaces in a string when using the command, put the quotes around the string (for example, p!say "hello world")

:bool - a boolean, supports yes/no, true/false, 1/0, but we convert it to a regular boolean for you

:user - a discord user, or null if it's invalid

:member - same as user, except they must be in the guild

:channel - a discord channel, or null if it's invalid

:role - a role that's in the server

Issues

Extra features

bot.ai(text, channelID): Promise<string> - Chat AI (install module using npx bot-i)

OPTIONS (parameter):

{
  ai: bool, //Use bot.ai?
  member: bool, //Use this.member?
  user: bool, //Use this.user?
  guild: bool, //Use this.guild?
  clientOptions: Discord Client Options,
  svgProxy: string //https://svg.to.png/convert.png?svgCode=$
}