1.4.1 • Published 3 years ago

bot-cmd v1.4.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

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=$
}
1.4.1

3 years ago

1.4.0

3 years ago

1.3.9

3 years ago

1.3.8

3 years ago

1.3.5-hotfix3

3 years ago

1.3.7

3 years ago

1.3.6

3 years ago

1.3.6-hotfix

3 years ago

1.3.5-hotfix2

3 years ago

1.3.5

3 years ago

1.3.5-hotfix

3 years ago

1.3.4

3 years ago

1.3.3

3 years ago

1.3.2

3 years ago

1.3.1

3 years ago

1.3.2-hotfix

3 years ago

1.3.0

3 years ago

1.3.0-hotfix

3 years ago

1.2.9-hotfix

3 years ago

1.2.9

3 years ago

1.2.8

3 years ago

1.2.7

3 years ago

1.2.6

3 years ago

1.2.5

3 years ago

1.2.4

3 years ago

1.2.3

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.2.0

3 years ago

1.1.9

3 years ago

1.1.8

3 years ago

1.1.7

3 years ago

1.1.6

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago