Skip to content

Commit

Permalink
Add help interface
Browse files Browse the repository at this point in the history
Signed-off-by: Prince Mendiratta <prince.mendi@gmail.com>
  • Loading branch information
Prince-Mendiratta committed Sep 25, 2021
1 parent 4bc315c commit 0bad2b9
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 10 deletions.
16 changes: 12 additions & 4 deletions BotsApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,22 @@ async function main() {
// if(BotsApp.chatId === "917838204238@s.whatsapp.net" && BotsApp.fromMe === false){ client.sendMessage(BotsApp.chatId, chat.message.imageMessage.jpegThumbnail, MessageType.image);}
if(BotsApp.isCmd){
const command = commandHandler.get(BotsApp.commandName);
if(!command){
client.sendMessage(BotsApp.chatId, "Woops, incorrect command! Use .help for command list.", MessageType.text);
return;
}
var args = BotsApp.body.trim().split(/\s+/).slice(1);
console.log("ARGS -> " + args);
args.forEach(arg => console.log("arg -> " + arg + " type -> " + typeof(arg)));
console.log("-------------------------------------------")
if(!command){
client.sendMessage(BotsApp.chatId, "Woops, incorrect command! Use .help for command list.", MessageType.text);
return;
}else if (command && BotsApp.commandName == "help"){
try{
command.handle(client, chat, BotsApp, args, commandHandler);
return;
}catch(err){
console.log(chalk.red("[ERROR] ", err));
return;
}
}
try{
command.handle(client, chat, BotsApp, args);
}catch(err){
Expand Down
2 changes: 1 addition & 1 deletion core/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ exports.resolve = function(messageInstance, client, groupMetadata) {
BotsApp.isReply = BotsApp.mimeType === 'extendedTextMessage';
// BotsApp.replyMessage = (BotsApp.isReply && messageInstance.message.extendedTextMessage.contextInfo) ? messageInstance.message.extendedTextMessage.contextInfo.quotedMessage.conversation : ''; TO DO - replied to an extended text
BotsApp.replyParticipant = (BotsApp.isReply && messageInstance.message.extendedTextMessage.contextInfo) ? messageInstance.message.extendedTextMessage.contextInfo.participant : '';
BotsApp.body = BotsApp.mimeType === 'conversation' ? messageInstance.message.conversation : (BotsApp.mimeType == 'imageMessage') ? messageInstance.message.imageMessage.caption : (BotsApp.mimeType == 'videoMessage') ? messageInstance.message.videoMessage.caption : (BotsApp.mimeType == 'extendedTextMessage') ? messageInstance.message.extendedTextMessage.text : '';
BotsApp.body = BotsApp.mimeType === 'conversation' ? messageInstance.message.conversation : (BotsApp.mimeType == 'imageMessage') ? messageInstance.message.imageMessage.caption : (BotsApp.mimeType == 'videoMessage') ? messageInstance.message.videoMessage.caption : (BotsApp.mimeType == 'extendedTextMessage') ? messageInstance.message.extendedTextMessage.text : (BotsApp.mimeType == 'buttonsResponseMessage') ? messageInstance.message.buttonsResponseMessage.selectedDisplayText :'';
BotsApp.isCmd = prefixRegex.test(BotsApp.body);
BotsApp.commandName = BotsApp.isCmd ? BotsApp.body.slice(1).trim().split(/ +/).shift().toLowerCase() : '';
BotsApp.isImage = BotsApp.type === "image";
Expand Down
13 changes: 13 additions & 0 deletions lib/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ const data = {
"Enter a valid contact number. Valid syntax,\n 1. XXXXXXXXXX\n 2. Tag the person\n 3. +YYXXXXXXXXXX (YY- Country Code, without zeros)",
MESSAGE_NOT_TAGGED: "Tag a message or enter a number",
},
alive: {
DESCRIPTION: "Check if bot is online.",
EXTENDED_DESCRIPTION: "```This module can be used to check if the bot is currently online or not.```\n\n*Example usage,*\n```.alive```",
ALIVE_MSG: "I'm alive, {}."
},
add: {
DESCRIPTION: "Module to add a person to a group.",
EXTENDED_DESCRIPTION: "Use this module to add people to a group. You can enter the person's mobile number. *Valid Syntaxes -*\n1. XXXXXXXXXX\n2. YYXXXXXXXXXX ()\n\nFor example -\n```.add 9861212121```",
Expand All @@ -23,6 +28,14 @@ const data = {
"Enter a valid contact number. Valid syntax,\n 1. XXXXXXXXXX\n 2. Tag the person\n 3. +YYXXXXXXXXXX (YY- Country Code, without zeros)",
MESSAGE_NOT_TAGGED: "Tag a message or enter a number",
},
help: {
DESCRIPTION: "Get the command list and info on modules.",
EXTENDED_DESCRIPTION: "This module is used to get info on other modules and their triggers.",
HEAD: "🌀 *BotsApp Menu* 🌀\n```Use .help command for detailed info on a module.```",
TEMPLATE: "\n\n🤖 *Command* - ```{}```\n💡 *Info* - ```{}```",
COMMAND_INTERFACE: "🌀 *BotsApp Command Interface* 🌀\n\n",
COMMAND_INTERFACE_TEMPLATE: "💠 *Triggers -* ```{}```\n📚 *Info -* {}"
}
};

module.exports = data;
41 changes: 41 additions & 0 deletions modules/help.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const { MessageType } = require("@adiwajshing/baileys");
const Strings = require("../lib/db");
const format = require('python-format-js');
const config = require('../config')
const HELP = Strings.help

module.exports = {
name: "help",
description: HELP.DESCRIPTION,
extendedDescription: HELP.EXTENDED_DESCRIPTION,
async handle(client, chat, BotsApp, args, commandHandler){
var prefixes = /\/\^\[(.*)+\]\/\g/g.exec(config.PREFIX)[1];
console.log("arguments -> ");
if(!args[0]){
console.log("Inside loop.")
var helpMessage = HELP.HEAD;
commandHandler.forEach(element => {
helpMessage += HELP.TEMPLATE.format(prefixes[0] + element.name, element.description);
});
client.sendMessage(BotsApp.chatId, helpMessage, MessageType.text);
return;
}
var helpMessage = HELP.COMMAND_INTERFACE;
var command = commandHandler.get(args[0]);
if(command){
var triggers = " | "
prefixes.split("").forEach(prefix => {
triggers += prefix + command.name + " | "
});
helpMessage += HELP.COMMAND_INTERFACE_TEMPLATE.format(triggers, command.extendedDescription);
const buttonMessage = {
contentText: helpMessage,
buttons: [{buttonId: 'id1', buttonText: {displayText: '.alive'}, type: 1}],
headerType: 1
}
client.sendMessage(BotsApp.chatId, buttonMessage, MessageType.buttonsMessage);
return;
}
client.sendMessage(BotsApp.chatId, HELP.COMMAND_INTERFACE + "*Invalid Command. Check the correct name from* ```.help``` *command list.* ", MessageType.text);
}
}
9 changes: 5 additions & 4 deletions modules/id.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
const { MessageType } = require("@adiwajshing/baileys")
const Strings = require("../lib/db")
const ID = Strings.add
const format = require('python-format-js');
const alive = Strings.alive

module.exports = {
name: "alive",
description: ID.DESCRIPTION,
extendedDescription: ID.EXTENDED_DESCRIPTION,
description: alive.DESCRIPTION,
extendedDescription: alive.EXTENDED_DESCRIPTION,
async handle(client, chat, BotsApp, args){
client.sendMessage(BotsApp.from, ID.EXTENDED_DESCRIPTION, MessageType.text);
client.sendMessage(BotsApp.chatId, alive.ALIVE_MSG.format("Prince"), MessageType.text);
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@adiwajshing/baileys": "^3.5.0",
"axios": "^0.21.4",
"chalk": "^4.1.1",
"dotenv": "^10.0.0"
"dotenv": "^10.0.0",
"python-format-js": "^1.3.9"
}
}

0 comments on commit 0bad2b9

Please sign in to comment.