Bots.Business - Help
  • Welcome
  • Getting started
  • Create bot from Google Table
  • App
    • Reset or Update Your Password
  • Commands
    • Answer
    • Aliases
    • Keyboard
    • Groups
    • Wait for answer
    • Auto Retry (AR)
  • Coding: BJS
    • Variables
    • Bot functions
    • Message broadcasting and editing
    • User functions
    • Properties
    • Always running commands
    • Error command: "!"
    • Lists
      • Migration from properties to list
    • Api functions
    • BB Admin functions
    • Admin Panel
    • Send HTTP request
    • Web App
    • Caching
    • Inline Bot
    • BJS Security
    • Good coding practices
    • Top errors
  • Git
    • Import bot from Git repository
    • Export bot to Git repository
    • Repository structure
    • File: bot.json
    • Automatic importing on Git push
  • Iterations. How to reduce theys?
  • Limitations
  • Cloud
  • Reports
  • Deep Linking - pass any params on Bot starting
  • How to link chat account with BB account?
  • BB Inspection
  • Protected bot
  • VS Code
  • How to...
  • Smart Bot
    • Overview
    • Lang File
    • SmartBot
    • SmartTasker
    • Amount Dialog
  • Libs
    • What it is - Libs?
    • Libs development
    • RefferalLib
    • ResourcesLib
    • Random
    • MembershipChecker (MCL)
    • Cooldown Lib
    • CurrencyConverter
    • Lang
    • TopBoardLib
    • QiwiPayments
    • Coinbase (CB)
    • CoinPayments (CP)
    • OxaPay
    • CryptoJS
    • CurrencyQuote
    • GoogleApp
    • GoogleTableSync
    • Guard
    • Webhooks lib
    • DateTimeFormat Lib
  • Store
    • BB Point Bot
    • Welcome bot
    • Help bot
    • SRB Demo Keyboard Tools
Powered by GitBook
On this page
  • Use Libs
  • Use folders
  • Use good names
  • Use simular names!
  • Use JSON property
  • Do not use many methods of getProperty or setProperty
  • Use functions!

Was this helpful?

  1. Coding: BJS

Good coding practices

PreviousBJS SecurityNextTop errors

Last updated 3 years ago

Was this helpful?

Use Libs

BB have good . Just install needed library to your bot.

Don't install unnecessary libraries. Your bot might be slow after that.

Use folders

You can organize your commands in folders.

You can use folder in BJS too. For example in command:

// Before all command - @

// set your ADMIN_ID here
// you can get it via Bot.sendMessage(user.id)
var isAdmin = ( user && (user.id == ADMIN_ID) )

if(!command){
   return
}

if((command.folder=="Admin Panel")&&(isAdmin){
  // only admin can run command from Admin Panel's folder
  // any common bjs here for admin
  Bot.sendMessage("Hello, admin!")
}else{
  Bot.sendMessage("Access denied");
  return // exit from command now
}

// other example
if(command.folder=="Under development"){
  Bot.sendMessage("Sorry this command on development")
}

Use good names

Do you have children.

Two boys and one girl. You do not call them b1, b2 ang g1, are you not ?

So why do you call your variables like that?

Bad examples:

  • x1

  • y2

  • d3

Good:

  • currentLimit

  • maxCount

  • userName

Use simular names!

Use JSON property

Bad code:

Good code:

Do not use many methods of getProperty or setProperty

Bad code:

Each getProperty method spent above 10-100 ms for execution. So if you have 10 getProperty methods bot can spent above 1 sec for execution! It is slowly

Use JSON type:

Use functions!

Do not repeat youself!

Bad code:

Good code:

libs
before All