Good coding practices

Use Libs

BB have good libs. 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 before All command:
1
// Before all command - @
2
​
3
// set your ADMIN_ID here
4
// you can get it via Bot.sendMessage(user.id)
5
var isAdmin = ( user && (user.id == ADMIN_ID) )
6
​
7
if((command.folder=="Admin Panel")&&(isAdmin){
8
// only admin can run command from Admin Panel's folder
9
// any common bjs here for admin
10
Bot.sendMessage("Hello, admin!")
11
}else{
12
Bot.sendMessage("Access denied");
13
return // exit from command now
14
}
15
​
16
// other example
17
if(command.folder=="Under development"){
18
Bot.sendMessage("Sorry this command on development")
19
}
Copied!

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:
​
Last modified 26d ago