├── .gitignore ├── .vscode └── launch.json ├── BotsApp.js ├── BotsApp.ts ├── CHANGELOG.md ├── Dockerfile ├── LICENSE ├── README.md ├── app.json ├── config.ts ├── core ├── clearance.ts ├── dbAuth.js ├── gitpull.ts └── helper.ts ├── database ├── auth.ts ├── blacklist.ts ├── greeting.ts └── user.ts ├── heroku.yml ├── images ├── BotsApp_Logo.png ├── BotsApp_invite.jpeg └── default_dp.png ├── lib ├── banner.ts ├── cpp.js ├── db.ts └── neko.js ├── modules ├── abl.ts ├── add.ts ├── admins.ts ├── alive.ts ├── block.ts ├── carbon.ts ├── cpp.bak ├── create.bak ├── decodeqr.ts ├── demote.ts ├── disappear.ts ├── getdp.ts ├── github.ts ├── goodbye.ts ├── help.ts ├── invite.ts ├── lyrics.ts ├── meaning.ts ├── mute.bak ├── news.ts ├── ocr.ts ├── promote.ts ├── qr.ts ├── quote.ts ├── rbl.ts ├── remove.ts ├── rename.ts ├── setdp.ts ├── song.ts ├── sticker.ts ├── stoi.ts ├── stov.ts ├── tagall.ts ├── translate.ts ├── tts.ts ├── unblock.ts ├── unmute.bak ├── urban-dictionary.ts ├── weather.ts ├── welcome.ts └── yt.ts ├── package.json ├── qr.js ├── sidekick ├── client.ts ├── command.ts ├── input-sanitization.ts ├── message-type.ts └── sidekick.ts ├── tmp └── placeholder ├── tsconfig.json ├── updater.ts └── yarn.lock /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | build/Release 4 | *.env 5 | .env.test 6 | tmp/* 7 | .vs/ 8 | .idea/ 9 | BotsApp.db 10 | yarn-error.log 11 | dist/ 12 | session.data.json 13 | auth -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "node", 9 | "request": "launch", 10 | "name": "Launch Program", 11 | "skipFiles": [ 12 | "/**" 13 | ], 14 | "program": "${workspaceFolder}/BotsApp.ts", 15 | "outFiles": ["${workspaceFolder}/dist/**/*.js"] 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /BotsApp.js: -------------------------------------------------------------------------------- 1 | const conn = require('./core/sessionString') 2 | const fs = require('fs') 3 | const { join } = require('path') 4 | const config = require('./config') 5 | const banner = require('./lib/banner'); 6 | const chalk = require('chalk'); 7 | const wa = require('./core/helper'); 8 | const { MessageType } = require('@whiskeysockets/baileys'); 9 | const Greetings = require('./database/greeting'); 10 | const sequelize = config.DATABASE; 11 | const STRINGS = require("./lib/db"); 12 | const Blacklist = require('./database/blacklist'); 13 | const GENERAL = STRINGS.general; 14 | // const gitPull = require('./core/gitpull'); 15 | const clearance = require('./core/clearance'); 16 | 17 | var client = conn.WhatsApp; 18 | 19 | async function main() { 20 | 21 | client.logger.level = 'error'; 22 | console.log(banner); 23 | var commandHandler = new Map(); 24 | try { 25 | var session = conn.restoreSession(config.STRING_SESSION) 26 | client.loadAuthInfo(session) 27 | } catch (err) { 28 | if (err instanceof TypeError || err.message === "given authInfo is null" || err instanceof SyntaxError) { 29 | console.log( 30 | chalk.redBright.bold("Incorrect Session String. Please authenticate again using command -> "), 31 | chalk.yellowBright.bold("npm start") 32 | ); 33 | console.debug("[DEBUG] " + err); 34 | fs.writeFileSync('./config.env', `STRING_SESSION=""`); 35 | process.exit(0); 36 | } 37 | else { 38 | console.log( 39 | chalk.redBright.bold("SOMETHING WENT WRONG.\n"), 40 | chalk.redBright.bold("[DEBUG] " + err) 41 | ); 42 | process.exit(0) 43 | } 44 | } 45 | 46 | client.on('connecting', async () => { 47 | console.log(chalk.yellowBright("[INFO] Connecting to WhatsApp...")); 48 | }) 49 | 50 | client.on('open', async () => { 51 | console.log(chalk.yellowBright.bold("[INFO] Installing Plugins... Please wait.")); 52 | var moduleFiles = fs.readdirSync(join(__dirname, 'modules')).filter((file) => file.endsWith('.js')) 53 | for (var file of moduleFiles) { 54 | try { 55 | const command = require(join(__dirname, 'modules', `${file}`)); 56 | console.log( 57 | chalk.magentaBright("[INFO] Successfully imported module"), 58 | chalk.cyanBright.bold(`${file}`) 59 | ) 60 | commandHandler.set(command.name, command); 61 | } catch (error) { 62 | console.log( 63 | chalk.blueBright.bold("[INFO] Could not import module"), 64 | chalk.redBright.bold(`${file}`) 65 | ) 66 | console.log(`[ERROR] `, error); 67 | continue; 68 | } 69 | } 70 | console.log(chalk.green.bold("[INFO] Plugins Installed Successfully. The bot is ready to use.")); 71 | console.log(chalk.yellowBright.bold("[INFO] Connecting to Database.")); 72 | try { 73 | await sequelize.authenticate(); 74 | console.log(chalk.greenBright.bold('[INFO] Connection has been established successfully.')); 75 | } catch (error) { 76 | console.error('[ERROR] Unable to connect to the database:', error); 77 | } 78 | console.log(chalk.yellowBright.bold("[INFO] Syncing Database...")); 79 | await sequelize.sync(); 80 | console.log(chalk.greenBright.bold("[INFO] All models were synchronized successfully.")); 81 | console.log(chalk.greenBright.bold("[INFO] Connected! Welcome to BotsApp")); 82 | client.sendMessage( 83 | client.user.jid, 84 | GENERAL.SUCCESSFUL_CONNECTION.format({ 85 | worktype: config.WORK_TYPE, 86 | }), 87 | MessageType.text 88 | ); 89 | }) 90 | 91 | 92 | await client.connect(); 93 | 94 | 95 | client.on('group-participants-update', async update => { 96 | // console.log("-------------------" + "GROUP PARTICIPANT UPDATE" + "-------------------"); 97 | // console.log(update.participants); 98 | // console.log(update.action); 99 | // console.log(update.jid); 100 | var groupId = update.jid; 101 | 102 | try { 103 | if (update.action === 'add') { 104 | var enable = await Greetings.checkSettings(groupId, "welcome"); 105 | if (enable === false || enable === "OFF") { 106 | return; 107 | } 108 | var Msg = await Greetings.getMessage(groupId, "welcome"); 109 | 110 | client.sendMessage(groupId, Msg.message, MessageType.text); 111 | return; 112 | } 113 | else if (update.action === 'remove') { 114 | var enable = await Greetings.checkSettings(groupId, "goodbye"); 115 | if (enable === false || enable === "OFF") { 116 | return; 117 | } 118 | var Msg = await Greetings.getMessage(groupId, "goodbye"); 119 | 120 | client.sendMessage(groupId, Msg.message, MessageType.text); 121 | return; 122 | } 123 | } 124 | catch (err) { 125 | // console.log("Greeting message are off"); 126 | } 127 | }); 128 | 129 | client.on('chat-update', async chat => { 130 | if (!chat.hasNewMessage) return 131 | if (!chat.messages) return 132 | // console.log("-------------------------------------------") 133 | chat = chat.messages.all()[0]; 134 | var sender = chat.key.remoteJid; 135 | const groupMetadata = sender.endsWith("@g.us") ? await client.groupMetadata(sender) : ''; 136 | var BotsApp = wa.resolve(chat, client, groupMetadata); 137 | // console.log(BotsApp); 138 | if (BotsApp.isCmd) { 139 | let isBlacklist = await Blacklist.getBlacklistUser(BotsApp.sender, BotsApp.chatId); 140 | const cleared = await clearance(BotsApp, client, isBlacklist); 141 | if (!cleared) { 142 | return; 143 | } 144 | console.log(chalk.redBright.bold(`[INFO] ${BotsApp.commandName} command executed.`)); 145 | const command = commandHandler.get(BotsApp.commandName); 146 | var args = BotsApp.body.trim().split(/\s+/).slice(1); 147 | // console.log("ARGS -> " + args); 148 | // args.forEach(arg => console.log("arg -> " + arg + " type -> " + typeof(arg))); 149 | // console.log("-------------------------------------------") 150 | if (!command) { 151 | client.sendMessage(BotsApp.chatId, "```Woops, invalid command! Use``` *.help* ```to display the command list.```", MessageType.text); 152 | return; 153 | } else if (command && BotsApp.commandName == "help") { 154 | try { 155 | command.handle(client, chat, BotsApp, args, commandHandler); 156 | return; 157 | } catch (err) { 158 | console.log(chalk.red("[ERROR] ", err)); 159 | return; 160 | } 161 | } 162 | try { 163 | command.handle(client, chat, BotsApp, args).catch(err => console.log("[ERROR] " + err)); 164 | } catch (err) { 165 | console.log(chalk.red("[ERROR] ", err)); 166 | } 167 | } 168 | }) 169 | } 170 | 171 | main().catch(err => console.log('[ERROR] : %s', chalk.redBright.bold(err))); 172 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | All notable changes to this add-on will be documented in this file. 3 | 4 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and 5 | this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 6 | 7 | ## [Unreleased] 8 | 9 | ## [1.1.0] - 2021-12-12 10 | ### Added 11 | - Disable the bot in support group #1 and support group #2. 12 | - Ability to blacklist certain people / chats from using the bot in public mode. 13 | - Generate invite link to invite people who cannot be added directly. 14 | - Rename and resend file directly on WhatsApp. 15 | - Create groups with the tagged person directly. 16 | - Execute C++ code and get output directly on WhatsApp. 17 | - Search for meaning in the dictionary for a word. 18 | - Create QR code from text. 19 | - Decode QR code to extract text. 20 | 21 | ### Changed 22 | - Removed case sensitivity issue for WORK_TYPE. 23 | - The getdp module can now get profile pictures of a tagged person as well. 24 | - Improved the lyrics search module. 25 | - Make the permission check asynchronous. 26 | - Switch back to stable version of baileys. 27 | 28 | ## [1.0.1] - 2021-11-15 29 | ### Added 30 | - Pull latest changes from the repo before starting the bot. 31 | - Automatically install new packages, if any, in case of new updates. 32 | 33 | ### Changed 34 | - Elevate tagall command to admin only. 35 | - Mention the license in readme. 36 | - Improve command detection regex to avoid triggering just prefix as a command. 37 | - Fix minor typos. 38 | - Private / Public acknowledgement message only sent once in each group. 39 | - Fix the bug where bot wasn't working in new groups. 40 | 41 | ## [1.0.0] - 2021-11-07 42 | ### Added 43 | - Initial Release 44 | 45 | [Unreleased]: https://github.com/Prince-Mendiratta/BotsApp/compare/v1.1.0...HEAD 46 | [1.1.0]: https://github.com/Prince-Mendiratta/BotsApp/releases/tag/v1.1.0 47 | [1.0.1]: https://github.com/Prince-Mendiratta/BotsApp/releases/tag/v1.0.1 48 | [1.0.0]: https://github.com/Prince-Mendiratta/BotsApp/releases/tag/v1.0.0 -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM princemendiratta/botsapp:latest 2 | 3 | WORKDIR / 4 | 5 | COPY . /BotsApp 6 | 7 | WORKDIR /BotsApp 8 | 9 | RUN git init --initial-branch=multi-device 10 | 11 | RUN git remote add origin https://github.com/Prince-Mendiratta/BotsApp.git 12 | 13 | RUN git fetch origin multi-device 14 | 15 | RUN git reset --hard origin/multi-device 16 | 17 | RUN yarn 18 | 19 | # RUN cp -r /root/Baileys/lib /BotsApp/node_modules/@whiskeysockets/baileys/ 20 | 21 | CMD [ "npm", "start"] -------------------------------------------------------------------------------- /app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "BotsApp", 3 | "description": "The most user friendly and easy to use WhatsApp bot.", 4 | "logo": "https://i.imgur.com/xw9lULI.jpg", 5 | "keywords": [ 6 | "Whatsapp", 7 | "WhatsApp bot", 8 | "userbot", 9 | "BotsApp", 10 | "nodejs", 11 | "WhatsApp Multi Device", 12 | "WhatsApp Multi Device bot" 13 | ], 14 | "repository": "https://github.com/Prince-Mendiratta/BotsApp", 15 | "website": "https://mybotsapp.com", 16 | "success_url": "", 17 | "stack": "container", 18 | "env": { 19 | "STRING_SESSION": { 20 | "description": "Your BotsApp session. Can be obtained via website or running npm start locally.", 21 | "value": "", 22 | "required": true 23 | }, 24 | "HEROKU": { 25 | "description": "Is the bot running on heroku? If you're seeing this, then probably it's true.", 26 | "value": "true", 27 | "required": false 28 | }, 29 | "PREFIX": { 30 | "description": "Regex pattern for the prefix. Leave default if you are not sure about this.", 31 | "value": "^[.?!]", 32 | "required": false 33 | }, 34 | "COUNTRY_CODE": { 35 | "description": "The default country code to be used in modules.", 36 | "value": "91", 37 | "required": false 38 | }, 39 | "OCR_API_KEY": { 40 | "description": "API key for using OCR (Optical Character Recognition) module. You can obtain this for free from https://ocr.space/", 41 | "value": "", 42 | "required": false 43 | }, 44 | "WEATHER_API_KEY": { 45 | "description": "API key for using weather module. You can obtain this for free from https://openweathermap.org/", 46 | "value": "", 47 | "required": false 48 | }, 49 | "DEBUG": { 50 | "description": "Set this to true to see detailed logs.", 51 | "value": "false", 52 | "required": false 53 | }, 54 | "WORK_TYPE": { 55 | "description": "Which mode should the bot work in? In private mode, only the bot number and sudo users can use the bot.", 56 | "value": "private", 57 | "required": false 58 | }, 59 | "SUDO": { 60 | "description": "List down the phone numbers in international format, separated by commas, who should have permission to use the bot. For example -> 917838xxxxxx,1875xxxxxxxx", 61 | "value": "", 62 | "required": false 63 | } 64 | }, 65 | "addons": [ 66 | { 67 | "plan": "heroku-postgresql", 68 | "options": { 69 | "version": "13" 70 | } 71 | } 72 | ], 73 | "formation": { 74 | "botsapp": { 75 | "quantity": 1, 76 | "size": "free" 77 | } 78 | } 79 | } -------------------------------------------------------------------------------- /config.ts: -------------------------------------------------------------------------------- 1 | import fs from 'fs'; 2 | import { Sequelize } from 'sequelize'; 3 | 4 | if (fs.existsSync('config.env')) { 5 | require('dotenv').config({ path: './config.env' }); 6 | } else { 7 | require('dotenv'); 8 | } 9 | 10 | const convertToLogLevel = (value: string) => { 11 | var log: any = false; 12 | if (typeof value === "string") { 13 | if (value.toLowerCase() === "true") { 14 | log = console.log; 15 | } 16 | } 17 | return log; 18 | } 19 | 20 | // Declare these environment variables first 21 | process.env.DATABASE_URL = process.env.DATABASE_URL === undefined ? './BotsApp.db' : process.env.DATABASE_URL; 22 | process.env.DEBUG = process.env.DEBUG === undefined ? 'false' : process.env.DEBUG; 23 | 24 | const config = { 25 | NEWS_API_URL: process.env.NEWS_API_URL === undefined ? "http://43.204.197.96:8080/" : process.env.NEWS_API_URL, 26 | STRING_SESSION: process.env.STRING_SESSION === undefined ? '' : process.env.STRING_SESSION, 27 | HEROKU: process.env.HEROKU === undefined ? false : true, 28 | PREFIX: process.env.PREFIX === undefined ? "^[.?!]" : process.env.PREFIX, 29 | COUNTRY_CODE: process.env.COUNTRY_CODE === undefined ? "91" : process.env.COUNTRY_CODE, 30 | OCR_API_KEY: process.env.OCR_API_KEY === undefined ? "9ffb44def388957" : process.env.OCR_API_KEY, 31 | WEATHER_API_KEY: 32 | process.env.CURRENT_WEATHER_API_KEY === undefined 33 | ? "6729ac2b2e2bb5c686ff427a2f06df92" 34 | : process.env.CURRENT_WEATHER_API_KEY, 35 | DATABASE_URL: process.env.DATABASE_URL === undefined ? './BotsApp.db' : process.env.DATABASE_URL, 36 | DEBUG: process.env.DEBUG === undefined ? false : process.env.DEBUG, 37 | DATABASE: process.env.DATABASE_URL === './BotsApp.db' ? new Sequelize({ dialect: "sqlite", storage: process.env.DATABASE_URL, logging: convertToLogLevel(process.env.DEBUG) }) : new Sequelize(process.env.DATABASE_URL, { dialect: 'postgres', protocol: 'postgres', logging: convertToLogLevel(process.env.DEBUG), dialectOptions: { ssl: { require: true, rejectUnauthorized: false } } }), 38 | WORK_TYPE: process.env.WORK_TYPE === undefined ? "private" : process.env.WORK_TYPE, 39 | SUDO: process.env.SUDO === undefined ? "" : process.env.SUDO, 40 | OFFLINE_RESPONSE: process.env.OFFLINE_RESPONSE === undefined ? true : process.env.OFFLINE_RESPONSE 41 | } 42 | 43 | export default config; -------------------------------------------------------------------------------- /core/clearance.ts: -------------------------------------------------------------------------------- 1 | import chalk from 'chalk'; 2 | import config from '../config'; 3 | import { adminCommands, sudoCommands } from "../sidekick/input-sanitization" 4 | import STRINGS from "../lib/db"; 5 | import Users from '../database/user'; 6 | import format from 'string-format'; 7 | import BotsApp from '../sidekick/sidekick'; 8 | import Client from '../sidekick/client'; 9 | import { MessageType } from '../sidekick/message-type'; 10 | 11 | const GENERAL = STRINGS.general; 12 | 13 | const clearance = async (BotsApp: BotsApp, client: Client, isBlacklist: boolean): Promise => { 14 | if (isBlacklist) { 15 | if (BotsApp.isGroup) { 16 | await client.getGroupMetaData(BotsApp.chatId, BotsApp); 17 | if ((!BotsApp.fromMe && !BotsApp.isSenderSUDO && !BotsApp.isSenderGroupAdmin)) { 18 | return false; 19 | } 20 | } else if ((!BotsApp.fromMe && !BotsApp.isSenderSUDO)) { 21 | console.log(chalk.blueBright.bold(`[INFO] Blacklisted Chat or User.`)); 22 | return false; 23 | } 24 | } 25 | else if ((BotsApp.chatId === "917838204238-1634977991@g.us" || BotsApp.chatId === "120363020858647962@g.us" || BotsApp.chatId === "120363023294554225@g.us")) { 26 | console.log(chalk.blueBright.bold(`[INFO] Bot disabled in Support Groups.`)); 27 | return false; 28 | } 29 | if (BotsApp.isCmd && (!BotsApp.fromMe && !BotsApp.isSenderSUDO)) { 30 | if (config.WORK_TYPE.toLowerCase() === "public") { 31 | if (BotsApp.isGroup) { 32 | await client.getGroupMetaData(BotsApp.chatId, BotsApp); 33 | if (adminCommands.indexOf(BotsApp.commandName) >= 0 && !BotsApp.isSenderGroupAdmin) { 34 | console.log( 35 | chalk.redBright.bold(`[INFO] admin commmand `), 36 | chalk.greenBright.bold(`${BotsApp.commandName}`), 37 | chalk.redBright.bold( 38 | `not executed in public Work Type.` 39 | ) 40 | ); 41 | await client.sendMessage( 42 | BotsApp.chatId, 43 | GENERAL.ADMIN_PERMISSION, 44 | MessageType.text 45 | ); 46 | return false; 47 | } else if (sudoCommands.indexOf(BotsApp.commandName) >= 0 && !BotsApp.isSenderSUDO) { 48 | console.log( 49 | chalk.redBright.bold(`[INFO] sudo commmand `), 50 | chalk.greenBright.bold(`${BotsApp.commandName}`), 51 | chalk.redBright.bold( 52 | `not executed in public Work Type.` 53 | ) 54 | ); 55 | let messageSent: boolean = await Users.getUser(BotsApp.chatId); 56 | if (messageSent) { 57 | console.log(chalk.blueBright.bold("[INFO] Promo message had already been sent to " + BotsApp.chatId)) 58 | return false; 59 | } 60 | else { 61 | await client.sendMessage( 62 | BotsApp.chatId, 63 | format(GENERAL.SUDO_PERMISSION, { worktype: "public", groupName: BotsApp.groupName ? BotsApp.groupName : "private chat", commandName: BotsApp.commandName }), 64 | MessageType.text 65 | ); 66 | await Users.addUser(BotsApp.chatId); 67 | return false; 68 | } 69 | } else { 70 | return true; 71 | } 72 | }else if(BotsApp.isPm){ 73 | return true; 74 | } 75 | } else if (config.WORK_TYPE.toLowerCase() != "public" && !BotsApp.isSenderSUDO) { 76 | console.log( 77 | chalk.redBright.bold(`[INFO] commmand `), 78 | chalk.greenBright.bold(`${BotsApp.commandName}`), 79 | chalk.redBright.bold( 80 | `not executed in private Work Type.` 81 | ) 82 | ); 83 | // let messageSent = await Users.getUser(BotsApp.chatId); 84 | // if(messageSent){ 85 | // console.log(chalk.blueBright.bold("[INFO] Promo message had already been sent to " + BotsApp.chatId)) 86 | // return false; 87 | // } 88 | // else{ 89 | // await client.sendMessage( 90 | // BotsApp.chatId, 91 | // GENERAL.SUDO_PERMISSION.format({ worktype: "private", groupName: BotsApp.groupName ? BotsApp.groupName : "private chat", commandName: BotsApp.commandName }), 92 | // MessageType.text, 93 | // { 94 | // contextInfo: { 95 | // stanzaId: BotsApp.chatId, 96 | // participant: BotsApp.sender, 97 | // quotedMessage: { 98 | // conversation: BotsApp.body, 99 | // }, 100 | // }, 101 | // } 102 | // ); 103 | // await Users.addUser(BotsApp.chatId) 104 | // return false; 105 | // } 106 | } 107 | } else { 108 | return true; 109 | } 110 | } 111 | 112 | export = clearance; -------------------------------------------------------------------------------- /core/dbAuth.js: -------------------------------------------------------------------------------- 1 | 'use strict';const _0x3afda0=_0x15f5;function _0x4fac(){const _0x2e8149=['log','@whiskeysockets/baileys','useRemoteFileAuthState','update','then','map','8ZSiDtu','initAuthCreds','BufferJSON','fromObject','354232UhcfGw','credential','82470XexctE','proto','8851890QojJaw','AppStateSyncKeyData','next','replacer','1807770UKcDyz','creds','__awaiter','__esModule','1938215QHmfbg','26RggKmH','reviver','stringify','catch','774QPwRIz','Auth','36536DcisBp','push','create','21iUeLoC','value','destroy','done','40692278pwpYot'];_0x4fac=function(){return _0x2e8149;};return _0x4fac();}(function(_0x508b97,_0x336cd7){const _0x5e0057=_0x15f5,_0xa7ad36=_0x508b97();while(!![]){try{const _0x38a33c=-parseInt(_0x5e0057(0x8d))/0x1+-parseInt(_0x5e0057(0x75))/0x2*(-parseInt(_0x5e0057(0x6a))/0x3)+-parseInt(_0x5e0057(0x89))/0x4*(parseInt(_0x5e0057(0x74))/0x5)+parseInt(_0x5e0057(0x70))/0x6*(-parseInt(_0x5e0057(0x7e))/0x7)+parseInt(_0x5e0057(0x7b))/0x8*(-parseInt(_0x5e0057(0x79))/0x9)+-parseInt(_0x5e0057(0x6c))/0xa+parseInt(_0x5e0057(0x82))/0xb;if(_0x38a33c===_0x336cd7)break;else _0xa7ad36['push'](_0xa7ad36['shift']());}catch(_0x1d81aa){_0xa7ad36['push'](_0xa7ad36['shift']());}}}(_0x4fac,0xb5f62));function _0x15f5(_0x1e61be,_0x299c77){const _0x4fac38=_0x4fac();return _0x15f5=function(_0x15f571,_0x3c168e){_0x15f571=_0x15f571-0x6a;let _0x15df2d=_0x4fac38[_0x15f571];return _0x15df2d;},_0x15f5(_0x1e61be,_0x299c77);}var __awaiter=this&&this[_0x3afda0(0x72)]||function(_0xe947b2,_0x565e88,_0x2d9c38,_0xb1673a){function _0x41b0ca(_0x594b52){return _0x594b52 instanceof _0x2d9c38?_0x594b52:new _0x2d9c38(function(_0x2ab125){_0x2ab125(_0x594b52);});}return new(_0x2d9c38||(_0x2d9c38=Promise))(function(_0x36b387,_0x3983a6){const _0x3934b3=_0x15f5;function _0x22f00f(_0x7d6792){const _0x2d7269=_0x15f5;try{_0x54a191(_0xb1673a[_0x2d7269(0x6e)](_0x7d6792));}catch(_0x19b5c3){_0x3983a6(_0x19b5c3);}}function _0x7e6a8a(_0x552fe7){try{_0x54a191(_0xb1673a['throw'](_0x552fe7));}catch(_0x507f32){_0x3983a6(_0x507f32);}}function _0x54a191(_0x1fcd53){const _0xe253ca=_0x15f5;_0x1fcd53[_0xe253ca(0x81)]?_0x36b387(_0x1fcd53[_0xe253ca(0x7f)]):_0x41b0ca(_0x1fcd53['value'])[_0xe253ca(0x87)](_0x22f00f,_0x7e6a8a);}_0x54a191((_0xb1673a=_0xb1673a['apply'](_0xe947b2,_0x565e88||[]))[_0x3934b3(0x6e)]());});};Object['defineProperty'](exports,_0x3afda0(0x73),{'value':!![]}),exports[_0x3afda0(0x85)]=void 0x0;const baileys_1=require(_0x3afda0(0x84)),auth_1=require('../database/auth'),useRemoteFileAuthState=()=>__awaiter(void 0x0,void 0x0,void 0x0,function*(){const _0x12efa4=_0x3afda0,_0x54def0=(_0x516877,_0x4e11e6,_0x2c7103)=>__awaiter(void 0x0,void 0x0,void 0x0,function*(){const _0xd16931=_0x15f5;return auth_1[_0xd16931(0x7a)]['findOne']({'where':{'type':_0x4e11e6,'key':_0x2c7103}})[_0xd16931(0x87)](_0x58f271=>{const _0x43ed94=_0xd16931;_0x58f271?_0x58f271[_0x43ed94(0x86)]({'value':JSON['stringify'](_0x516877,baileys_1[_0x43ed94(0x8b)]['replacer'])})[_0x43ed94(0x87)](_0x24e3b4=>{})[_0x43ed94(0x78)](_0x582f48=>{const _0x1816fb=_0x43ed94;console[_0x1816fb(0x83)](_0x582f48);}):auth_1[_0x43ed94(0x7a)][_0x43ed94(0x7d)]({'key':_0x2c7103,'value':JSON[_0x43ed94(0x77)](_0x516877,baileys_1[_0x43ed94(0x8b)][_0x43ed94(0x6f)]),'type':_0x4e11e6})[_0x43ed94(0x87)](_0x523347=>{})[_0x43ed94(0x78)](_0x47d6b9=>{const _0x201ae8=_0x43ed94;console[_0x201ae8(0x83)](_0x47d6b9);});});}),_0x1b813b=(_0x38c456,_0x18cdbe)=>__awaiter(void 0x0,void 0x0,void 0x0,function*(){const _0x4648d6=_0x15f5;try{let _0x5a1dfd=yield auth_1[_0x4648d6(0x7a)]['findAll']({'where':{'type':_0x38c456,'key':_0x18cdbe},'raw':!![]});if(!_0x5a1dfd[0x0])return null;return JSON['parse'](_0x5a1dfd[0x0][_0x4648d6(0x7f)],baileys_1[_0x4648d6(0x8b)][_0x4648d6(0x76)]);}catch(_0x54415d){return console[_0x4648d6(0x83)]('Got\x20error\x20while\x20reading\x20'+_0x38c456+'\x20'+_0x18cdbe+'!!'),console[_0x4648d6(0x83)](_0x54415d),null;}}),_0x422f6e=(_0xc9b503,_0x516fc9)=>__awaiter(void 0x0,void 0x0,void 0x0,function*(){const _0x1169f2=_0x15f5;try{yield auth_1[_0x1169f2(0x7a)][_0x1169f2(0x80)]({'where':{'type':_0xc9b503,'key':_0x516fc9}});}catch(_0x37f12d){}}),_0x206229=(yield _0x1b813b(_0x12efa4(0x71),_0x12efa4(0x8e)))||(0x0,baileys_1[_0x12efa4(0x8a)])();return{'state':{'creds':_0x206229,'keys':{'get':(_0x3fc378,_0x54e6fb)=>__awaiter(void 0x0,void 0x0,void 0x0,function*(){const _0x44652e=_0x12efa4,_0x56e420={};return yield Promise['all'](_0x54e6fb[_0x44652e(0x88)](_0x25ad9d=>__awaiter(void 0x0,void 0x0,void 0x0,function*(){const _0x50691c=_0x44652e;let _0x31650=yield _0x1b813b(_0x3fc378,_0x25ad9d);_0x3fc378==='app-state-sync-key'&&_0x31650&&(_0x31650=baileys_1[_0x50691c(0x6b)][_0x50691c(0x6d)][_0x50691c(0x8c)](_0x31650)),_0x56e420[_0x25ad9d]=_0x31650;}))),_0x56e420;}),'set':_0x4363bd=>__awaiter(void 0x0,void 0x0,void 0x0,function*(){const _0x3ea249=_0x12efa4,_0x9e23ef=[];for(const _0x13e71b in _0x4363bd){for(const _0x45fc65 in _0x4363bd[_0x13e71b]){const _0x5d0b4e=_0x4363bd[_0x13e71b][_0x45fc65];_0x9e23ef[_0x3ea249(0x7c)](_0x5d0b4e?_0x54def0(_0x5d0b4e,_0x13e71b,_0x45fc65):_0x422f6e(_0x13e71b,_0x45fc65));}}yield Promise['all'](_0x9e23ef);})}},'saveCreds':()=>{const _0x1ec5af=_0x12efa4;return _0x54def0(_0x206229,_0x1ec5af(0x71),_0x1ec5af(0x8e));}};});exports['useRemoteFileAuthState']=useRemoteFileAuthState; -------------------------------------------------------------------------------- /core/gitpull.ts: -------------------------------------------------------------------------------- 1 | const git = require('simple-git')() 2 | import chalk from 'chalk'; 3 | import { exec } from 'child_process'; 4 | 5 | const gitPull = async () : Promise => { 6 | console.log(chalk.yellowBright.bold("[INFO] Checking for updates...")); 7 | await git.fetch(); 8 | let newCommits: any = await git.log(['main..origin/main']) 9 | if (newCommits.total) { 10 | console.log(chalk.blueBright("[INFO] New Update pending, updating...")); 11 | await git.pull("origin", "main", (err: any, update: { summary: { changes: any; }; files: string | string[]; }) => { 12 | if(update && update.summary.changes){ 13 | if(update.files.includes('package.json')){ 14 | exec('npm install').stderr.pipe(process.stderr); 15 | } 16 | console.log(chalk.greenBright.bold("[INFO] Updated the bot with latest changes.")); 17 | }else if(err){ 18 | console.log(chalk.redBright.bold("[ERROR] Could not pull latest changes!")); 19 | console.log(err); 20 | } 21 | }); 22 | }else{ 23 | console.log(chalk.greenBright.bold("[INFO] Bot is already working on latest version.")); 24 | } 25 | } 26 | 27 | export = gitPull; -------------------------------------------------------------------------------- /core/helper.ts: -------------------------------------------------------------------------------- 1 | import fs from 'fs' 2 | import config from '../config' 3 | import chalk from 'chalk' 4 | import BotsAppClass from '../sidekick/sidekick' 5 | import { Contact, GroupMetadata, GroupParticipant, proto, WASocket } from '@whiskeysockets/baileys' 6 | 7 | 8 | const resolve = async function (messageInstance: proto.IWebMessageInfo, client: WASocket) { 9 | var BotsApp: BotsAppClass = new BotsAppClass(); 10 | var prefix: string = config.PREFIX + '\\w+' 11 | var prefixRegex: RegExp = new RegExp(prefix, 'g'); 12 | var SUDOstring: string = config.SUDO; 13 | try { 14 | var jsonMessage: string = JSON.stringify(messageInstance); 15 | } catch (err) { 16 | console.log(chalk.redBright("[ERROR] Something went wrong. ", err)) 17 | } 18 | BotsApp.chatId = messageInstance.key.remoteJid; 19 | BotsApp.fromMe = messageInstance.key.fromMe; 20 | BotsApp.owner = client.user.id.replace(/:.*@/g, '@'); 21 | BotsApp.mimeType = messageInstance.message ? (Object.keys(messageInstance.message)[0] === 'senderKeyDistributionMessage' ? Object.keys(messageInstance.message)[2] : (Object.keys(messageInstance.message)[0] === 'messageContextInfo' ? Object.keys(messageInstance.message)[1] : Object.keys(messageInstance.message)[0])) : null; 22 | BotsApp.type = BotsApp.mimeType === 'imageMessage' ? 'image' : (BotsApp.mimeType === 'videoMessage') ? 'video' : (BotsApp.mimeType === 'conversation' || BotsApp.mimeType == 'extendedTextMessage') ? 'text' : (BotsApp.mimeType === 'audioMessage') ? 'audio' : (BotsApp.mimeType === 'stickerMessage') ? 'sticker' : (BotsApp.mimeType === 'senderKeyDistributionMessage' && messageInstance.message?.senderKeyDistributionMessage?.groupId === 'status@broadcast') ? 'status' : null; 23 | BotsApp.isTextReply = (BotsApp.mimeType === 'extendedTextMessage' && messageInstance.message?.extendedTextMessage?.contextInfo?.stanzaId) ? true : false; 24 | BotsApp.replyMessageId = messageInstance.message?.extendedTextMessage?.contextInfo?.stanzaId; 25 | BotsApp.replyParticipant = messageInstance.message?.extendedTextMessage?.contextInfo?.participant.replace(/:.*@/g, '@');; 26 | BotsApp.replyMessage = messageInstance.message?.extendedTextMessage?.contextInfo?.quotedMessage?.conversation || messageInstance.message?.extendedTextMessage?.contextInfo?.quotedMessage?.extendedTextMessage?.text; 27 | 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 : null; 28 | BotsApp.isCmd = prefixRegex.test(BotsApp.body); 29 | BotsApp.commandName = BotsApp.isCmd ? BotsApp.body.slice(1).trim().split(/ +/).shift().toLowerCase().split('\n')[0] : null; 30 | BotsApp.isImage = BotsApp.type === "image"; 31 | BotsApp.isReplyImage = messageInstance.message?.extendedTextMessage?.contextInfo?.quotedMessage?.imageMessage ? true : false; 32 | BotsApp.imageCaption = BotsApp.isImage ? messageInstance.message?.imageMessage.caption : null; 33 | BotsApp.isGIF = (BotsApp.type === 'video' && messageInstance.message?.videoMessage?.gifPlayback); 34 | BotsApp.isReplyGIF = messageInstance.message?.extendedTextMessage?.contextInfo?.quotedMessage?.videoMessage?.gifPlayback ? true : false; 35 | BotsApp.isSticker = BotsApp.type === 'sticker'; 36 | BotsApp.isReplySticker = messageInstance.message?.extendedTextMessage?.contextInfo?.quotedMessage?.stickerMessage ? true : false; 37 | BotsApp.isReplyAnimatedSticker = messageInstance.message?.extendedTextMessage?.contextInfo?.quotedMessage?.stickerMessage?.isAnimated; 38 | BotsApp.isVideo = (BotsApp.type === 'video' && !messageInstance.message?.videoMessage?.gifPlayback); 39 | BotsApp.isReplyVideo = BotsApp.isTextReply ? (jsonMessage.indexOf("videoMessage") !== -1 && !messageInstance.message?.extendedTextMessage?.contextInfo.quotedMessage.videoMessage.gifPlayback) : false; 40 | BotsApp.isAudio = BotsApp.type === 'audio'; 41 | BotsApp.isReplyAudio = messageInstance.message?.extendedTextMessage?.contextInfo?.quotedMessage?.audioMessage ? true : false; 42 | BotsApp.logGroup = client.user.id.replace(/:.*@/g, '@');; 43 | BotsApp.isGroup = BotsApp.chatId.endsWith('@g.us'); 44 | BotsApp.isPm = !BotsApp.isGroup; 45 | BotsApp.sender = (BotsApp.isGroup && messageInstance.message && BotsApp.fromMe) ? BotsApp.owner : (BotsApp.isGroup && messageInstance.message) ? messageInstance.key.participant.replace(/:.*@/g, '@') : (!BotsApp.isGroup) ? BotsApp.chatId : null; 46 | BotsApp.isSenderSUDO = SUDOstring.includes(BotsApp.sender?.substring(0, BotsApp.sender.indexOf("@"))); 47 | 48 | return BotsApp; 49 | } 50 | 51 | export = resolve; -------------------------------------------------------------------------------- /database/auth.ts: -------------------------------------------------------------------------------- 1 | import config from "../config"; 2 | import { DataTypes, InferAttributes, Model, InferCreationAttributes, Sequelize } from "sequelize"; 3 | 4 | const sequelize: Sequelize = config.DATABASE; 5 | 6 | // @ts-ignore 7 | class Auth extends Model, InferCreationAttributes> { 8 | declare key: string; 9 | declare value: string; 10 | declare type: string; 11 | } 12 | 13 | Auth.init({ 14 | // @ts-ignore 15 | key: { 16 | type: DataTypes.STRING(1000000), 17 | allowNull: false, 18 | }, 19 | value: { 20 | type: DataTypes.STRING(1000000) 21 | }, 22 | type: { 23 | type: DataTypes.STRING(1000000), 24 | } 25 | }, { 26 | sequelize, 27 | tableName: "Authentication", 28 | timestamps: false, 29 | } 30 | ); 31 | 32 | export {Auth}; -------------------------------------------------------------------------------- /database/blacklist.ts: -------------------------------------------------------------------------------- 1 | import config from "../config"; 2 | import { DataTypes, InferAttributes, Model, InferCreationAttributes, Sequelize } from "sequelize"; 3 | 4 | const sequelize: Sequelize = config.DATABASE; 5 | 6 | // @ts-ignore 7 | class Blacklist extends Model, InferCreationAttributes> { 8 | declare JID: string; 9 | declare GRPID: string; 10 | } 11 | 12 | Blacklist.init({ 13 | // @ts-ignore 14 | JID: { 15 | type: DataTypes.STRING, 16 | allowNull: false, 17 | }, 18 | GRPID: { 19 | type: DataTypes.STRING, 20 | allowNull: false, 21 | }, 22 | }, {sequelize, tableName: "Blacklist"}); 23 | 24 | async function addBlacklistUser(jid: string = "", GrpId: string = "") : Promise { 25 | Blacklist.findOrCreate({ 26 | where: { 27 | JID: jid, 28 | GRPID: GrpId, 29 | }, 30 | }); 31 | } 32 | 33 | async function getBlacklistUser(jid: string = "", GrpId: string = "") : Promise { 34 | var Msg = await Blacklist.findAll({ 35 | where: { 36 | JID: "", 37 | GRPID: GrpId, 38 | }, 39 | }); 40 | 41 | if (Msg.length < 1) { 42 | var Msg = await Blacklist.findAll({ 43 | where: { 44 | JID: jid, 45 | GRPID: "", 46 | }, 47 | }); 48 | 49 | if (Msg.length < 1) { 50 | var Msg = await Blacklist.findAll({ 51 | where: { 52 | JID: jid, 53 | GRPID: GrpId, 54 | }, 55 | }); 56 | 57 | if (Msg.length < 1) { 58 | return false; 59 | } else { 60 | return true; 61 | } 62 | } else { 63 | return true; 64 | } 65 | } else { 66 | return true; 67 | } 68 | } 69 | 70 | async function removeBlacklistUser(jid: string = "", GrpId: string = "") : Promise { 71 | var Msg = await Blacklist.findAll({ 72 | where: { 73 | JID: jid, 74 | GRPID: GrpId, 75 | }, 76 | }); 77 | if (Msg.length < 1) { 78 | return false; 79 | } else { 80 | return await Msg[0].destroy(); 81 | } 82 | } 83 | 84 | export = { 85 | Blacklist: Blacklist, 86 | addBlacklistUser: addBlacklistUser, 87 | getBlacklistUser: getBlacklistUser, 88 | removeBlacklistUser: removeBlacklistUser, 89 | }; 90 | -------------------------------------------------------------------------------- /database/greeting.ts: -------------------------------------------------------------------------------- 1 | import config from "../config"; 2 | import { DataTypes, InferAttributes, Model, InferCreationAttributes, Sequelize } from "sequelize"; 3 | 4 | const sequelize: Sequelize = config.DATABASE; 5 | 6 | // @ts-ignore 7 | class Greeting extends Model, InferCreationAttributes> { 8 | declare chat: string; 9 | declare switched: string; 10 | declare greetingType: string | null; 11 | declare message: string | null; 12 | } 13 | 14 | Greeting.init({ 15 | // @ts-ignore 16 | chat: { 17 | type: DataTypes.STRING, 18 | allowNull: false 19 | }, 20 | switched: { 21 | type: DataTypes.STRING, 22 | allowNull: false, 23 | defaultValue: "ON", 24 | }, 25 | greetingType: { 26 | type: DataTypes.TEXT, 27 | }, 28 | message: { 29 | type: DataTypes.TEXT, 30 | }, 31 | }, {sequelize, tableName: "Greetings"}); 32 | 33 | async function getMessage(jid: string | null = null, type: string) : Promise { 34 | var Msg = await Greeting.findAll({ 35 | where: { 36 | chat: jid, 37 | greetingType: type, 38 | }, 39 | raw: true 40 | }); 41 | 42 | if (Msg.length < 1) { 43 | return false; 44 | } else { 45 | return Msg[0]; 46 | } 47 | } 48 | 49 | async function checkSettings(jid: string | null = null, type: string) : Promise { 50 | var Msg = await Greeting.findAll({ 51 | where: { 52 | chat: jid, 53 | greetingType: type, 54 | }, 55 | raw: true 56 | }); 57 | 58 | if (Msg.length < 1) { 59 | return false; 60 | } else { 61 | if (Msg[0].switched === "ON") { 62 | return "ON"; 63 | } else { 64 | return "OFF"; 65 | } 66 | } 67 | } 68 | 69 | async function changeSettings(groupJid: string = null, isWorking: string) : Promise { 70 | await Greeting.update({ 71 | switched: isWorking 72 | }, { 73 | where: { 74 | chat: groupJid, 75 | }, 76 | }); 77 | } 78 | 79 | async function setWelcome(jid: string = null, text: string = null) : Promise { 80 | Greeting.findOrCreate({ 81 | where: { 82 | chat: jid, 83 | greetingType: "welcome", 84 | }, 85 | defaults: { 86 | chat: jid, 87 | switched: "ON", 88 | greetingType: "welcome", 89 | message: text, 90 | }, 91 | }); 92 | } 93 | async function setGoodbye(jid: string, text: string = null) : Promise { 94 | Greeting.findOrCreate({ 95 | where: { 96 | chat: jid, 97 | greetingType: "goodbye", 98 | }, 99 | defaults: { 100 | chat: jid, 101 | switched: "ON", 102 | greetingType: "goodbye", 103 | message: text, 104 | }, 105 | }); 106 | } 107 | 108 | async function deleteMessage(jid: string = null, type: string = null) : Promise { 109 | var Msg = await Greeting.findAll({ 110 | where: { 111 | chat: jid, 112 | greetingType: type, 113 | }, 114 | }); 115 | if (Msg.length < 1) { 116 | return false; 117 | } else { 118 | return await Msg[0].destroy(); 119 | } 120 | } 121 | 122 | export = { 123 | Greeting: Greeting, 124 | getMessage: getMessage, 125 | changeSettings: changeSettings, 126 | checkSettings: checkSettings, 127 | setWelcome: setWelcome, 128 | setGoodbye: setGoodbye, 129 | deleteMessage: deleteMessage, 130 | }; -------------------------------------------------------------------------------- /database/user.ts: -------------------------------------------------------------------------------- 1 | import config from "../config"; 2 | import { DataTypes, InferAttributes, Model, InferCreationAttributes, Sequelize } from "sequelize"; 3 | 4 | const sequelize = config.DATABASE; 5 | 6 | // @ts-ignore 7 | class User extends Model, InferCreationAttributes> { 8 | declare JID: string; 9 | } 10 | 11 | User.init({ 12 | // @ts-ignore 13 | JID: { 14 | type: DataTypes.STRING, 15 | allowNull: false, 16 | }, 17 | }, { sequelize, tableName: "Users"}); 18 | 19 | async function addUser(jid: string | null = null) { 20 | User.findOrCreate({ 21 | where: { 22 | JID: jid 23 | }, 24 | }); 25 | 26 | } 27 | 28 | async function getUser(jid: string | null = null) { 29 | var Msg = await User.findAll({ 30 | where: { 31 | JID: jid 32 | }, 33 | }); 34 | 35 | if (Msg.length < 1) { 36 | return false; 37 | } else { 38 | return true; 39 | } 40 | } 41 | 42 | export = { 43 | User: User, 44 | addUser: addUser, 45 | getUser: getUser 46 | }; -------------------------------------------------------------------------------- /heroku.yml: -------------------------------------------------------------------------------- 1 | build: 2 | docker: 3 | botsapp: Dockerfile -------------------------------------------------------------------------------- /images/BotsApp_Logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Prince-Mendiratta/BotsApp/c148312ed2e1162cb7963317ad8f92161a3cea60/images/BotsApp_Logo.png -------------------------------------------------------------------------------- /images/BotsApp_invite.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Prince-Mendiratta/BotsApp/c148312ed2e1162cb7963317ad8f92161a3cea60/images/BotsApp_invite.jpeg -------------------------------------------------------------------------------- /images/default_dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Prince-Mendiratta/BotsApp/c148312ed2e1162cb7963317ad8f92161a3cea60/images/default_dp.png -------------------------------------------------------------------------------- /lib/banner.ts: -------------------------------------------------------------------------------- 1 | export const banner: string = ` 2 | 3 | ██████╗ ██████╗ ████████╗███████╗ █████╗ ██████╗ ██████╗ 4 | ██╔══██╗██╔═══██╗╚══██╔══╝██╔════╝██╔══██╗██╔══██╗██╔══██╗ 5 | ██████╔╝██║ ██║ ██║ ███████╗███████║██████╔╝██████╔╝ 6 | ██╔══██╗██║ ██║ ██║ ╚════██║██╔══██║██╔═══╝ ██╔═══╝ 7 | ██████╔╝╚██████╔╝ ██║ ███████║██║ ██║██║ ██║ 8 | ╚═════╝ ╚═════╝ ╚═╝ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝ 9 | 10 | 11 | `; -------------------------------------------------------------------------------- /lib/cpp.js: -------------------------------------------------------------------------------- 1 | // Temporarily Disabled. 2 | 3 | // const { MessageType, Mimetype } = require("@whiskeysockets/baileys"); 4 | // const Strings = require("../lib/db"); 5 | // const format = require("python-format-js"); 6 | // const inputSanitization = require("../sidekick/input-sanitization"); 7 | // const CPP = Strings.cpp; 8 | // const fs = require("fs"); 9 | // const { promisify } = require('util'); 10 | // const exec = promisify(require("child_process").exec); 11 | // var execFile = require('child_process').execFile 12 | // const config = require('../config') 13 | 14 | // module.exports = { 15 | // name: "cpp", 16 | // description: CPP.DESCRIPTION, 17 | // extendedDescription: CPP.EXTENDED_DESCRIPTION, 18 | // demo: { isEnabled: true, text: ['.cpp printf("Hello from BotsApp!");', '.cpp float x, y;\ncin >> x >> y;\ncout<<"sum of provide numbers is -> " << x + y; -i 6 0.9', '.cpp #include \nusing namespace std;\n\nint main() {\n cout << "BotsApp is the best!" << endl;\n}'] }, 19 | // async handle(client, chat, BotsApp, args) { 20 | // try { 21 | // if (args[0] == null) { 22 | // await client.sendMessage( 23 | // BotsApp.chatId, 24 | // CPP.NO_INPUT, 25 | // MessageType.text 26 | // ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 27 | // return; 28 | // } 29 | // var processing = await client.sendMessage( 30 | // BotsApp.chatId, 31 | // CPP.PROCESSING, 32 | // MessageType.text 33 | // ) 34 | // var body = BotsApp.body.replace( 35 | // BotsApp.body[0] + BotsApp.commandName + " ", 36 | // "" 37 | // ); 38 | // try{ 39 | // var text = body.split("-i") 40 | // var code = text[0] 41 | // var input = text[1].substring(1) 42 | 43 | // }catch(err){ 44 | // var code = body; 45 | // } 46 | // var cpp = "" 47 | // if (!(/main\(/g.test(code))) { 48 | // cpp = CPP.BOILERPLATE.replace("{code}", code); 49 | // } else { 50 | // cpp = code; 51 | // } 52 | // fs.writeFileSync('./tmp/cpp-botsapp.cpp', cpp); 53 | // var out = { 54 | // stderr: 'N/A', 55 | // stdout: 'N/A', 56 | // code: cpp 57 | // } 58 | // var compile = "g++ ./tmp/cpp-botsapp.cpp -o ./tmp/cppBotsApp.out" 59 | // var execute = "env -i ./tmp/cppBotsApp.out" 60 | // try { 61 | // await exec(compile) 62 | // var child = execFile("env -i ./tmp/cppBotsApp.out", [], {shell: true}, 63 | // async function (error, stdout, stderr) { 64 | // if(stdout){ 65 | // out.stdout = stdout 66 | // } 67 | // if(stderr){ 68 | // out.stderr = stderr 69 | // }else if(error){ 70 | // if(error.code == null){ 71 | // out.stderr = "Execution timed out (10 seconds). Please make sure that the input has been provided and is in correct order. Use the``` *.help cpp* ```command for more info!" 72 | // }else{ 73 | // out.stderr = error 74 | // } 75 | // out.stdout = "N/A" 76 | // } 77 | // await client.sendMessage( 78 | // BotsApp.chatId, 79 | // CPP.OUTPUT_TEMPLATE.format(out), 80 | // MessageType.text 81 | // ) 82 | // await client.deleteMessage(BotsApp.chatId, { 83 | // id: processing.key.id, 84 | // remoteJid: BotsApp.chatId, 85 | // fromMe: true, 86 | // }) 87 | // } 88 | // ); 89 | // if(input){ 90 | // child.stdin.setEncoding('utf-8'); 91 | // child.stdin.write(input + "\n"); 92 | // out.code += "\n\nWith Input - " + input 93 | // } 94 | // } catch (err) { 95 | // out.stderr = err.stderr 96 | // await client.sendMessage( 97 | // BotsApp.chatId, 98 | // CPP.OUTPUT_TEMPLATE.format(out), 99 | // MessageType.text 100 | // ) 101 | // return await client.deleteMessage(BotsApp.chatId, { 102 | // id: processing.key.id, 103 | // remoteJid: BotsApp.chatId, 104 | // fromMe: true, 105 | // }) 106 | // } 107 | // setTimeout(() => { 108 | // try{ 109 | // child.kill(); // Does not terminate the Node.js process in the shell. 110 | // inputSanitization.deleteFiles( 111 | // "./tmp/cppBotsApp.out", 112 | // "./tmp/cpp-botsapp.cpp" 113 | // ); 114 | // }catch(err){ 115 | // // Do nothing lmao 116 | // } 117 | // }, 10000); 118 | // } catch (err) { 119 | // await inputSanitization.handleError(err, client, BotsApp); 120 | // } 121 | // } 122 | // }; 123 | -------------------------------------------------------------------------------- /lib/neko.js: -------------------------------------------------------------------------------- 1 | // Disabled till fix can be found. 2 | 3 | // const { MessageType } = require("@whiskeysockets/baileys"); 4 | // const inputSanitization = require("../sidekick/input-sanitization"); 5 | // const String = require("../lib/db.js"); 6 | // const got = require("got"); 7 | // const REPLY = String.neko; 8 | // module.exports = { 9 | // name: "neko", 10 | // description: REPLY.DESCRIPTION, 11 | // extendedDescription: REPLY.EXTENDED_DESCRIPTION, 12 | // demo: { 13 | // isEnabled: true, 14 | // text: '.neko #include \nint main() \n{\n std::cout << "Hello BotsApp!"; \n return 0;\n}', 15 | // }, 16 | // async handle(client, chat, BotsApp, args) { 17 | // try { 18 | // if (args.length === 0 && !BotsApp.isReply) { 19 | // await client.sendMessage( 20 | // BotsApp.chatId, 21 | // REPLY.ENTER_TEXT, 22 | // MessageType.text 23 | // ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 24 | // return; 25 | // } 26 | // const processing = await client.sendMessage( 27 | // BotsApp.chatId, 28 | // REPLY.PROCESSING, 29 | // MessageType.text 30 | // ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 31 | // if (!BotsApp.isReply) { 32 | // var json = { 33 | // content: BotsApp.body.replace( 34 | // BotsApp.body[0] + BotsApp.commandName + " ", 35 | // "" 36 | // ), 37 | // }; 38 | // } else { 39 | // var json = { 40 | // content: BotsApp.replyMessage.replace( 41 | // BotsApp.body[0] + BotsApp.commandName + " ", 42 | // "" 43 | // ), 44 | // }; 45 | // } 46 | // let text = await got.post("https://nekobin.com/api/documents", { 47 | // json, 48 | // }); 49 | // json = JSON.parse(text.body); 50 | // neko_url = "https://nekobin.com/" + json.result.key; 51 | // client.sendMessage(BotsApp.chatId, neko_url, MessageType.text).catch(err => inputSanitization.handleError(err, client, BotsApp)); 52 | // return await client.deleteMessage(BotsApp.chatId, { 53 | // id: processing.key.id, 54 | // remoteJid: BotsApp.chatId, 55 | // fromMe: true, 56 | // }).catch(err => inputSanitization.handleError(err, client, BotsApp)); 57 | // } catch (err) { 58 | // if (json.result == undefined) { 59 | // await inputSanitization.handleError( 60 | // err, 61 | // client, 62 | // BotsApp, 63 | // REPLY.TRY_LATER 64 | // ); 65 | // } else { 66 | // await inputSanitization.handleError(err, client, BotsApp); 67 | // } 68 | // return await client.deleteMessage(BotsApp.chatId, { 69 | // id: processing.key.id, 70 | // remoteJid: BotsApp.chatId, 71 | // fromMe: true, 72 | // }).catch(err => inputSanitization.handleError(err, client, BotsApp)); 73 | // } 74 | // }, 75 | // }; 76 | -------------------------------------------------------------------------------- /modules/abl.ts: -------------------------------------------------------------------------------- 1 | import Strings from "../lib/db"; 2 | import format from "string-format"; 3 | import inputSanitization from "../sidekick/input-sanitization"; 4 | import Blacklist from "../database/blacklist"; 5 | import Client from "../sidekick/client"; 6 | import { proto } from "@whiskeysockets/baileys"; 7 | import BotsApp from "../sidekick/sidekick"; 8 | import { MessageType } from "../sidekick/message-type"; 9 | const abl = Strings.abl; 10 | 11 | module.exports = { 12 | name: "abl", 13 | description: abl.DESCRIPTION, 14 | extendedDescription: abl.EXTENDED_DESCRIPTION, 15 | demo: { isEnabled: true, text: ".abl" }, 16 | async handle(client: Client, chat: proto.IWebMessageInfo, BotsApp: BotsApp, args: string[]): Promise { 17 | try { 18 | if (BotsApp.isPm && BotsApp.fromMe) { 19 | let PersonToBlacklist = BotsApp.chatId; 20 | Blacklist.addBlacklistUser(PersonToBlacklist, ""); 21 | client.sendMessage( 22 | BotsApp.chatId, 23 | format(abl.PM_ACKNOWLEDGEMENT, PersonToBlacklist.substring(0, PersonToBlacklist.indexOf("@"))), 24 | MessageType.text 25 | ); 26 | return; 27 | } else { 28 | await client.getGroupMetaData(BotsApp.chatId, BotsApp); 29 | if (args.length > 0) { 30 | let PersonToBlacklist = await inputSanitization.getCleanedContact( 31 | args, 32 | client, 33 | BotsApp); 34 | if (PersonToBlacklist === undefined) return; 35 | PersonToBlacklist += "@s.whatsapp.net"; 36 | if (BotsApp.owner === PersonToBlacklist) { 37 | client.sendMessage( 38 | BotsApp.chatId, 39 | abl.CAN_NOT_BLACKLIST_BOT, 40 | MessageType.text 41 | ); 42 | return; 43 | } 44 | Blacklist.addBlacklistUser( 45 | PersonToBlacklist, 46 | BotsApp.chatId 47 | ); 48 | client.sendMessage( 49 | BotsApp.chatId, 50 | format(abl.GRP_ACKNOWLEDGEMENT, PersonToBlacklist.substring(0, PersonToBlacklist.indexOf("@"))), 51 | MessageType.text 52 | ); 53 | return; 54 | } else if (BotsApp.isTextReply) { 55 | let PersonToBlacklist = BotsApp.replyParticipant; 56 | if (BotsApp.owner === PersonToBlacklist) { 57 | client.sendMessage( 58 | BotsApp.chatId, 59 | abl.CAN_NOT_BLACKLIST_BOT, 60 | MessageType.text 61 | ); 62 | return; 63 | } 64 | Blacklist.addBlacklistUser( 65 | PersonToBlacklist, 66 | BotsApp.chatId 67 | ); 68 | client.sendMessage( 69 | BotsApp.chatId, 70 | format(abl.GRP_ACKNOWLEDGEMENT, PersonToBlacklist.substring(0, PersonToBlacklist.indexOf("@"))), 71 | MessageType.text 72 | ); 73 | return; 74 | } else { 75 | Blacklist.addBlacklistUser("", BotsApp.chatId); 76 | client.sendMessage( 77 | BotsApp.chatId, 78 | format(abl.GRP_BAN, BotsApp.groupName), 79 | MessageType.text 80 | ); 81 | return; 82 | } 83 | } 84 | } catch (err) { 85 | await inputSanitization.handleError(err, client, BotsApp); 86 | } 87 | }, 88 | }; 89 | -------------------------------------------------------------------------------- /modules/add.ts: -------------------------------------------------------------------------------- 1 | import chalk from "chalk"; 2 | import STRINGS from "../lib/db.js"; 3 | import inputSanitization from "../sidekick/input-sanitization"; 4 | import CONFIG from "../config"; 5 | import Client from "../sidekick/client"; 6 | import { proto } from "@whiskeysockets/baileys"; 7 | import BotsApp from "../sidekick/sidekick"; 8 | import { MessageType } from "../sidekick/message-type"; 9 | import format from "string-format"; 10 | import fs from 'fs'; 11 | const ADD = STRINGS.add; 12 | 13 | module.exports = { 14 | name: "add", 15 | description: ADD.DESCRIPTION, 16 | extendedDescription: ADD.EXTENDED_DESCRIPTION, 17 | demo: { isEnabled: false }, 18 | async handle(client: Client, chat: proto.IWebMessageInfo, BotsApp: BotsApp, args: string[]): Promise { 19 | try { 20 | if (!BotsApp.isGroup) { 21 | client.sendMessage( 22 | BotsApp.chatId, 23 | STRINGS.general.NOT_A_GROUP, 24 | MessageType.text 25 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 26 | return; 27 | } 28 | await client.getGroupMetaData(BotsApp.chatId, BotsApp); 29 | if (!BotsApp.isBotGroupAdmin) { 30 | client.sendMessage( 31 | BotsApp.chatId, 32 | STRINGS.general.BOT_NOT_ADMIN, 33 | MessageType.text 34 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 35 | return; 36 | } 37 | if (!args[0]) { 38 | client.sendMessage( 39 | BotsApp.chatId, 40 | ADD.NO_ARG_ERROR, 41 | MessageType.text 42 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 43 | return; 44 | } 45 | let number; 46 | if (Number.isNaN(parseInt(args[0])) || args[0][0] === "+" || args[0].length < 10) { 47 | client.sendMessage( 48 | BotsApp.chatId, 49 | ADD.NUMBER_SYNTAX_ERROR, 50 | MessageType.text 51 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 52 | return; 53 | } 54 | if (args[0].length == 10 && !(Number.isNaN(parseInt(args[0])))) { 55 | number = CONFIG.COUNTRY_CODE + args[0]; 56 | } else { 57 | number = args[0]; 58 | } 59 | const [exists] = await client.sock.onWhatsApp( 60 | number + "@s.whatsapp.net" 61 | ); 62 | if (!(exists)) { 63 | client.sendMessage( 64 | BotsApp.chatId, 65 | format(ADD.NOT_ON_WHATSAPP, number), 66 | MessageType.text 67 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 68 | return; 69 | } 70 | const response: any = await client.sock.groupParticipantsUpdate(BotsApp.chatId, [number + "@s.whatsapp.net"], 'add'); 71 | 72 | // if (response[number + "@c.us"] == 408) { 73 | // client.sendMessage( 74 | // BotsApp.chatId, 75 | // ADD.NO_24HR_BAN, 76 | // MessageType.text 77 | // ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 78 | // return; 79 | // } else if (response[number + "@c.us"] == 403) { 80 | // for (const index in response.participants) { 81 | // if ((number + "@c.us") in response.participants[index]) { 82 | // var code = response.participants[index][number + "@c.us"].invite_code; 83 | // var tom = response.participants[index][number + "@c.us"].invite_code_exp; 84 | // } 85 | // } 86 | // var invite = { 87 | // caption: "```Hi! You have been invited to join this WhatsApp group by BotsApp!```\n\n🔗https://mybotsapp.com", 88 | // groupJid: BotsApp.groupId, 89 | // groupName: BotsApp.groupName, 90 | // inviteCode: code, 91 | // inviteExpiration: tom, 92 | // jpegThumbnail: fs.readFileSync('./images/BotsApp_invite.jpeg') 93 | // } 94 | // await client.sendMessage( 95 | // number + "@s.whatsapp.net", 96 | // invite, 97 | // MessageType.groupInviteMessage 98 | // ); 99 | // client.sendMessage( 100 | // BotsApp.chatId, 101 | // ADD.PRIVACY, 102 | // MessageType.text 103 | // ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 104 | // return; 105 | // } else if (response[number + "@c.us"] == 409) { 106 | // client.sendMessage( 107 | // BotsApp.chatId, 108 | // ADD.ALREADY_MEMBER, 109 | // MessageType.text 110 | // ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 111 | // return; 112 | // } 113 | client.sendMessage( 114 | BotsApp.chatId, 115 | "```" + number + ADD.SUCCESS + "```", 116 | MessageType.text 117 | ); 118 | } catch (err) { 119 | if (err.status == 400) { 120 | await inputSanitization.handleError( 121 | err, 122 | client, 123 | BotsApp, 124 | ADD.NOT_ON_WHATSAPP 125 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 126 | } 127 | await inputSanitization.handleError(err, client, BotsApp); 128 | } 129 | return; 130 | }, 131 | }; 132 | -------------------------------------------------------------------------------- /modules/admins.ts: -------------------------------------------------------------------------------- 1 | import Strings from "../lib/db"; 2 | const ADMINS = Strings.admins; 3 | import inputSanitization from "../sidekick/input-sanitization"; 4 | import Client from "../sidekick/client.js"; 5 | import BotsApp from "../sidekick/sidekick"; 6 | import { MessageType } from "../sidekick/message-type"; 7 | import { proto } from "@whiskeysockets/baileys"; 8 | 9 | module.exports = { 10 | name: "admins", 11 | description: ADMINS.DESCRIPTION, 12 | extendedDescription: ADMINS.EXTENDED_DESCRIPTION, 13 | demo: { text: ".admins", isEnabled: true }, 14 | async handle(client: Client, chat: proto.IWebMessageInfo, BotsApp: BotsApp, args: string[]): Promise { 15 | try { 16 | if (!BotsApp.isGroup) { 17 | client.sendMessage( 18 | BotsApp.chatId, 19 | ADMINS.NOT_GROUP_CHAT, 20 | MessageType.text 21 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 22 | return; 23 | } 24 | 25 | let message: string = ""; 26 | await client.getGroupMetaData(BotsApp.chatId, BotsApp); 27 | for (let admin of BotsApp.groupAdmins) { 28 | let number: string = admin.split("@")[0]; 29 | message += `@${number} `; 30 | } 31 | 32 | client.sendMessage(BotsApp.chatId, message, MessageType.text, { 33 | contextInfo: { 34 | mentionedJid: BotsApp.groupAdmins, 35 | }, 36 | }).catch(err => inputSanitization.handleError(err, client, BotsApp)); 37 | return; 38 | } catch (err) { 39 | await inputSanitization.handleError(err, client, BotsApp); 40 | } 41 | }, 42 | }; 43 | -------------------------------------------------------------------------------- /modules/alive.ts: -------------------------------------------------------------------------------- 1 | import Strings from "../lib/db"; 2 | import format from "string-format"; 3 | import inputSanitization from "../sidekick/input-sanitization"; 4 | import { MessageType } from "../sidekick/message-type"; 5 | import Client from "../sidekick/client"; 6 | import { proto } from "@whiskeysockets/baileys"; 7 | import BotsApp from "../sidekick/sidekick"; 8 | const alive = Strings.alive; 9 | 10 | export = { 11 | name: "alive", 12 | description: alive.DESCRIPTION, 13 | extendedDescription: alive.EXTENDED_DESCRIPTION, 14 | demo: { isEnabled: true, text: ".alive" }, 15 | async handle(client: Client, chat: proto.IWebMessageInfo, BotsApp: BotsApp, args: string[]): Promise { 16 | try { 17 | client.sendMessage( 18 | BotsApp.chatId, 19 | alive.ALIVE_MSG, 20 | MessageType.text 21 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 22 | } catch (err) { 23 | await inputSanitization.handleError(err, client, BotsApp); 24 | } 25 | }, 26 | }; 27 | -------------------------------------------------------------------------------- /modules/block.ts: -------------------------------------------------------------------------------- 1 | import Strings from "../lib/db"; 2 | import Client from "../sidekick/client"; 3 | import { proto } from "@whiskeysockets/baileys"; 4 | import BotsApp from "../sidekick/sidekick"; 5 | import { MessageType } from "../sidekick/message-type" 6 | import inputSanitization from "../sidekick/input-sanitization"; 7 | const Reply = Strings.block; 8 | 9 | module.exports = { 10 | name: "block", 11 | description: Reply.DESCRIPTION, 12 | extendedDescription: Reply.EXTENDED_DESCRIPTION, 13 | async handle(client: Client, chat: proto.IWebMessageInfo, BotsApp: BotsApp, args: string[]): Promise { 14 | try { 15 | const reply: proto.Message.IExtendedTextMessage = chat.message.extendedTextMessage; 16 | var contact: string = ""; 17 | if(args.length == 0 && !BotsApp.isTextReply){ 18 | client.sendMessage( 19 | BotsApp.chatId, 20 | Reply.MESSAGE_NOT_TAGGED, 21 | MessageType.text 22 | ); 23 | return; 24 | } 25 | 26 | if (!(args.length > 0) && BotsApp.isTextReply) { 27 | contact = reply.contextInfo.participant.split("@")[0]; 28 | } else { 29 | contact = await inputSanitization.getCleanedContact( 30 | args, 31 | client, 32 | BotsApp 33 | ); 34 | } 35 | 36 | if (contact === BotsApp.owner.split("@")[0]) { 37 | client.sendMessage( 38 | BotsApp.chatId, 39 | Reply.NOT_BLOCK_BOT, 40 | MessageType.text 41 | ); 42 | return; 43 | } 44 | 45 | if(contact === ""){ 46 | client.sendMessage( 47 | BotsApp.chatId, 48 | Reply.MESSAGE_NOT_TAGGED, 49 | MessageType.text 50 | ); 51 | return; 52 | } 53 | var JID: string = contact + "@s.whatsapp.net"; 54 | client.sock.updateBlockStatus(JID, "block"); 55 | client.sendMessage( 56 | BotsApp.chatId, 57 | "*" + contact + " blocked successfully.*", 58 | MessageType.text 59 | ); 60 | } catch (err) { 61 | await inputSanitization.handleError( 62 | err, 63 | client, 64 | BotsApp, 65 | Reply.MESSAGE_NOT_TAGGED 66 | ); 67 | } 68 | }, 69 | }; 70 | -------------------------------------------------------------------------------- /modules/carbon.ts: -------------------------------------------------------------------------------- 1 | import chalk from "chalk"; 2 | import String from "../lib/db.js"; 3 | import * as Carbon from "unofficial-carbon-now"; 4 | import inputSanitization from "../sidekick/input-sanitization"; 5 | import format from "string-format"; 6 | import Client from "../sidekick/client.js"; 7 | import BotsApp from "../sidekick/sidekick"; 8 | import { MessageType } from "../sidekick/message-type"; 9 | import { proto } from "@whiskeysockets/baileys"; 10 | 11 | const CARBON = String.carbon; 12 | 13 | module.exports = { 14 | name: "carbon", 15 | description: CARBON.DESCRIPTION, 16 | extendedDescription: CARBON.EXTENDED_DESCRIPTION, 17 | demo: { 18 | isEnabled: true, 19 | text: [ 20 | ".carbon Hi! Welcome to BotsApp.", 21 | '.carbon #include \nint main() \n{\n std::cout << "Hello BotsApp!"; \n return 0;\n} -t yeti', 22 | ".carbon -t", 23 | ], 24 | }, 25 | async handle(client: Client, chat: proto.IWebMessageInfo, BotsApp: BotsApp, args: string[]): Promise { 26 | try { 27 | let themes: string[] = [ 28 | "3024 night", 29 | "a11y dark", 30 | "blackboard", 31 | "base 16 (dark)", 32 | "base 16 (light)", 33 | "cobalt", 34 | "duotone", 35 | "hopscotch", 36 | "lucario", 37 | "material", 38 | "monokai", 39 | "night owl", 40 | "nord", 41 | "oceanic next", 42 | "one light", 43 | "one dark", 44 | "panda", 45 | "paraiso", 46 | "seti", 47 | "shades of purple", 48 | "solarized (dark)", 49 | "solarized (light)", 50 | "synthwave '84", 51 | "twilight", 52 | "verminal", 53 | "vscode", 54 | "yeti", 55 | "zenburn", 56 | ]; 57 | let code: string = ""; 58 | let themeInput: string; 59 | if (args[0] == null && !BotsApp.isTextReply) { 60 | await client.sendMessage( 61 | BotsApp.chatId, 62 | CARBON.NO_INPUT, 63 | MessageType.text 64 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 65 | return; 66 | } else if (BotsApp.isTextReply && !BotsApp.replyMessage) { 67 | await client.sendMessage( 68 | BotsApp.chatId, 69 | CARBON.INVALID_REPLY, 70 | MessageType.text 71 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 72 | return; 73 | } else if (BotsApp.isTextReply) { 74 | code = BotsApp.replyMessage; 75 | themeInput = themes[Math.floor(Math.random() * themes.length)]; 76 | } else { 77 | try { 78 | let text: string = BotsApp.body.replace( 79 | BotsApp.body[0] + BotsApp.commandName + " ", 80 | "" 81 | ); 82 | if (text[0] === "-" && text[1] === "t") { 83 | if(text[2] == null){ 84 | let counter: number = 1; 85 | let message: string = 'Available themes: '; 86 | themes.forEach((theme) => { 87 | message += `\n${counter}. ${theme}`; 88 | counter += 1; 89 | }) 90 | await client.sendMessage( 91 | BotsApp.chatId, 92 | "```" + message + "```", 93 | MessageType.text 94 | ) 95 | return; 96 | } 97 | else{ 98 | await client.sendMessage( 99 | BotsApp.chatId, 100 | CARBON.NO_INPUT, 101 | MessageType.text 102 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 103 | return; 104 | } 105 | } 106 | let body: string[] = BotsApp.body.split("-t"); 107 | code = body[0].replace( 108 | BotsApp.body[0] + BotsApp.commandName + " ", 109 | "" 110 | ); 111 | themeInput = body[1].substring(1); 112 | if (!themes.includes(themeInput)) { 113 | await client.sendMessage( 114 | BotsApp.chatId, 115 | CARBON.INVALID_THEME, 116 | MessageType.text 117 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 118 | return; 119 | } 120 | } catch (err) { 121 | if (err instanceof TypeError) { 122 | code = BotsApp.body.replace( 123 | BotsApp.body[0] + BotsApp.commandName + " ", 124 | "" 125 | ); 126 | themeInput = 127 | themes[Math.floor(Math.random() * themes.length)]; 128 | } 129 | } 130 | } 131 | try { 132 | const processing: proto.WebMessageInfo = await client.sendMessage( 133 | BotsApp.chatId, 134 | CARBON.CARBONIZING, 135 | MessageType.text 136 | ); 137 | const carbon = new Carbon.createCarbon() 138 | .setCode(code) 139 | .setPrettify(true) 140 | .setTheme(themeInput); 141 | const output = await Carbon.generateCarbon(carbon); 142 | await client.sendMessage( 143 | BotsApp.chatId, 144 | output, 145 | MessageType.image, 146 | { 147 | caption: format(CARBON.OUTPUT, themeInput), 148 | } 149 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 150 | return await client.deleteMessage(BotsApp.chatId, { 151 | id: processing.key.id, 152 | remoteJid: BotsApp.chatId, 153 | fromMe: true, 154 | }); 155 | } catch (err) { 156 | throw err; 157 | } 158 | } catch (err) { 159 | await inputSanitization.handleError(err, client, BotsApp); 160 | } 161 | }, 162 | }; 163 | -------------------------------------------------------------------------------- /modules/cpp.bak: -------------------------------------------------------------------------------- 1 | // Temporarily Disabled. 2 | import Strings from "../lib/db"; 3 | import format from "string-format"; 4 | import inputSanitization from "../sidekick/input-sanitization"; 5 | import { MessageType } from "../sidekick/message-type"; 6 | import Client from "../sidekick/client"; 7 | import { proto } from "@whiskeysockets/baileys"; 8 | import BotsApp from "../sidekick/sidekick"; 9 | import fs from "fs"; 10 | import { promisify } from 'util'; 11 | import config from "../config"; 12 | 13 | const CPP = Strings.cpp; 14 | const exec = promisify(require("child_process").exec); 15 | var execFile = require('child_process').execFile 16 | 17 | module.exports = { 18 | name: "cpp", 19 | description: CPP.DESCRIPTION, 20 | extendedDescription: CPP.EXTENDED_DESCRIPTION, 21 | demo: { isEnabled: true, text: ['.cpp printf("Hello from BotsApp!");', '.cpp float x, y;\ncin >> x >> y;\ncout<<"sum of provide numbers is -> " << x + y; -i 6 0.9', '.cpp #include \nusing namespace std;\n\nint main() {\n cout << "BotsApp is the best!" << endl;\n}'] }, 22 | async handle(client: Client, chat: proto.IWebMessageInfo, BotsApp: BotsApp, args: string[]): Promise { 23 | try { 24 | if (args[0] == null) { 25 | await client.sendMessage( 26 | BotsApp.chatId, 27 | CPP.NO_INPUT, 28 | MessageType.text 29 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 30 | return; 31 | } 32 | var processing = await client.sendMessage( 33 | BotsApp.chatId, 34 | CPP.PROCESSING, 35 | MessageType.text 36 | ) 37 | var body = BotsApp.body.replace( 38 | BotsApp.body[0] + BotsApp.commandName + " ", 39 | "" 40 | ); 41 | let input; 42 | try{ 43 | var text = body.split("-i") 44 | var code = text[0] 45 | input = text[1].substring(1) 46 | 47 | }catch(err){ 48 | var code = body; 49 | } 50 | var cpp = "" 51 | if (!(/main\(/g.test(code))) { 52 | cpp = CPP.BOILERPLATE.replace("{code}", code); 53 | } else { 54 | cpp = code; 55 | } 56 | let filename = './tmp/cpp-botsapp' + chat.key.id +'.cpp'; 57 | let outname = './tmp/cpp-botsapp' + chat.key.id +'.out'; 58 | fs.writeFileSync(filename, cpp); 59 | var out = { 60 | stderr: 'N/A', 61 | stdout: 'N/A', 62 | code: cpp 63 | } 64 | var compile = `g++ ${filename} -o ${outname}` 65 | var execute = `env -i ${outname}` 66 | try { 67 | await exec(compile) 68 | var child = execFile(`env -i ${outname}`, [], {shell: true}, 69 | async function (error, stdout, stderr) { 70 | if(stdout){ 71 | out.stdout = stdout 72 | } 73 | if(stderr){ 74 | out.stderr = stderr 75 | }else if(error){ 76 | if(error.code == null){ 77 | out.stderr = "Execution timed out (10 seconds). Please make sure that the input has been provided and is in correct order. Use the``` *.help cpp* ```command for more info!" 78 | }else{ 79 | out.stderr = error 80 | } 81 | out.stdout = "N/A" 82 | } 83 | await client.sendMessage( 84 | BotsApp.chatId, 85 | format(CPP.OUTPUT_TEMPLATE, out), 86 | MessageType.text 87 | ) 88 | await client.deleteMessage(BotsApp.chatId, { 89 | id: processing.key.id, 90 | remoteJid: BotsApp.chatId, 91 | fromMe: true, 92 | }) 93 | } 94 | ); 95 | if(input){ 96 | child.stdin.setEncoding('utf-8'); 97 | child.stdin.write(input + "\n"); 98 | out.code += "\n\nWith Input - " + input 99 | } 100 | } catch (err) { 101 | out.stderr = err.stderr 102 | await client.sendMessage( 103 | BotsApp.chatId, 104 | format(CPP.OUTPUT_TEMPLATE, out), 105 | MessageType.text 106 | ) 107 | return await client.deleteMessage(BotsApp.chatId, { 108 | id: processing.key.id, 109 | remoteJid: BotsApp.chatId, 110 | fromMe: true, 111 | }) 112 | } 113 | setTimeout(() => { 114 | try{ 115 | child.kill(); // Does not terminate the Node.js process in the shell. 116 | inputSanitization.deleteFiles( 117 | filename, 118 | outname 119 | ); 120 | }catch(err){ 121 | // Do nothing lmao 122 | } 123 | }, 10000); 124 | } catch (err) { 125 | await inputSanitization.handleError(err, client, BotsApp); 126 | } 127 | } 128 | }; 129 | -------------------------------------------------------------------------------- /modules/create.bak: -------------------------------------------------------------------------------- 1 | // Doesn't really look all that useful... 2 | 3 | // const { MessageType, Mimetype } = require("@whiskeysockets/baileys"); 4 | // const chalk = require("chalk"); 5 | // const inputSanitization = require("../sidekick/input-sanitization"); 6 | // const strings = require("../lib/db") 7 | // const CREATE = strings.create; 8 | 9 | // module.exports = { 10 | // name: "create", 11 | // description: CREATE.DESCRIPTION, 12 | // extendedDescription: CREATE.EXTENDED_DESCRIPTION, 13 | // demo: { isEnabled: false }, 14 | // async handle(client, chat, BotsApp, args) { 15 | // try{ 16 | // if(args.length === 0) { 17 | // client.sendMessage(BotsApp.chatId, CREATE.NO_TEXT, MessageType.text); 18 | // return; 19 | // } 20 | // let nameOfTheGrp = 21 | // BotsApp.body.replace( 22 | // BotsApp.body[0] + BotsApp.commandName + " ", 23 | // "" 24 | // ); 25 | 26 | // if(BotsApp.isPm) { 27 | // const group = await client.groupCreate (nameOfTheGrp, [BotsApp.owner, BotsApp.sender]); 28 | // client.sendMessage(BotsApp.chatId, CREATE.GROUP_CREATED, MessageType.text); 29 | // return; 30 | // } 31 | // else { 32 | // if(BotsApp.isReply){ 33 | // const group = await client.groupCreate (nameOfTheGrp, [BotsApp.sender, BotsApp.replyParticipant]); 34 | // client.sendMessage(BotsApp.chatId, CREATE.GROUP_CREATED, MessageType.text); 35 | // return; 36 | // } 37 | // else { 38 | // client.sendMessage(BotsApp.chatId, CREATE.TAG_PERSON, MessageType.text); 39 | // return; 40 | // } 41 | // } 42 | // } 43 | 44 | // catch(err) { 45 | // await inputSanitization.handleError(err, client, BotsApp); 46 | // } 47 | // } 48 | // } -------------------------------------------------------------------------------- /modules/decodeqr.ts: -------------------------------------------------------------------------------- 1 | import Jimp from "jimp"; 2 | import fs from "fs"; 3 | import ffmpeg from "fluent-ffmpeg"; 4 | import inputSanitization from "../sidekick/input-sanitization"; 5 | import qrCode from "qrcode-reader"; 6 | import Strings from "../lib/db"; 7 | import Client from "../sidekick/client.js"; 8 | import BotsApp from "../sidekick/sidekick"; 9 | import { MessageType } from "../sidekick/message-type"; 10 | import { Transform } from "stream"; 11 | import { downloadContentFromMessage, proto } from "@whiskeysockets/baileys"; 12 | import { URL } from "url"; 13 | 14 | const DECODE = Strings.decodeqr; 15 | 16 | module.exports = { 17 | name: "dqr", 18 | description: DECODE.DESCRIPTION, 19 | extendedDescription: DECODE.EXTENDED_DESCRIPTION, 20 | demo: { isEnabled: false }, 21 | async handle(client: Client, chat: proto.IWebMessageInfo, BotsApp: BotsApp, args: string[]): Promise { 22 | var processing: proto.WebMessageInfo; 23 | 24 | // Function to convert qr to text 25 | const qrToText = async (imagePath: string, processing: proto.WebMessageInfo): Promise => { 26 | var buffer: Buffer = fs.readFileSync(imagePath); 27 | Jimp.read(buffer, function (err, image) { 28 | if (err) { 29 | console.error(err); 30 | } 31 | let qrcode: any = new qrCode(); 32 | qrcode.callback = async function (err: string | string[], value: { result: any; }) { 33 | if (err) { 34 | console.error(err); 35 | if (err.includes('enough finder patterns')) { 36 | await client 37 | .sendMessage(BotsApp.chatId, Strings.decodeqr.INVALID_INPUT, MessageType.text); 38 | } 39 | } else { 40 | await client 41 | .sendMessage(BotsApp.chatId, value.result, MessageType.text) 42 | .catch((err) => 43 | inputSanitization.handleError(err, client, BotsApp) 44 | ); 45 | } 46 | }; 47 | 48 | // Decoding the QR code 49 | qrcode.decode(image.bitmap); 50 | }); 51 | 52 | //Image and message deletion 53 | await inputSanitization.deleteFiles(imagePath); 54 | return await client 55 | .deleteMessage(BotsApp.chatId, { 56 | id: processing.key.id, 57 | remoteJid: BotsApp.chatId, 58 | fromMe: true, 59 | }) 60 | .catch((err) => inputSanitization.handleError(err, client, BotsApp)); 61 | }; 62 | 63 | // Function to convert sticker to image 64 | const convertToImage = async (stickerId: string, replyChat: { message: any; type: any; }, processing: proto.WebMessageInfo): Promise => { 65 | const fileName: string = "./tmp/convert_to_image-" + stickerId; 66 | const stream: Transform = await downloadContentFromMessage(replyChat.message, replyChat.type); 67 | await inputSanitization.saveBuffer(fileName, stream); 68 | const imagePath: string = "./tmp/image-" + stickerId + ".png"; 69 | 70 | try { 71 | ffmpeg(fileName) 72 | .save(imagePath) 73 | .on("error", async function (err, stdout, stderr) { 74 | inputSanitization.deleteFiles(fileName); 75 | throw err; 76 | }) 77 | .on("end", async () => { 78 | inputSanitization.deleteFiles(fileName); 79 | qrToText(imagePath, processing); 80 | }); 81 | 82 | } catch (err) { 83 | await inputSanitization.handleError(err, client, BotsApp); 84 | } 85 | }; 86 | 87 | try { 88 | if (!BotsApp.isTextReply || (BotsApp.isReplyAudio || BotsApp.isReplyVideo || BotsApp.isReplyAnimatedSticker)) { 89 | 90 | await client 91 | .sendMessage(BotsApp.chatId, DECODE.INVALID_REPLY, MessageType.text) 92 | .catch((err) => inputSanitization.handleError(err, client, BotsApp)); 93 | return; 94 | 95 | } else if (BotsApp.isReplySticker) { 96 | 97 | processing = await client 98 | .sendMessage(BotsApp.chatId, DECODE.PROCESSING, MessageType.text); 99 | var replyChatObject = { 100 | message: chat.message?.extendedTextMessage?.contextInfo?.quotedMessage?.stickerMessage, 101 | type: 'sticker' 102 | }; 103 | var stickerId: string = chat.message?.extendedTextMessage?.contextInfo?.stanzaId; 104 | await convertToImage(stickerId, replyChatObject, processing); 105 | 106 | } else if (BotsApp.isReplyImage) { 107 | 108 | processing = await client 109 | .sendMessage(BotsApp.chatId, DECODE.PROCESSING, MessageType.text); 110 | var imageId: string = chat?.message?.extendedTextMessage?.contextInfo?.stanzaId; 111 | const fileName: string = "./tmp/qr_pic" + imageId; 112 | const stream: Transform = await downloadContentFromMessage(chat.message.extendedTextMessage.contextInfo.quotedMessage.imageMessage, 'image'); 113 | await inputSanitization.saveBuffer(fileName, stream); 114 | qrToText(fileName, processing); 115 | 116 | } else if (!BotsApp.isImage) { 117 | 118 | await client 119 | .sendMessage(BotsApp.chatId, DECODE.INVALID_INPUT, MessageType.text) 120 | .catch((err) => inputSanitization.handleError(err, client, BotsApp)); 121 | return; 122 | 123 | } 124 | 125 | } catch (err) { 126 | await inputSanitization.handleError(err, client, BotsApp); 127 | } 128 | }, 129 | }; 130 | -------------------------------------------------------------------------------- /modules/demote.ts: -------------------------------------------------------------------------------- 1 | import inputSanitization from "../sidekick/input-sanitization"; 2 | import String from "../lib/db.js"; 3 | import Client from "../sidekick/client"; 4 | import { proto } from "@whiskeysockets/baileys"; 5 | import BotsApp from "../sidekick/sidekick"; 6 | import { MessageType } from "../sidekick/message-type"; 7 | const REPLY = String.demote; 8 | 9 | module.exports = { 10 | name: "demote", 11 | description: REPLY.DESCRIPTION, 12 | extendedDescription: REPLY.EXTENDED_DESCRIPTION, 13 | async handle(client: Client, chat: proto.IWebMessageInfo, BotsApp: BotsApp, args: string[]): Promise { 14 | try { 15 | if (!BotsApp.isGroup) { 16 | client.sendMessage( 17 | BotsApp.chatId, 18 | REPLY.NOT_A_GROUP, 19 | MessageType.text 20 | ); 21 | return; 22 | } 23 | await client.getGroupMetaData(BotsApp.chatId, BotsApp); 24 | if (!BotsApp.isBotGroupAdmin) { 25 | client.sendMessage( 26 | BotsApp.chatId, 27 | REPLY.BOT_NOT_ADMIN, 28 | MessageType.text 29 | ); 30 | return; 31 | } 32 | if (!BotsApp.isTextReply && typeof args[0] == "undefined") { 33 | client.sendMessage( 34 | BotsApp.chatId, 35 | REPLY.MESSAGE_NOT_TAGGED, 36 | MessageType.text 37 | ); 38 | return; 39 | } 40 | 41 | const reply = chat.message.extendedTextMessage; 42 | if (BotsApp.isTextReply) { 43 | var contact = reply.contextInfo.participant.split("@")[0]; 44 | } else { 45 | var contact = await inputSanitization.getCleanedContact( 46 | args, 47 | client, 48 | BotsApp 49 | ); 50 | } 51 | var admin = false; 52 | var isMember = await inputSanitization.isMember( 53 | contact, 54 | BotsApp.groupMembers 55 | ); 56 | var owner = false; 57 | for (const index in BotsApp.groupMembers) { 58 | if (contact == BotsApp.groupMembers[index].id.split("@")[0]) { 59 | console.log(BotsApp.groupMembers[index]); 60 | owner = BotsApp.groupMembers[index].admin === 'superadmin'; 61 | admin = BotsApp.groupMembers[index].admin != undefined; 62 | } 63 | } 64 | 65 | if (owner) { 66 | client.sendMessage( 67 | BotsApp.chatId, 68 | "*" + contact + " is the owner of the group*", 69 | MessageType.text 70 | ); 71 | return; 72 | } 73 | 74 | if (isMember) { 75 | if (admin) { 76 | const arr = [contact + "@s.whatsapp.net"]; 77 | await client.sock.groupParticipantsUpdate(BotsApp.chatId, arr, 'demote'); 78 | client.sendMessage( 79 | BotsApp.chatId, 80 | "*" + contact + " is demoted from admin*", 81 | MessageType.text 82 | ); 83 | return; 84 | } else { 85 | client.sendMessage( 86 | BotsApp.chatId, 87 | "*" + contact + " was not an admin*", 88 | MessageType.text 89 | ); 90 | return; 91 | } 92 | } 93 | if (!isMember) { 94 | if (contact === undefined) { 95 | return; 96 | } 97 | 98 | client.sendMessage( 99 | BotsApp.chatId, 100 | REPLY.PERSON_NOT_IN_GROUP, 101 | MessageType.text 102 | ); 103 | return; 104 | } 105 | return; 106 | } catch (err) { 107 | if (err === "NumberInvalid") { 108 | await inputSanitization.handleError( 109 | err, 110 | client, 111 | BotsApp, 112 | "```Invalid number ```" + args[0] 113 | ); 114 | } else { 115 | await inputSanitization.handleError(err, client, BotsApp); 116 | } 117 | } 118 | }, 119 | }; 120 | -------------------------------------------------------------------------------- /modules/disappear.ts: -------------------------------------------------------------------------------- 1 | import STRINGS from "../lib/db.js"; 2 | import inputSanitization from "../sidekick/input-sanitization"; 3 | import Client from "../sidekick/client"; 4 | import { proto } from "@whiskeysockets/baileys"; 5 | import BotsApp from "../sidekick/sidekick"; 6 | import { MessageType } from "../sidekick/message-type" 7 | 8 | module.exports = { 9 | name: "disappear", 10 | description: STRINGS.disappear.DESCRIPTION, 11 | extendedDescription: STRINGS.disappear.EXTENDED_DESCRIPTION, 12 | demo: { isEnabled: true, text: [".disappear", ".disappear off"] }, 13 | async handle(client: Client, chat: proto.IWebMessageInfo, BotsApp: BotsApp, args: string[]): Promise { 14 | try { 15 | var time: any = 7 * 24 * 60 * 60; 16 | if (BotsApp.isPm) { 17 | client.sendMessage( 18 | BotsApp.chatId, 19 | STRINGS.general.NOT_A_GROUP, 20 | MessageType.text 21 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 22 | return; 23 | } 24 | if (BotsApp.isGroup) { 25 | if (chat.message.extendedTextMessage == null) { 26 | await client.sock.sendMessage( 27 | BotsApp.chatId, 28 | {disappearingMessagesInChat: time} 29 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 30 | } else { 31 | await client.sock.sendMessage( 32 | BotsApp.chatId, 33 | {disappearingMessagesInChat: false} 34 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 35 | } 36 | return; 37 | } 38 | if (chat.message.extendedTextMessage.contextInfo.expiration == 0) { 39 | time = 7 * 24 * 60 * 60; 40 | } else { 41 | time = false; 42 | } 43 | await client.sock.sendMessage( 44 | BotsApp.chatId, 45 | {disappearingMessagesInChat: time} 46 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 47 | return; 48 | } catch (err) { 49 | await inputSanitization.handleError(err, client, BotsApp); 50 | } 51 | }, 52 | }; 53 | -------------------------------------------------------------------------------- /modules/getdp.ts: -------------------------------------------------------------------------------- 1 | import inputSanitization from "../sidekick/input-sanitization"; 2 | import fs from "fs"; 3 | import Strings from "../lib/db"; 4 | import Client from "../sidekick/client.js"; 5 | import BotsApp from "../sidekick/sidekick"; 6 | import { MessageType } from "../sidekick/message-type"; 7 | import { proto } from "@whiskeysockets/baileys"; 8 | const GETDP = Strings.getdp; 9 | 10 | module.exports = { 11 | name: "getdp", 12 | description: GETDP.DESCRIPTION, 13 | extendedDescription: GETDP.EXTENDED_DESCRIPTION, 14 | demo: { isEnabled: true, text: ".getdp" }, 15 | async handle(client: Client, chat: proto.IWebMessageInfo, BotsApp: BotsApp, args: string[]): Promise { 16 | const getDp = async (jid: string) => { 17 | let url: string; 18 | try { 19 | url = await client.sock.profilePictureUrl(jid, "image"); 20 | } catch { 21 | try { 22 | url = await client.sock.profilePictureUrl(jid); 23 | } catch(err) { 24 | if (err.data === 404 || err.data === 401) { 25 | return err; 26 | } else { 27 | console.log('Error in getting profile pic - ' + console.log(err)); 28 | } 29 | } 30 | } 31 | return url; 32 | }; 33 | 34 | try { 35 | let url: string; 36 | if (!args[0]) { 37 | url = await getDp(BotsApp.chatId); 38 | } else { 39 | let jid: string = args[0].split("@")[1] + "@s.whatsapp.net"; 40 | url = await getDp(jid); 41 | } 42 | 43 | if(typeof(url) === 'object'){ 44 | await client.sendMessage( 45 | BotsApp.chatId, 46 | fs.readFileSync("./images/default_dp.png"), 47 | MessageType.image, 48 | { 49 | caption: "```This is the display picture visible to me. :P```", 50 | } 51 | ); 52 | return; 53 | } 54 | 55 | await client.sendMessage( 56 | BotsApp.chatId, 57 | { url: url }, 58 | MessageType.image, 59 | { 60 | caption: GETDP.IMAGE_CAPTION 61 | } 62 | ); 63 | return 64 | } catch (err) { 65 | await inputSanitization.handleError(err, client, BotsApp); 66 | return; 67 | } 68 | }, 69 | }; 70 | -------------------------------------------------------------------------------- /modules/github.ts: -------------------------------------------------------------------------------- 1 | import inputSanitization from "../sidekick/input-sanitization"; 2 | import STRINGS from "../lib/db"; 3 | import got, {Response} from "got"; 4 | import Client from "../sidekick/client.js"; 5 | import BotsApp from "../sidekick/sidekick"; 6 | import { MessageType } from "../sidekick/message-type"; 7 | import { proto } from "@whiskeysockets/baileys"; 8 | 9 | module.exports = { 10 | name: "github", 11 | description: STRINGS.github.DESCRIPTION, 12 | extendedDescription: STRINGS.github.EXTENDED_DESCRIPTION, 13 | demo: { isEnabled: true, text: ".github Prince-Mendiratta" }, 14 | async handle(client: Client, chat: proto.IWebMessageInfo, BotsApp: BotsApp, args: string[]): Promise { 15 | try { 16 | let user_name: string = ""; 17 | if (BotsApp.isTextReply) { 18 | user_name = BotsApp.replyMessage; 19 | } else { 20 | if (args.length == 0) { 21 | client.sendMessage( 22 | BotsApp.chatId, 23 | STRINGS.github.NO_ARG_ERROR, 24 | MessageType.text 25 | ); 26 | return; 27 | } 28 | user_name = args[0]; 29 | } 30 | var fetching: proto.WebMessageInfo = await client.sendMessage( 31 | BotsApp.chatId, 32 | STRINGS.github.FETCHING, 33 | MessageType.text 34 | ); 35 | let userResponse: Response = await got( 36 | "https://api.github.com/users/" + user_name 37 | ); 38 | let user: any = JSON.parse(userResponse.body); 39 | Object.keys(user).forEach(function (key) { 40 | if (user[key] === null || user[key] === "") { 41 | user[key] = "N/A"; 42 | } 43 | }); 44 | let caption: string = 45 | "*👤 Name :* " + 46 | user.name + 47 | "\n*💻 Link :* " + 48 | user.html_url + 49 | "\n*🔧 Type :* " + 50 | user.type + 51 | "\n*🏢 Company :* " + 52 | user.company + 53 | "\n*🔭 Blog :* " + 54 | user.blog + 55 | "\n*📍 Location :* " + 56 | user.location + 57 | "\n*📝 Bio :* " + 58 | user.bio + 59 | "\n*❤️ Followers :* " + 60 | user.followers + 61 | "\n*👁️ Following :* " + 62 | user.following + 63 | "\n*📊 Public Repos :* " + 64 | user.public_repos + 65 | "\n*📄 Public Gists :* " + 66 | user.public_gists + 67 | "\n*🔗 Profile Created :* " + 68 | user.created_at + 69 | "\n*✏️ Profile Updated :* " + 70 | user.updated_at; 71 | if (user.public_repos > 0) { 72 | let reposResponse: Response = await got(user.repos_url); 73 | let reposData: any = JSON.parse(reposResponse.body); 74 | let repos: string = reposData[0].name; 75 | for (let i = 1; i < reposData.length && i < 5; i++) { 76 | repos += " | " + reposData[i].name; 77 | } 78 | caption += "\n*🔍 Some Repos :* " + repos; 79 | } 80 | try { 81 | await client.sendMessage( 82 | BotsApp.chatId, 83 | { 84 | url: user.avatar_url, 85 | }, 86 | MessageType.image, 87 | { 88 | caption: caption, 89 | } 90 | ); 91 | } catch (err) { 92 | client.sendMessage(BotsApp.chatId, caption, MessageType.text); 93 | } 94 | return await client.deleteMessage(BotsApp.chatId, { 95 | id: fetching.key.id, 96 | remoteJid: BotsApp.chatId, 97 | fromMe: true, 98 | }); 99 | } catch (err) { 100 | await inputSanitization.handleError( 101 | err, 102 | client, 103 | BotsApp, 104 | STRINGS.github.ERROR_MSG 105 | ); 106 | return await client.deleteMessage(BotsApp.chatId, { 107 | id: fetching.key.id, 108 | remoteJid: BotsApp.chatId, 109 | fromMe: true, 110 | }); 111 | } 112 | }, 113 | }; 114 | -------------------------------------------------------------------------------- /modules/goodbye.ts: -------------------------------------------------------------------------------- 1 | import Strings from "../lib/db"; 2 | import inputSanitization from "../sidekick/input-sanitization"; 3 | import Greetings from "../database/greeting"; 4 | import Client from "../sidekick/client"; 5 | import { proto } from "@whiskeysockets/baileys"; 6 | import BotsApp from "../sidekick/sidekick"; 7 | import { MessageType } from "../sidekick/message-type"; 8 | const GOODBYE = Strings.goodbye; 9 | 10 | module.exports = { 11 | name: "goodbye", 12 | description: GOODBYE.DESCRIPTION, 13 | extendedDescription: GOODBYE.EXTENDED_DESCRIPTION, 14 | demo: { 15 | isEnabled: true, 16 | text: [".goodbye", ".goodbye off", ".goodbye delete"], 17 | }, 18 | async handle(client: Client, chat: proto.IWebMessageInfo, BotsApp: BotsApp, args: string[]): Promise { 19 | try { 20 | if (!BotsApp.isGroup) { 21 | client.sendMessage( 22 | BotsApp.chatId, 23 | GOODBYE.NOT_A_GROUP, 24 | MessageType.text 25 | ); 26 | return; 27 | } 28 | if (args.length == 0) { 29 | await client.getGroupMetaData(BotsApp.chatId, BotsApp); 30 | var Msg: any = await Greetings.getMessage(BotsApp.chatId, "goodbye"); 31 | try { 32 | var enabled = await Greetings.checkSettings( 33 | BotsApp.chatId, 34 | "goodbye" 35 | ); 36 | if (enabled === false || enabled === undefined) { 37 | client.sendMessage( 38 | BotsApp.chatId, 39 | GOODBYE.SET_GOODBYE_FIRST, 40 | MessageType.text 41 | ); 42 | return; 43 | } else if (enabled === "OFF") { 44 | await client.sendMessage( 45 | BotsApp.chatId, 46 | GOODBYE.CURRENTLY_DISABLED, 47 | MessageType.text 48 | ); 49 | await client.sendMessage( 50 | BotsApp.chatId, 51 | Msg.message, 52 | MessageType.text 53 | ); 54 | return; 55 | } 56 | 57 | await client.sendMessage( 58 | BotsApp.chatId, 59 | GOODBYE.CURRENTLY_ENABLED, 60 | MessageType.text 61 | ); 62 | await client.sendMessage( 63 | BotsApp.chatId, 64 | Msg.message, 65 | MessageType.text 66 | ); 67 | } catch (err) { 68 | throw err; 69 | } 70 | } else { 71 | try { 72 | if ( 73 | args[0] === "OFF" || 74 | args[0] === "off" || 75 | args[0] === "Off" 76 | ) { 77 | let switched = "OFF"; 78 | await Greetings.changeSettings( 79 | BotsApp.chatId, 80 | switched 81 | ); 82 | client.sendMessage( 83 | BotsApp.chatId, 84 | GOODBYE.GREETINGS_UNENABLED, 85 | MessageType.text 86 | ); 87 | return; 88 | } 89 | if ( 90 | args[0] === "ON" || 91 | args[0] === "on" || 92 | args[0] === "On" 93 | ) { 94 | let switched = "ON"; 95 | await Greetings.changeSettings( 96 | BotsApp.chatId, 97 | switched 98 | ); 99 | client.sendMessage( 100 | BotsApp.chatId, 101 | GOODBYE.GREETINGS_ENABLED, 102 | MessageType.text 103 | ); 104 | return; 105 | } 106 | if (args[0] === "delete") { 107 | var Msg: any = await Greetings.deleteMessage( 108 | BotsApp.chatId, 109 | "goodbye" 110 | ); 111 | if (Msg === false || Msg === undefined) { 112 | client.sendMessage( 113 | BotsApp.chatId, 114 | GOODBYE.SET_GOODBYE_FIRST, 115 | MessageType.text 116 | ); 117 | return; 118 | } 119 | await client.sendMessage( 120 | BotsApp.chatId, 121 | GOODBYE.GOODBYE_DELETED, 122 | MessageType.text 123 | ); 124 | 125 | return; 126 | } 127 | let text = BotsApp.body.replace( 128 | BotsApp.body[0] + BotsApp.commandName + " ", 129 | "" 130 | ); 131 | 132 | var Msg: any = await Greetings.getMessage( 133 | BotsApp.chatId, 134 | "goodbye" 135 | ); 136 | if (Msg === false || Msg === undefined) { 137 | await Greetings.setGoodbye(BotsApp.chatId, text); 138 | await client.sendMessage( 139 | BotsApp.chatId, 140 | GOODBYE.GOODBYE_UPDATED, 141 | MessageType.text 142 | ); 143 | 144 | return; 145 | } else { 146 | await Greetings.deleteMessage( 147 | BotsApp.chatId, 148 | "goodbye" 149 | ); 150 | await Greetings.setGoodbye(BotsApp.chatId, text); 151 | await client.sendMessage( 152 | BotsApp.chatId, 153 | GOODBYE.GOODBYE_UPDATED, 154 | MessageType.text 155 | ); 156 | return; 157 | } 158 | } catch (err) { 159 | throw err; 160 | } 161 | } 162 | } catch (err) { 163 | await inputSanitization.handleError(err, client, BotsApp); 164 | } 165 | }, 166 | }; 167 | -------------------------------------------------------------------------------- /modules/help.ts: -------------------------------------------------------------------------------- 1 | import Strings from "../lib/db"; 2 | import format from "string-format"; 3 | import inputSanitization from "../sidekick/input-sanitization"; 4 | import config from "../config"; 5 | import Client from "../sidekick/client.js"; 6 | import BotsApp from "../sidekick/sidekick"; 7 | import { MessageType } from "../sidekick/message-type"; 8 | import { AnyMediaMessageContent, AnyMessageContent, proto } from "@whiskeysockets/baileys"; 9 | import Command from "../sidekick/command"; 10 | const HELP = Strings.help; 11 | 12 | module.exports = { 13 | name: "help", 14 | description: HELP.DESCRIPTION, 15 | extendedDescription: HELP.EXTENDED_DESCRIPTION, 16 | demo: {isEnabled: false}, 17 | async handle(client: Client, chat: proto.IWebMessageInfo, BotsApp: BotsApp, args: string[], commandHandler: Map): Promise { 18 | try { 19 | var prefixRegex: any = new RegExp(config.PREFIX, "g"); 20 | var prefixes: string = /\/\^\[(.*)+\]\/\g/g.exec(prefixRegex)[1]; 21 | let helpMessage: string; 22 | if(!args[0]){ 23 | helpMessage = HELP.HEAD; 24 | commandHandler.forEach(element => { 25 | helpMessage += format(HELP.TEMPLATE, prefixes[0] + element.name, element.description); 26 | }); 27 | client.sendMessage(BotsApp.chatId, helpMessage, MessageType.text).catch(err => inputSanitization.handleError(err, client, BotsApp)); 28 | return; 29 | } 30 | helpMessage = HELP.COMMAND_INTERFACE; 31 | var command: Command = commandHandler.get(args[0]); 32 | if(command){ 33 | var triggers: string = " | " 34 | prefixes.split("").forEach(prefix => { 35 | triggers += prefix + command.name + " | " 36 | }); 37 | 38 | if(command.demo?.isEnabled) { 39 | var buttons: proto.Message.ButtonsMessage.IButton[] = []; 40 | helpMessage += format(HELP.COMMAND_INTERFACE_TEMPLATE, triggers, command.extendedDescription) + HELP.FOOTER; 41 | if(command.demo.text instanceof Array){ 42 | for (var i in command.demo.text){ 43 | var button: proto.Message.ButtonsMessage.IButton = { 44 | buttonId: 'id' + i, 45 | buttonText: {displayText: command.demo.text[i]}, 46 | type: 1 47 | } 48 | buttons.push(button); 49 | } 50 | }else{ 51 | buttons.push({buttonId: 'id1', buttonText: {displayText: command.demo.text}, type: 1}); 52 | } 53 | const buttonMessage = { 54 | text: helpMessage, 55 | buttons: buttons, 56 | headerType: 1 57 | } 58 | await client.sendMessage(BotsApp.chatId, buttonMessage, MessageType.buttonsMessage).catch(err => inputSanitization.handleError(err, client, BotsApp)) 59 | return; 60 | } 61 | 62 | helpMessage += format(HELP.COMMAND_INTERFACE_TEMPLATE, triggers, command.extendedDescription); 63 | client.sendMessage(BotsApp.chatId, helpMessage, MessageType.text).catch(err => inputSanitization.handleError(err, client, BotsApp)); 64 | return; 65 | } 66 | client.sendMessage(BotsApp.chatId, HELP.COMMAND_INTERFACE + "```Invalid Command. Check the correct name from``` *.help* ```command list.```", MessageType.text).catch(err => inputSanitization.handleError(err, client, BotsApp)); 67 | } catch (err) { 68 | await inputSanitization.handleError(err, client, BotsApp); 69 | } 70 | }, 71 | }; 72 | -------------------------------------------------------------------------------- /modules/invite.ts: -------------------------------------------------------------------------------- 1 | import inputSanitization from "../sidekick/input-sanitization"; 2 | import STRINGS from "../lib/db.js"; 3 | import Client from "../sidekick/client"; 4 | import { proto } from "@whiskeysockets/baileys"; 5 | import BotsApp from "../sidekick/sidekick"; 6 | import { MessageType } from "../sidekick/message-type" 7 | 8 | module.exports = { 9 | name: "invite", 10 | description: STRINGS.invite.DESCRIPTION, 11 | extendedDescription: STRINGS.invite.EXTENDED_DESCRIPTION, 12 | demo: { isEnabled: false }, 13 | async handle(client: Client, chat: proto.IWebMessageInfo, BotsApp: BotsApp, args: string[]): Promise { 14 | try { 15 | if (!BotsApp.isGroup) { 16 | client.sendMessage( 17 | BotsApp.chatId, 18 | STRINGS.general.NOT_A_GROUP, 19 | MessageType.text 20 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 21 | return; 22 | } 23 | await client.getGroupMetaData(BotsApp.chatId, BotsApp); 24 | if (!BotsApp.isBotGroupAdmin) { 25 | client.sendMessage( 26 | BotsApp.chatId, 27 | STRINGS.general.BOT_NOT_ADMIN, 28 | MessageType.text 29 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 30 | return; 31 | } 32 | const code = await client.sock.groupInviteCode(BotsApp.chatId); 33 | if (BotsApp.isTextReply) { 34 | client.sendMessage( 35 | chat.message.extendedTextMessage.contextInfo.participant, 36 | "https://chat.whatsapp.com/" + code, 37 | MessageType.text 38 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 39 | client.sendMessage( 40 | BotsApp.chatId, 41 | STRINGS.invite.LINK_SENT, 42 | MessageType.text 43 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 44 | return; 45 | } 46 | client.sendMessage( 47 | BotsApp.chatId, 48 | "https://chat.whatsapp.com/" + code, 49 | MessageType.text 50 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 51 | return; 52 | } catch (err) { 53 | await inputSanitization.handleError(err, client, BotsApp); 54 | } 55 | }, 56 | }; 57 | -------------------------------------------------------------------------------- /modules/lyrics.ts: -------------------------------------------------------------------------------- 1 | import Client from "../sidekick/client.js"; 2 | import BotsApp from "../sidekick/sidekick"; 3 | import { MessageType } from "../sidekick/message-type"; 4 | import { proto } from "@whiskeysockets/baileys"; 5 | import got, {Response} from "got"; 6 | import inputSanitization from "../sidekick/input-sanitization"; 7 | import STRINGS from "../lib/db"; 8 | 9 | const songlyrics = require("songlyrics").default; 10 | 11 | module.exports = { 12 | name: "lyrics", 13 | description: STRINGS.lyrics.DESCRIPTION, 14 | extendedDescription: STRINGS.lyrics.EXTENDED_DESCRIPTION, 15 | demo: { isEnabled: true, text: ".lyrics Stairway to heaven" }, 16 | async handle(client: Client, chat: proto.IWebMessageInfo, BotsApp: BotsApp, args: string[]): Promise { 17 | const processing: proto.WebMessageInfo = await client.sendMessage( 18 | BotsApp.chatId, 19 | STRINGS.lyrics.PROCESSING, 20 | MessageType.text 21 | ); 22 | try { 23 | var song: string = ""; 24 | if (BotsApp.isTextReply) { 25 | song = BotsApp.replyMessage; 26 | } else if (args.length == 0) { 27 | client.sendMessage( 28 | BotsApp.chatId, 29 | STRINGS.lyrics.NO_ARG, 30 | MessageType.text 31 | ); 32 | return; 33 | } else { 34 | song = args.join(" "); 35 | } 36 | let Response: Response = await got( 37 | `https://some-random-api.ml/lyrics/?title=${song}` 38 | ); 39 | let data = JSON.parse(Response.body); 40 | let caption: string = 41 | "*Title :* " + 42 | data.title + 43 | "\n*Author :* " + 44 | data.author + 45 | "\n*Lyrics :*\n" + 46 | data.lyrics; 47 | 48 | try { 49 | await client.sendMessage( 50 | BotsApp.chatId, 51 | { url: data.thumbnail.genius }, 52 | MessageType.image, 53 | { 54 | caption: caption, 55 | } 56 | ); 57 | } catch (err) { 58 | client.sendMessage(BotsApp.chatId, caption, MessageType.text); 59 | } 60 | await client.deleteMessage(BotsApp.chatId, { 61 | id: processing.key.id, 62 | remoteJid: BotsApp.chatId, 63 | fromMe: true, 64 | }); 65 | // return; 66 | } catch (err) { 67 | try{ 68 | let data = await songlyrics(song) 69 | let caption: string = 70 | "*Title :* " + 71 | song + 72 | "\n*Source :* " + 73 | data.source.link + 74 | "\n*Lyrics :*\n" + 75 | data.lyrics; 76 | 77 | await client.sendMessage(BotsApp.chatId, caption, MessageType.text); 78 | await client.deleteMessage(BotsApp.chatId, { 79 | id: processing.key.id, 80 | remoteJid: BotsApp.chatId, 81 | fromMe: true, 82 | }); 83 | }catch(err){ 84 | await inputSanitization.handleError( 85 | err, 86 | client, 87 | BotsApp, 88 | STRINGS.lyrics.NOT_FOUND 89 | ); 90 | return await client.deleteMessage(BotsApp.chatId, { 91 | id: processing.key.id, 92 | remoteJid: BotsApp.chatId, 93 | fromMe: true, 94 | }); 95 | } 96 | } 97 | }, 98 | }; 99 | -------------------------------------------------------------------------------- /modules/meaning.ts: -------------------------------------------------------------------------------- 1 | import Strings from "../lib/db"; 2 | import inputSanitization from "../sidekick/input-sanitization"; 3 | import googleDictionaryApi from "google-dictionary-api"; 4 | import Client from "../sidekick/client.js"; 5 | import BotsApp from "../sidekick/sidekick"; 6 | import format from "string-format"; 7 | import { MessageType } from "../sidekick/message-type"; 8 | import { proto } from "@whiskeysockets/baileys"; 9 | 10 | const MEANING = Strings.meaning; 11 | 12 | module.exports = { 13 | name: "meaning", 14 | description: MEANING.DESCRIPTION, 15 | extendedDescription: MEANING.EXTENDED_DESCRIPTION, 16 | demo: {isEnabled: true, text: ".meaning meaning"}, 17 | async handle(client: Client, chat: proto.IWebMessageInfo, BotsApp: BotsApp, args: string[]): Promise { 18 | try { 19 | var word: string = ""; 20 | if (BotsApp.isTextReply) { 21 | word = BotsApp.replyMessage; 22 | } else if (args.length === 0) { 23 | client.sendMessage( 24 | BotsApp.chatId, 25 | MEANING.NO_ARG, 26 | MessageType.text 27 | ); 28 | return; 29 | } else { 30 | word = args.join(" "); 31 | } 32 | googleDictionaryApi 33 | .search(word) 34 | .then((results) => { 35 | let mean: string = ""; 36 | for(let key in results[0].meaning){ 37 | mean += "\n\n" 38 | mean += "*[" + key + "]* : " 39 | mean += results[0].meaning[key][0].definition 40 | } 41 | const msg: string = 42 | "*Word :* " + results[0].word + "\n\n*Meaning :*" + mean; 43 | client 44 | .sendMessage(BotsApp.chatId, msg, MessageType.text) 45 | .catch((err) => 46 | inputSanitization.handleError(err, client, BotsApp) 47 | ); 48 | }) 49 | .catch(() => { 50 | client 51 | .sendMessage( 52 | BotsApp.chatId, 53 | format(MEANING.NOT_FOUND, word), 54 | MessageType.text 55 | ) 56 | .catch((err) => 57 | inputSanitization.handleError(err, client, BotsApp) 58 | ); 59 | }); 60 | } catch (err) { 61 | await inputSanitization.handleError(err, client, BotsApp); 62 | } 63 | }, 64 | }; 65 | -------------------------------------------------------------------------------- /modules/mute.bak: -------------------------------------------------------------------------------- 1 | import inputSanitization from "../sidekick/input-sanitization"; 2 | import Strings from "../lib/db"; 3 | import Client from "../sidekick/client.js"; 4 | import BotsApp from "../sidekick/sidekick"; 5 | import format from "string-format"; 6 | import { MessageType } from "../sidekick/message-type"; 7 | import { proto } from "@whiskeysockets/baileys"; 8 | 9 | const MUTE = Strings.mute; 10 | 11 | module.exports = { 12 | name: "mute", 13 | description: MUTE.DESCRIPTION, 14 | extendedDescription: MUTE.EXTENDED_DESCRIPTION, 15 | demo: { isEnabled: true, text: [".mute", ".mute 10 s", ".mute 1 h"] }, 16 | async handle(client: Client, chat: proto.IWebMessageInfo, BotsApp: BotsApp, args: string[]): Promise { 17 | try { 18 | if (!BotsApp.isGroup) { 19 | client.sendMessage( 20 | BotsApp.chatId, 21 | MUTE.NOT_GROUP_CHAT, 22 | MessageType.text 23 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 24 | return; 25 | } 26 | await client.getGroupMetaData(BotsApp.chatId, BotsApp); 27 | if (!BotsApp.isBotGroupAdmin) { 28 | client.sendMessage( 29 | BotsApp.chatId, 30 | MUTE.NOT_ADMIN, 31 | MessageType.text 32 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 33 | return; 34 | } 35 | if (!args[0]) { 36 | const ok = await client.sock.chatModify( 37 | { mute: 8*60*60*1000 }, 38 | BotsApp.chatId 39 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 40 | console.log(ok); 41 | client.sendMessage( 42 | BotsApp.chatId, 43 | MUTE.CHAT_ADMIN_ONLY, 44 | MessageType.text 45 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 46 | return; 47 | } else if (parseInt(args[0]) === NaN) { 48 | client.sendMessage( 49 | BotsApp.chatId, 50 | MUTE.MENTION_DURATION, 51 | MessageType.text 52 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 53 | return; 54 | } 55 | 56 | var duration: number = parseInt(args[0]); 57 | var type: string = "minutes"; 58 | if (args[1] === "s") { 59 | duration = duration * 1000; 60 | type = "seconds"; 61 | } else if (args[1] === "m") { 62 | duration = duration * 60 * 1000; 63 | type = "minutes"; 64 | } else if (args[1] === "h") { 65 | duration = duration * 60 * 60 * 1000; 66 | type = "hours"; 67 | } else { 68 | duration = duration * 60 * 1000; // default to minutes 69 | } 70 | 71 | await client.sock.chatModify( 72 | { mute: duration }, 73 | BotsApp.chatId 74 | ); 75 | client.sendMessage( 76 | BotsApp.chatId, 77 | "```Chat permissions changed to``` *admin only* ```for " + 78 | args[0] + 79 | " " + 80 | type + 81 | ".```", 82 | MessageType.text 83 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 84 | setTimeout(async () => { 85 | await client.sock.chatModify( 86 | { mute: null }, 87 | BotsApp.chatId 88 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 89 | client.sendMessage( 90 | BotsApp.chatId, 91 | MUTE.CHAT_ALL_MEMBERS, 92 | MessageType.text 93 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 94 | }, duration); 95 | } catch (err) { 96 | await inputSanitization.handleError(err, client, BotsApp); 97 | } 98 | }, 99 | }; 100 | -------------------------------------------------------------------------------- /modules/news.ts: -------------------------------------------------------------------------------- 1 | import STRINGS from "../lib/db.js"; 2 | import Client from "../sidekick/client"; 3 | import { proto } from "@whiskeysockets/baileys"; 4 | import BotsApp from "../sidekick/sidekick"; 5 | import { MessageType } from "../sidekick/message-type"; 6 | import inputSanitization from "../sidekick/input-sanitization"; 7 | import Axios from "axios"; 8 | import config from "../config"; 9 | const NEWS = STRINGS.news; 10 | 11 | module.exports = { 12 | name: "news", 13 | description: NEWS.DESCRIPTION, 14 | extendedDescription: NEWS.EXTENDED_DESCRIPTION, 15 | demo: { 16 | isEnabled: true, 17 | text: [ 18 | ".news search The Times", 19 | ".news fetch The Hindu" 20 | ] 21 | }, 22 | async handle( 23 | client: Client, 24 | chat: proto.IWebMessageInfo, 25 | BotsApp: BotsApp, 26 | args: string[] 27 | ): Promise { 28 | /******************************************* 29 | * 30 | * 31 | * Functions 32 | * 33 | * 34 | ********************************************/ 35 | const checkPub = async (newsList: string[], requestedPub: string) => { 36 | for (let i = 0; i < newsList.length; i++) { 37 | if (newsList[i].toUpperCase == requestedPub.toUpperCase) { 38 | return newsList[i]; 39 | } 40 | return; 41 | } 42 | }; 43 | /******************************************* 44 | * 45 | * 46 | * Actions 47 | * 48 | * 49 | ********************************************/ 50 | if (args.length === 0) { 51 | await client 52 | .sendMessage(BotsApp.chatId, NEWS.NO_COMMMAND, MessageType.text) 53 | .catch((err) => inputSanitization.handleError(err, client, BotsApp)); 54 | return; 55 | } 56 | if (args[0] == "help") { 57 | await client 58 | .sendMessage( 59 | BotsApp.chatId, 60 | NEWS.EXTENDED_DESCRIPTION, 61 | MessageType.text 62 | ) 63 | .catch((err) => inputSanitization.handleError(err, client, BotsApp)); 64 | return; 65 | } 66 | if (args[0] == "search") { 67 | args.shift(); 68 | var searchTerm = args.join(" "); 69 | let searchResponse; 70 | try { 71 | await Axios.get( 72 | config.NEWS_API_URL + "news-list?searchTerm=" + searchTerm 73 | ) 74 | .then((res) => { 75 | searchResponse = res.data; 76 | }) 77 | .catch((error) => { 78 | console.error(error); 79 | }); 80 | } catch (error) { 81 | throw error; 82 | } 83 | 84 | for (let i = 0; i < searchResponse.length; i++) { 85 | searchResponse[i] = `${i + 1}` + ".) " + `${searchResponse[i]}`; 86 | } 87 | 88 | let message = "```The following publications are available with the term ``` *" + searchTerm + "* ``` in it:``` \n\n" + searchResponse.join("\n\n"); 89 | if (searchResponse.length < 1) { 90 | message = "```Sorry, no publication found by that name!```" 91 | } 92 | await client 93 | .sendMessage(BotsApp.chatId, message, MessageType.text) 94 | .catch((err) => inputSanitization.handleError(err, client, BotsApp)); 95 | return; 96 | } 97 | if (args[0] == "fetch") { 98 | args.shift(); 99 | var searchTerm = args.join(" "); 100 | if (!searchTerm) { 101 | await client 102 | .sendMessage(BotsApp.chatId, NEWS.NO_PUB_NAME, MessageType.text) 103 | .catch((err) => inputSanitization.handleError(err, client, BotsApp)); 104 | return; 105 | } 106 | let searchResponse; 107 | try { 108 | await Axios.get( 109 | config.NEWS_API_URL + "news-list?searchTerm=" + searchTerm 110 | ) 111 | .then((res) => { 112 | searchResponse = res.data; 113 | }) 114 | .catch((error) => { 115 | console.error(error); 116 | }); 117 | } catch (error) { 118 | throw error; 119 | } 120 | let foundPub = await checkPub(searchResponse, searchTerm); 121 | let message = 122 | "```Your requested publication``` *" + 123 | foundPub + 124 | "* ```is being fetched by BotsApp, this may take some time, please be patient!```"; 125 | if (!foundPub) { 126 | message = "```Sorry, no publication found by that name!```"; 127 | await client 128 | .sendMessage(BotsApp.chatId, message, MessageType.text) 129 | .catch((err) => inputSanitization.handleError(err, client, BotsApp)); 130 | return; 131 | } 132 | await client 133 | .sendMessage( 134 | BotsApp.chatId, 135 | { 136 | url: 137 | config.NEWS_API_URL + "news?pubName=" + foundPub + "&format=epub", 138 | }, 139 | MessageType.document, 140 | { 141 | mimetype: "application/epub", 142 | filename: foundPub + ".epub", 143 | caption: message, 144 | } 145 | ) 146 | .catch((err) => inputSanitization.handleError(err, client, BotsApp)); 147 | message = "```Your requested publication fetched by BotsApp``` ☝️"; 148 | await client 149 | .sendMessage(BotsApp.chatId, message, MessageType.text) 150 | .catch((err) => inputSanitization.handleError(err, client, BotsApp)); 151 | return; 152 | } 153 | }, 154 | }; 155 | -------------------------------------------------------------------------------- /modules/ocr.ts: -------------------------------------------------------------------------------- 1 | import ocrSpace from "ocr-space-api-wrapper"; 2 | import STRINGS from "../lib/db.js"; 3 | import config from "../config"; 4 | import inputSanitization from "../sidekick/input-sanitization"; 5 | import Client from "../sidekick/client"; 6 | import { downloadContentFromMessage, proto } from "@whiskeysockets/baileys"; 7 | import BotsApp from "../sidekick/sidekick"; 8 | import { MessageType } from "../sidekick/message-type"; 9 | import { Transform } from "stream"; 10 | const OCR = STRINGS.ocr; 11 | 12 | module.exports = { 13 | name: "ocr", 14 | description: OCR.DESCRIPTION, 15 | extendedDescription: OCR.EXTENDED_DESCRIPTION, 16 | async handle(client: Client, chat: proto.IWebMessageInfo, BotsApp: BotsApp, args: string[]): Promise{ 17 | try { 18 | 19 | if (BotsApp.isImage) { 20 | const processing = await client.sendMessage( 21 | BotsApp.chatId, 22 | OCR.PROCESSING, 23 | MessageType.text 24 | ); 25 | var replyChatObject = { 26 | message: chat.message.imageMessage, 27 | }; 28 | var imageId = chat.key.id; 29 | const fileName = "./tmp/img-" + imageId + '.png'; 30 | const stream: Transform = await downloadContentFromMessage(replyChatObject.message, 'image'); 31 | await inputSanitization.saveBuffer(fileName, stream); 32 | try { 33 | const text = await ocrSpace(fileName, { 34 | apiKey: config.OCR_API_KEY, 35 | }); 36 | var Msg = text.ParsedResults[0].ParsedText; 37 | if (Msg === "") { 38 | client.sendMessage( 39 | BotsApp.chatId, 40 | OCR.NO_TEXT, 41 | MessageType.text 42 | ); 43 | return await client.deleteMessage(BotsApp.chatId, { 44 | id: processing.key.id, 45 | remoteJid: BotsApp.chatId, 46 | fromMe: true, 47 | }); 48 | } 49 | await client.sendMessage(BotsApp.chatId, Msg, MessageType.text); 50 | } catch (error) { 51 | throw error; 52 | } 53 | inputSanitization.deleteFiles(fileName); 54 | return await client.deleteMessage(BotsApp.chatId, { 55 | id: processing.key.id, 56 | remoteJid: BotsApp.chatId, 57 | fromMe: true, 58 | }); 59 | }else if (BotsApp.isReplyImage) { 60 | const processing = await client.sendMessage( 61 | BotsApp.chatId, 62 | OCR.PROCESSING, 63 | MessageType.text 64 | ); 65 | var replyChatObject = { 66 | message: 67 | chat.message.extendedTextMessage.contextInfo 68 | .quotedMessage.imageMessage, 69 | }; 70 | var imageId = 71 | chat.message.extendedTextMessage.contextInfo.stanzaId; 72 | const fileName = "./tmp/img-" + imageId + '.png'; 73 | const stream: Transform = await downloadContentFromMessage(replyChatObject.message, 'image'); 74 | await inputSanitization.saveBuffer(fileName, stream); 75 | try { 76 | const text = await ocrSpace(fileName, { 77 | apiKey: config.OCR_API_KEY, 78 | }); 79 | console.log(text); 80 | var Msg = text.ParsedResults[0].ParsedText; 81 | if (Msg === "") { 82 | client.sendMessage( 83 | BotsApp.chatId, 84 | OCR.NO_TEXT, 85 | MessageType.text 86 | ); 87 | return await client.deleteMessage(BotsApp.chatId, { 88 | id: processing.key.id, 89 | remoteJid: BotsApp.chatId, 90 | fromMe: true, 91 | }); 92 | } 93 | await client.sendMessage(BotsApp.chatId, Msg, MessageType.text); 94 | } catch (error) { 95 | throw error; 96 | } 97 | inputSanitization.deleteFiles(fileName); 98 | return client.deleteMessage(BotsApp.chatId, { 99 | id: processing.key.id, 100 | remoteJid: BotsApp.chatId, 101 | fromMe: true, 102 | }); 103 | }else{ 104 | await client.sendMessage( 105 | BotsApp.chatId, 106 | OCR.ERROR_MSG, 107 | MessageType.text 108 | ); 109 | } 110 | setTimeout(async () => { 111 | await client.sendMessage( 112 | BotsApp.chatId, 113 | OCR.ERROR_MSG, 114 | MessageType.text 115 | ); 116 | return; 117 | }, 300000); 118 | return; 119 | } catch (err) { 120 | await inputSanitization.handleError(err, client, BotsApp); 121 | } 122 | }, 123 | }; 124 | -------------------------------------------------------------------------------- /modules/promote.ts: -------------------------------------------------------------------------------- 1 | import inputSanitization from "../sidekick/input-sanitization"; 2 | import String from "../lib/db.js"; 3 | import Client from "../sidekick/client"; 4 | import { proto } from "@whiskeysockets/baileys"; 5 | import BotsApp from "../sidekick/sidekick"; 6 | import { MessageType } from "../sidekick/message-type"; 7 | const REPLY = String.promote; 8 | 9 | module.exports = { 10 | name: "promote", 11 | description: REPLY.DESCRIPTION, 12 | extendedDescription: REPLY.EXTENDED_DESCRIPTION, 13 | async handle(client: Client, chat: proto.IWebMessageInfo, BotsApp: BotsApp, args: string[]): Promise { 14 | try { 15 | if (!BotsApp.isGroup) { 16 | client.sendMessage( 17 | BotsApp.chatId, 18 | REPLY.NOT_A_GROUP, 19 | MessageType.text 20 | ); 21 | return; 22 | } 23 | await client.getGroupMetaData(BotsApp.chatId, BotsApp); 24 | if (!BotsApp.isBotGroupAdmin) { 25 | client.sendMessage( 26 | BotsApp.chatId, 27 | REPLY.BOT_NOT_ADMIN, 28 | MessageType.text 29 | ); 30 | return; 31 | } 32 | if (!BotsApp.isTextReply && typeof args[0] == "undefined") { 33 | client.sendMessage( 34 | BotsApp.chatId, 35 | REPLY.MESSAGE_NOT_TAGGED, 36 | MessageType.text 37 | ); 38 | return; 39 | } 40 | const reply = chat.message.extendedTextMessage; 41 | 42 | if (BotsApp.isTextReply) { 43 | var contact = reply.contextInfo.participant.split("@")[0]; 44 | } else { 45 | var contact = await inputSanitization.getCleanedContact( 46 | args, 47 | client, 48 | BotsApp 49 | ); 50 | } 51 | 52 | var admin = false; 53 | var isMember = await inputSanitization.isMember( 54 | contact, 55 | BotsApp.groupMembers 56 | ); 57 | for (const index in BotsApp.groupMembers) { 58 | if (contact == BotsApp.groupMembers[index].id.split("@")[0]) { 59 | admin = BotsApp.groupMembers[index].admin != undefined; 60 | } 61 | } 62 | if (isMember) { 63 | if (!admin) { 64 | const arr = [contact + "@s.whatsapp.net"]; 65 | await client.sock.groupParticipantsUpdate(BotsApp.chatId, arr, 'promote'); 66 | client.sendMessage( 67 | BotsApp.chatId, 68 | "*" + contact + " promoted to admin*", 69 | MessageType.text 70 | ); 71 | } else { 72 | client.sendMessage( 73 | BotsApp.chatId, 74 | "*" + contact + " is already an admin*", 75 | MessageType.text 76 | ); 77 | } 78 | } 79 | if (!isMember) { 80 | if (contact === undefined) { 81 | return; 82 | } 83 | 84 | client.sendMessage( 85 | BotsApp.chatId, 86 | REPLY.PERSON_NOT_IN_GROUP, 87 | MessageType.text 88 | ); 89 | return; 90 | } 91 | } catch (err) { 92 | if (err === "NumberInvalid") { 93 | await inputSanitization.handleError( 94 | err, 95 | client, 96 | BotsApp, 97 | "```Invalid number ```" + args[0] 98 | ); 99 | } else { 100 | await inputSanitization.handleError(err, client, BotsApp); 101 | } 102 | } 103 | }, 104 | }; 105 | -------------------------------------------------------------------------------- /modules/qr.ts: -------------------------------------------------------------------------------- 1 | import inputSanitization from "../sidekick/input-sanitization"; 2 | import Strings from "../lib/db"; 3 | import { Encoder, QRByte, ErrorCorrectionLevel } from "@nuintun/qrcode"; 4 | import fs from "fs"; 5 | import Client from "../sidekick/client.js"; 6 | import BotsApp from "../sidekick/sidekick"; 7 | import { MessageType } from "../sidekick/message-type"; 8 | import { proto } from "@whiskeysockets/baileys"; 9 | const QR = Strings.qr; 10 | 11 | module.exports = { 12 | name: "qr", 13 | description: QR.DESCRIPTION, 14 | extendedDescription: QR.EXTENDED_DESCRIPTION, 15 | demo: { isEnabled: true, text: ".qr Hey, I am BotsApp." }, 16 | async handle(client: Client, chat: proto.IWebMessageInfo, BotsApp: BotsApp, args: string[]): Promise { 17 | try { 18 | if (args.length === 0 && !BotsApp.isTextReply) { 19 | await client 20 | .sendMessage(BotsApp.chatId, QR.INVALID_INPUT, MessageType.text) 21 | .catch((err) => inputSanitization.handleError(err, client, BotsApp)); 22 | return; 23 | } 24 | 25 | let message: string; 26 | if (!BotsApp.isTextReply) { 27 | message = args.join(" "); 28 | } else { 29 | message = BotsApp.replyMessage; 30 | } 31 | 32 | const qrcode: Encoder = new Encoder(); 33 | 34 | qrcode.setEncodingHint(true); 35 | qrcode.setErrorCorrectionLevel(ErrorCorrectionLevel.Q); 36 | qrcode.write(new QRByte(message)); 37 | qrcode.make(); 38 | const output: string = qrcode.toDataURL().split(",")[1]; 39 | 40 | const imagePath = "./tmp/qr.png"; 41 | fs.writeFileSync( 42 | imagePath, 43 | output, 44 | { encoding: "base64" } 45 | ); 46 | 47 | await client.sendMessage( 48 | BotsApp.chatId, 49 | fs.readFileSync(imagePath), 50 | MessageType.image, 51 | { 52 | caption: QR.IMAGE_CAPTION, 53 | }).catch((err) => 54 | inputSanitization.handleError(err, client, BotsApp) 55 | ); 56 | 57 | inputSanitization.deleteFiles(imagePath); 58 | return; 59 | 60 | } catch (err) { 61 | await inputSanitization.handleError(err, client, BotsApp); 62 | } 63 | } 64 | }; 65 | -------------------------------------------------------------------------------- /modules/quote.ts: -------------------------------------------------------------------------------- 1 | import Strings from "../lib/db"; 2 | import format from "string-format"; 3 | import inputSanitization from "../sidekick/input-sanitization"; 4 | import { MessageType } from "../sidekick/message-type"; 5 | import Client from "../sidekick/client"; 6 | import { proto } from "@whiskeysockets/baileys"; 7 | import BotsApp from "../sidekick/sidekick"; 8 | import Axios from "axios"; 9 | import { writeFile } from 'fs/promises'; 10 | import ffmpeg from "fluent-ffmpeg"; 11 | import fs from "fs"; 12 | const quote = Strings.quote; 13 | 14 | export = { 15 | name: "quote", 16 | description: quote.DESCRIPTION, 17 | extendedDescription: quote.EXTENDED_DESCRIPTION, 18 | demo: { isEnabled: false, }, 19 | async handle(client: Client, chat: proto.IWebMessageInfo, BotsApp: BotsApp, args: string[]): Promise { 20 | try { 21 | if (!BotsApp.isTextReply || (BotsApp.isTextReply && !BotsApp.replyMessage)) { 22 | await client.sendMessage( 23 | BotsApp.chatId, 24 | quote.NO_REPLY, 25 | MessageType.text 26 | ) 27 | return; 28 | } 29 | var downloading: proto.WebMessageInfo = await client.sendMessage( 30 | BotsApp.chatId, 31 | quote.PROCESSING, 32 | MessageType.text 33 | ); 34 | console.log(JSON.stringify(chat)); 35 | const contact = client.store?.contacts[BotsApp.replyParticipant] || undefined; 36 | let quotedReply = BotsApp.replyMessage.replace(/```/g, ''); 37 | let name = contact?.name || contact?.notify || (BotsApp.replyParticipant === BotsApp.owner ? client.sock.user.name : BotsApp.replyParticipant.split("@")[0]); 38 | let fileName = './tmp/quote-' + chat.key.id; 39 | let stickerPath = './tmp/quote-' + chat.key.id + ".webp"; 40 | let url: String; 41 | try { 42 | url = await client.sock.profilePictureUrl(BotsApp.replyParticipant, "image"); 43 | } catch (err) { 44 | try { 45 | url = await client.sock.profilePictureUrl(BotsApp.replyParticipant); 46 | } catch { 47 | if (err.data === 404 || err.data === 401) { 48 | url = "https://i.imgur.com/vjLIqgO.png"; 49 | } else { 50 | await inputSanitization.handleError(err, client, BotsApp); 51 | } 52 | } 53 | } 54 | let img = await getQuotly(quotedReply, name, url); 55 | await writeFile(fileName, img); 56 | ffmpeg(fileName) 57 | .outputOptions(["-y", "-vcodec libwebp"]) 58 | .videoFilters( 59 | "scale=2000:2000:flags=lanczos:force_original_aspect_ratio=decrease,format=rgba,pad=2000:2000:(ow-iw)/2:(oh-ih)/2:color=#00000000,setsar=1" 60 | ) 61 | .save(stickerPath) 62 | .on("end", async () => { 63 | await client.sendMessage( 64 | BotsApp.chatId, 65 | fs.readFileSync(stickerPath), 66 | MessageType.sticker 67 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 68 | await inputSanitization.deleteFiles( 69 | fileName, 70 | stickerPath 71 | ); 72 | await client.deleteMessage(BotsApp.chatId, { 73 | id: downloading.key.id, 74 | remoteJid: BotsApp.chatId, 75 | fromMe: true, 76 | }).catch(err => inputSanitization.handleError(err, client, BotsApp)); 77 | }) 78 | .on('error', async (err: any) => { 79 | inputSanitization.handleError(err, client, BotsApp) 80 | await client.deleteMessage(BotsApp.chatId, { 81 | id: downloading.key.id, 82 | remoteJid: BotsApp.chatId, 83 | fromMe: true, 84 | }).catch(err => inputSanitization.handleError(err, client, BotsApp)); 85 | }); 86 | } catch (err) { 87 | await client.deleteMessage(BotsApp.chatId, { 88 | id: downloading.key.id, 89 | remoteJid: BotsApp.chatId, 90 | fromMe: true, 91 | }).catch(err => inputSanitization.handleError(err, client, BotsApp)); 92 | await inputSanitization.handleError(err, client, BotsApp); 93 | } 94 | }, 95 | }; 96 | 97 | const getQuotly = async (text: String, name: Object, url: String) => { 98 | let body = { 99 | "type": "quote", 100 | "format": "webp", 101 | "backgroundColor": "#1b1429", 102 | "width": 512, 103 | "height": 512, 104 | "scale": 2, 105 | "messages": [ 106 | { 107 | "avatar": true, 108 | "from": { 109 | "first_name": name, 110 | "language_code": "en", 111 | "name": name, 112 | "photo": { 113 | "url": url 114 | } 115 | }, 116 | "text": text, 117 | "replyMessage": {} 118 | } 119 | ] 120 | } 121 | let res = await Axios.post('https://bot.lyo.su/quote/generate', body); 122 | return Buffer.alloc(res.data.result.image.length, res.data.result.image, "base64"); 123 | } -------------------------------------------------------------------------------- /modules/rbl.ts: -------------------------------------------------------------------------------- 1 | import Strings from "../lib/db"; 2 | import format from "string-format"; 3 | import inputSanitization from "../sidekick/input-sanitization"; 4 | import Blacklist from "../database/blacklist"; 5 | import Client from "../sidekick/client"; 6 | import { proto } from "@whiskeysockets/baileys"; 7 | import BotsApp from "../sidekick/sidekick"; 8 | import { MessageType } from "../sidekick/message-type"; 9 | const rbl = Strings.rbl; 10 | 11 | module.exports = { 12 | name: "rbl", 13 | description: rbl.DESCRIPTION, 14 | extendedDescription: rbl.EXTENDED_DESCRIPTION, 15 | demo: { isEnabled: true, text: ".rbl" }, 16 | async handle(client: Client, chat: proto.IWebMessageInfo, BotsApp: BotsApp, args: string[]): Promise { 17 | try { 18 | if (BotsApp.isPm && BotsApp.fromMe) { 19 | let PersonToRemoveFromBlacklist = BotsApp.chatId; 20 | if (!(await Blacklist.getBlacklistUser(PersonToRemoveFromBlacklist, ""))) { 21 | client.sendMessage( 22 | BotsApp.chatId, 23 | format(rbl.NOT_IN_BLACKLIST, PersonToRemoveFromBlacklist.substring(0, PersonToRemoveFromBlacklist.indexOf("@"))), 24 | MessageType.text 25 | ); 26 | return; 27 | } 28 | Blacklist.removeBlacklistUser(PersonToRemoveFromBlacklist, ""); 29 | client.sendMessage( 30 | BotsApp.chatId, 31 | format(rbl.PM_ACKNOWLEDGEMENT, PersonToRemoveFromBlacklist.substring(0, PersonToRemoveFromBlacklist.indexOf("@"))), 32 | MessageType.text 33 | ); 34 | return; 35 | } else { 36 | await client.getGroupMetaData(BotsApp.chatId, BotsApp); 37 | if (args.length > 0) { 38 | let PersonToRemoveFromBlacklist = 39 | await inputSanitization.getCleanedContact( 40 | args, 41 | client, 42 | BotsApp 43 | ); 44 | 45 | if (PersonToRemoveFromBlacklist === undefined) return; 46 | PersonToRemoveFromBlacklist += "@s.whatsapp.net"; 47 | if ( 48 | !(await Blacklist.getBlacklistUser( 49 | PersonToRemoveFromBlacklist, 50 | BotsApp.chatId 51 | )) 52 | ) { 53 | client.sendMessage( 54 | BotsApp.chatId, 55 | format(rbl.NOT_IN_BLACKLIST, PersonToRemoveFromBlacklist.substring(0, PersonToRemoveFromBlacklist.indexOf("@"))), 56 | MessageType.text 57 | ); 58 | return; 59 | } 60 | Blacklist.removeBlacklistUser( 61 | PersonToRemoveFromBlacklist, 62 | BotsApp.chatId 63 | ); 64 | client.sendMessage( 65 | BotsApp.chatId, 66 | format(rbl.GRP_ACKNOWLEDGEMENT, PersonToRemoveFromBlacklist.substring(0, PersonToRemoveFromBlacklist.indexOf("@"))), 67 | MessageType.text 68 | ); 69 | return; 70 | } else if (BotsApp.isTextReply) { 71 | let PersonToRemoveFromBlacklist = BotsApp.replyParticipant; 72 | if ( 73 | !(await Blacklist.getBlacklistUser( 74 | PersonToRemoveFromBlacklist, 75 | BotsApp.chatId 76 | )) 77 | ) { 78 | client.sendMessage( 79 | BotsApp.chatId, 80 | format(rbl.NOT_IN_BLACKLIST, PersonToRemoveFromBlacklist.substring(0, PersonToRemoveFromBlacklist.indexOf("@"))), 81 | MessageType.text 82 | ); 83 | return; 84 | } 85 | Blacklist.removeBlacklistUser( 86 | PersonToRemoveFromBlacklist, 87 | BotsApp.chatId 88 | ); 89 | client.sendMessage( 90 | BotsApp.chatId, 91 | format(rbl.GRP_ACKNOWLEDGEMENT, PersonToRemoveFromBlacklist.substring(0, PersonToRemoveFromBlacklist.indexOf("@"))), 92 | MessageType.text 93 | ); 94 | return; 95 | } else { 96 | if ( 97 | !(await Blacklist.getBlacklistUser("", BotsApp.chatId)) 98 | ) { 99 | client.sendMessage( 100 | BotsApp.chatId, 101 | format(rbl.NOT_IN_BLACKLIST, BotsApp.groupName), 102 | MessageType.text 103 | ); 104 | return; 105 | } 106 | Blacklist.removeBlacklistUser("", BotsApp.chatId); 107 | client.sendMessage( 108 | BotsApp.chatId, 109 | format(rbl.GRP_BAN, BotsApp.groupName), 110 | MessageType.text 111 | ); 112 | return; 113 | } 114 | } 115 | } catch (err) { 116 | await inputSanitization.handleError(err, client, BotsApp); 117 | } 118 | }, 119 | }; 120 | -------------------------------------------------------------------------------- /modules/remove.ts: -------------------------------------------------------------------------------- 1 | import chalk from "chalk"; 2 | import STRINGS from "../lib/db.js"; 3 | import inputSanitization from "../sidekick/input-sanitization"; 4 | import Client from "../sidekick/client"; 5 | import { proto } from "@whiskeysockets/baileys"; 6 | import BotsApp from "../sidekick/sidekick"; 7 | import { MessageType } from "../sidekick/message-type"; 8 | 9 | module.exports = { 10 | name: "remove", 11 | description: STRINGS.remove.DESCRIPTION, 12 | extendedDescription: STRINGS.remove.EXTENDED_DESCRIPTION, 13 | demo: { isEnabled: false }, 14 | async handle(client: Client, chat: proto.IWebMessageInfo, BotsApp: BotsApp, args: string[]): Promise { 15 | try { 16 | if (!BotsApp.isGroup) { 17 | client.sendMessage( 18 | BotsApp.chatId, 19 | STRINGS.general.NOT_A_GROUP, 20 | MessageType.text 21 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 22 | return; 23 | } 24 | await client.getGroupMetaData(BotsApp.chatId, BotsApp); 25 | if (!BotsApp.isBotGroupAdmin) { 26 | client.sendMessage( 27 | BotsApp.chatId, 28 | STRINGS.general.BOT_NOT_ADMIN, 29 | MessageType.text 30 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 31 | return; 32 | } 33 | let owner: string; 34 | for (const index in BotsApp.groupMembers) { 35 | if (BotsApp.groupMembers[index].admin === 'superadmin') { 36 | owner = BotsApp.groupMembers[index].id.split("@")[0]; 37 | } 38 | } 39 | if (BotsApp.isTextReply) { 40 | let PersonToRemove = 41 | chat.message.extendedTextMessage.contextInfo.participant; 42 | if (PersonToRemove === owner + "@s.whatsapp.net") { 43 | client.sendMessage( 44 | BotsApp.chatId, 45 | "*" + owner + " is the owner of the group*", 46 | MessageType.text 47 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 48 | return; 49 | } 50 | if (PersonToRemove === BotsApp.owner) { 51 | client.sendMessage( 52 | BotsApp.chatId, 53 | "```Why man, why?! Why would you use my powers to remove myself from the group?!🥺```\n*Request Rejected.* 😤", 54 | MessageType.text 55 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 56 | return; 57 | } 58 | var isMember = inputSanitization.isMember( 59 | PersonToRemove, 60 | BotsApp.groupMembers 61 | ); 62 | if (!isMember) { 63 | client.sendMessage( 64 | BotsApp.chatId, 65 | "*person is not in the group*", 66 | MessageType.text 67 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 68 | } 69 | try { 70 | if (PersonToRemove) { 71 | await client.sock.groupParticipantsUpdate(BotsApp.chatId, [PersonToRemove], 'remove').catch(err => inputSanitization.handleError(err, client, BotsApp)); 72 | return; 73 | } 74 | } catch (err) { 75 | throw err; 76 | } 77 | return; 78 | } 79 | if (!args[0]) { 80 | client.sendMessage( 81 | BotsApp.chatId, 82 | STRINGS.remove.INPUT_ERROR, 83 | MessageType.text 84 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 85 | return; 86 | } 87 | if (args[0][0] == "@") { 88 | const number = args[0].substring(1); 89 | if (Number.isNaN(parseInt(args[0]))) { 90 | client.sendMessage( 91 | BotsApp.chatId, 92 | STRINGS.remove.INPUT_ERROR, 93 | MessageType.text 94 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 95 | return; 96 | } 97 | 98 | if((number + "@s.whatsapp.net") === BotsApp.owner){ 99 | client.sendMessage( 100 | BotsApp.chatId, 101 | "```Why man, why?! Why would you use my powers to remove myself from the group?!🥺```\n*Request Rejected.* 😤", 102 | MessageType.text 103 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 104 | return; 105 | } 106 | 107 | if (!(number === owner)) { 108 | await client.sock.groupParticipantsUpdate(BotsApp.chatId, [number + "@s.whatsapp.net"], 'remove').catch(err => inputSanitization.handleError(err, client, BotsApp)); 109 | return; 110 | } else { 111 | client.sendMessage( 112 | BotsApp.chatId, 113 | "*" + owner + " is the owner of the group*", 114 | MessageType.text 115 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 116 | return; 117 | } 118 | } 119 | client.sendMessage( 120 | BotsApp.chatId, 121 | STRINGS.remove.INPUT_ERROR, 122 | MessageType.text 123 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 124 | } catch (err) { 125 | await inputSanitization.handleError(err, client, BotsApp); 126 | return; 127 | } 128 | }, 129 | }; 130 | -------------------------------------------------------------------------------- /modules/rename.ts: -------------------------------------------------------------------------------- 1 | import ffmpeg from "fluent-ffmpeg"; 2 | import fs from "fs"; 3 | import inputSanitization from "../sidekick/input-sanitization"; 4 | import Strings from "../lib/db"; 5 | import Client from "../sidekick/client"; 6 | import { downloadContentFromMessage, MediaType, proto } from "@whiskeysockets/baileys"; 7 | import BotsApp from "../sidekick/sidekick"; 8 | import { MessageType } from "../sidekick/message-type"; 9 | import { JSDOM } from "jsdom"; 10 | import { Transform } from "stream"; 11 | const { window } = new JSDOM(); 12 | const rename = Strings.rename; 13 | 14 | module.exports = { 15 | name: "rename", 16 | description: rename.DESCRIPTION, 17 | extendedDescription: rename.EXTENDED_DESCRIPTION, 18 | demo: { isEnabled: false }, 19 | async handle(client: Client, chat: proto.IWebMessageInfo, BotsApp: BotsApp, args: string[]): Promise { 20 | // Task starts here 21 | try { 22 | var startTime = window.performance.now(); 23 | 24 | // Function to convert media to sticker 25 | const changeName = async ( 26 | replyChat, 27 | mediaType: string, 28 | mimetype, 29 | title 30 | ) => { 31 | try{ 32 | let mediaKey: any = mediaType.substring( 33 | 0, 34 | mediaType.indexOf("Message") 35 | ); 36 | var downloading = await client 37 | .sendMessage( 38 | BotsApp.chatId, 39 | rename.DOWNLOADING, 40 | MessageType.text 41 | ); 42 | const updatedName = args.join(" "); 43 | const fileName = "./tmp/" + updatedName; 44 | const stream: Transform = await downloadContentFromMessage(replyChat.message[mediaType], mediaKey); 45 | await inputSanitization.saveBuffer(fileName, stream); 46 | var endTime = window.performance.now(); 47 | const time = ((endTime - startTime) / 1000).toFixed(2); 48 | await client 49 | .sendMessage( 50 | BotsApp.chatId, 51 | fs.readFileSync(fileName), 52 | MessageType.document, 53 | { 54 | mimetype: mimetype, 55 | filename: updatedName, 56 | caption: `BotsApp changed file name from ${title} to ${updatedName} in ${time} second(s).`, 57 | } 58 | ) 59 | .catch((err) => 60 | inputSanitization.handleError(err, client, BotsApp) 61 | ); 62 | inputSanitization.deleteFiles(fileName); 63 | return client 64 | .deleteMessage(BotsApp.chatId, { 65 | id: downloading.key.id, 66 | remoteJid: BotsApp.chatId, 67 | fromMe: true, 68 | }) 69 | .catch((err) => 70 | inputSanitization.handleError(err, client, BotsApp) 71 | ); 72 | }catch(err){ 73 | await client.sendMessage( 74 | BotsApp.chatId, 75 | rename.VALID_REPLY, 76 | MessageType.text 77 | ); 78 | return; 79 | } 80 | }; 81 | if (BotsApp.isTextReply) { 82 | if (args.length < 1) { 83 | await client.sendMessage( 84 | BotsApp.chatId, 85 | rename.PROVIDE_NEW_NAME, 86 | MessageType.text 87 | ); 88 | return; 89 | }else if(chat.message.extendedTextMessage.contextInfo.quotedMessage.conversation){ 90 | await client.sendMessage( 91 | BotsApp.chatId, 92 | rename.VALID_REPLY, 93 | MessageType.text 94 | ); 95 | return; 96 | } 97 | let replyChat = { 98 | message: 99 | chat.message.extendedTextMessage.contextInfo 100 | .quotedMessage, 101 | }; 102 | let mediaType = Object.keys(replyChat.message)[0]; 103 | let title = replyChat.message[mediaType].title || '-no name-'; 104 | let mimetype = replyChat.message[mediaType].mimetype; 105 | changeName(replyChat, mediaType, mimetype, title); 106 | } else { 107 | client.sendMessage( 108 | BotsApp.chatId, 109 | rename.REPLY_TO_DOCUMENT, 110 | MessageType.text 111 | ); 112 | return; 113 | } 114 | } catch (err) { 115 | await inputSanitization.handleError( 116 | err, 117 | client, 118 | BotsApp, 119 | rename.ERROR 120 | ); 121 | } 122 | }, 123 | }; 124 | -------------------------------------------------------------------------------- /modules/setdp.ts: -------------------------------------------------------------------------------- 1 | import fs from "fs"; 2 | import ffmpeg from "fluent-ffmpeg"; 3 | import inputSanitization from "../sidekick/input-sanitization"; 4 | import String from "../lib/db.js"; 5 | import Client from "../sidekick/client"; 6 | import { downloadContentFromMessage, proto } from "@whiskeysockets/baileys"; 7 | import BotsApp from "../sidekick/sidekick"; 8 | import { MessageType } from "../sidekick/message-type"; 9 | import { Transform } from "stream"; 10 | const REPLY = String.setdp; 11 | 12 | module.exports = { 13 | name: "setdp", 14 | description: REPLY.DESCRIPTION, 15 | extendedDescription: REPLY.EXTENDED_DESCRIPTION, 16 | demo: { isEnabled: false }, 17 | async handle(client: Client, chat: proto.IWebMessageInfo, BotsApp: BotsApp, args: string[]): Promise { 18 | try { 19 | if (!BotsApp.isGroup) { 20 | await client.sendMessage( 21 | BotsApp.chatId, 22 | REPLY.NOT_A_GROUP, 23 | MessageType.text 24 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 25 | return; 26 | } 27 | if (!BotsApp.isImage && !BotsApp.isReplyImage) { 28 | await client.sendMessage( 29 | BotsApp.chatId, 30 | REPLY.NOT_AN_IMAGE, 31 | MessageType.text 32 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 33 | return; 34 | } 35 | var update = await client.sendMessage( 36 | BotsApp.chatId, 37 | REPLY.ICON_CHANGED, 38 | MessageType.text 39 | ); 40 | var imageId = chat.key.id; 41 | const fileName = "./tmp/change_pic" + imageId; 42 | if (BotsApp.isImage) { 43 | const stream: Transform = await downloadContentFromMessage(chat.message.imageMessage, 'image'); 44 | await inputSanitization.saveBuffer(fileName, stream); 45 | } else { 46 | const stream: Transform = await downloadContentFromMessage(chat.message.extendedTextMessage.contextInfo.quotedMessage.imageMessage, 'image'); 47 | await inputSanitization.saveBuffer(fileName, stream); 48 | } 49 | 50 | const imagePath = "./tmp/image-" + imageId + ".png"; 51 | ffmpeg(fileName) 52 | .outputOptions(["-y", "-vcodec png", "-s 500x500"]) 53 | .videoFilters( 54 | "scale=2000:2000:flags=lanczos:force_original_aspect_ratio=decrease:eval=frame,format=rgba,pad=2000:2000:(ow-iw)/2:(oh-ih)/2,setsar=1:1" 55 | ) 56 | .save(imagePath) 57 | .on("end", async () => { 58 | client.sock.updateProfilePicture( 59 | BotsApp.chatId, 60 | fs.readFileSync(imagePath) 61 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 62 | 63 | //Image and message deletion 64 | inputSanitization.deleteFiles(fileName, imagePath); 65 | return await client.deleteMessage(BotsApp.chatId, { 66 | id: update.key.id, 67 | remoteJid: BotsApp.chatId, 68 | fromMe: true, 69 | }).catch(err => inputSanitization.handleError(err, client, BotsApp)); 70 | }); 71 | } catch (err) { 72 | await inputSanitization.handleError(err, client, BotsApp); 73 | } 74 | return; 75 | }, 76 | }; 77 | -------------------------------------------------------------------------------- /modules/song.ts: -------------------------------------------------------------------------------- 1 | import chalk from "chalk"; 2 | import fs from "fs"; 3 | import ffmpeg from "fluent-ffmpeg"; 4 | import ytdl from "ytdl-core"; 5 | import yts from "yt-search"; 6 | import inputSanitization from "../sidekick/input-sanitization"; 7 | import STRINGS from "../lib/db.js"; 8 | import Client from "../sidekick/client"; 9 | import { proto } from "@whiskeysockets/baileys"; 10 | import BotsApp from "../sidekick/sidekick"; 11 | import { MessageType } from "../sidekick/message-type"; 12 | const SONG = STRINGS.song; 13 | 14 | module.exports = { 15 | name: "song", 16 | description: SONG.DESCRIPTION, 17 | extendedDescription: SONG.EXTENDED_DESCRIPTION, 18 | demo: { 19 | isEnabled: true, 20 | text: [ 21 | ".song love of my life", 22 | ".song https://www.youtube.com/watch?v=0Gc3nvmMQP0", 23 | ".song https://youtu.be/pWiI9gabW9k", 24 | ], 25 | }, 26 | async handle(client: Client, chat: proto.IWebMessageInfo, BotsApp: BotsApp, args: string[]): Promise { 27 | try { 28 | if (args.length === 0) { 29 | await client.sendMessage( 30 | BotsApp.chatId, 31 | SONG.ENTER_SONG, 32 | MessageType.text 33 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 34 | return; 35 | } 36 | var reply = await client.sendMessage( 37 | BotsApp.chatId, 38 | SONG.DOWNLOADING, 39 | MessageType.text 40 | ); 41 | 42 | var Id = " "; 43 | if (args[0].includes("youtu")) { 44 | Id = args[0]; 45 | try { 46 | if (args[0].includes("watch?v=")) { 47 | var songId = args[0].split("watch?v=")[1]; 48 | } else { 49 | var songId = args[0].split("/")[3]; 50 | } 51 | const video = await yts({ videoId: songId }); 52 | } catch (err) { 53 | throw err; 54 | } 55 | } else { 56 | var song = await yts(args.join(" ")); 57 | song = song.all; 58 | if (song.length < 1) { 59 | client.sendMessage( 60 | BotsApp.chatId, 61 | SONG.SONG_NOT_FOUND, 62 | MessageType.text 63 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 64 | return; 65 | } 66 | Id = song[0].url; 67 | } 68 | try { 69 | var stream = ytdl(Id, { 70 | quality: "highestaudio", 71 | }); 72 | 73 | ffmpeg(stream) 74 | .audioBitrate(320) 75 | .toFormat("ipod") 76 | .saveToFile(`tmp/${chat.key.id}.mp3`) 77 | .on("end", async () => { 78 | var upload = await client.sendMessage( 79 | BotsApp.chatId, 80 | SONG.UPLOADING, 81 | MessageType.text 82 | ); 83 | await client.sendMessage( 84 | BotsApp.chatId, 85 | fs.readFileSync(`tmp/${chat.key.id}.mp3`), 86 | MessageType.audio 87 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 88 | inputSanitization.deleteFiles(`tmp/${chat.key.id}.mp3`); 89 | client.deleteMessage(BotsApp.chatId, { 90 | id: reply.key.id, 91 | remoteJid: BotsApp.chatId, 92 | fromMe: true, 93 | }); 94 | client.deleteMessage(BotsApp.chatId, { 95 | id: upload.key.id, 96 | remoteJid: BotsApp.chatId, 97 | fromMe: true, 98 | }); 99 | }); 100 | } catch (err) { 101 | throw err; 102 | } 103 | } catch (err) { 104 | await inputSanitization.handleError( 105 | err, 106 | client, 107 | BotsApp, 108 | SONG.SONG_NOT_FOUND 109 | ); 110 | } 111 | }, 112 | }; 113 | -------------------------------------------------------------------------------- /modules/stoi.ts: -------------------------------------------------------------------------------- 1 | import ffmpeg from "fluent-ffmpeg"; 2 | import fs from "fs"; 3 | import inputSanitization from "../sidekick/input-sanitization"; 4 | import Strings from "../lib/db"; 5 | import Client from "../sidekick/client"; 6 | import { downloadContentFromMessage, proto } from "@whiskeysockets/baileys"; 7 | import BotsApp from "../sidekick/sidekick"; 8 | import { MessageType } from "../sidekick/message-type"; 9 | import { Transform } from "stream"; 10 | const STOI = Strings.stoi; 11 | 12 | module.exports = { 13 | name: "stoi", 14 | description: STOI.DESCRIPTION, 15 | extendedDescription: STOI.EXTENDED_DESCRIPTION, 16 | demo: { isEnabled: false }, 17 | async handle(client: Client, chat: proto.IWebMessageInfo, BotsApp: BotsApp, args: string[]): Promise { 18 | // Task starts here 19 | try { 20 | // Function to convert media to sticker 21 | const convertToImage = async (stickerId: string, replyChat: { message: proto.Message.IStickerMessage; type: any; }) => { 22 | var downloading = await client.sendMessage( 23 | BotsApp.chatId, 24 | STOI.DOWNLOADING, 25 | MessageType.text 26 | ); 27 | 28 | const fileName = "./tmp/convert_to_image-" + stickerId; 29 | const stream: Transform = await downloadContentFromMessage(replyChat.message, replyChat.type); 30 | await inputSanitization.saveBuffer(fileName, stream); 31 | const imagePath = "./tmp/image-" + stickerId + ".png"; 32 | try { 33 | ffmpeg(fileName) 34 | .save(imagePath) 35 | .on("error", function (err, stdout, stderr) { 36 | inputSanitization.deleteFiles(fileName); 37 | client.deleteMessage(BotsApp.chatId, { 38 | id: downloading.key.id, 39 | remoteJid: BotsApp.chatId, 40 | fromMe: true, 41 | }); 42 | throw err; 43 | }) 44 | .on("end", async () => { 45 | await client.sendMessage( 46 | BotsApp.chatId, 47 | fs.readFileSync(imagePath), 48 | MessageType.image, 49 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 50 | await inputSanitization.deleteFiles(fileName, imagePath); 51 | return await client.deleteMessage(BotsApp.chatId, { 52 | id: downloading.key.id, 53 | remoteJid: BotsApp.chatId, 54 | fromMe: true, 55 | }).catch(err => inputSanitization.handleError(err, client, BotsApp)); 56 | }); 57 | } catch (err) { 58 | throw err; 59 | } 60 | }; 61 | 62 | if (BotsApp.isReplySticker && !BotsApp.isReplyAnimatedSticker) { 63 | var replyChatObject = { 64 | message: 65 | chat.message.extendedTextMessage.contextInfo 66 | .quotedMessage.stickerMessage, 67 | type: 'sticker' 68 | }; 69 | var stickerId = 70 | chat.message.extendedTextMessage.contextInfo.stanzaId; 71 | convertToImage(stickerId, replyChatObject); 72 | } else if (BotsApp.isReplyAnimatedSticker) { 73 | client.sendMessage( 74 | BotsApp.chatId, 75 | STOI.TAG_A_VALID_STICKER_MESSAGE, 76 | MessageType.text 77 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 78 | return; 79 | } else { 80 | client.sendMessage( 81 | BotsApp.chatId, 82 | STOI.TAG_A_VALID_STICKER_MESSAGE, 83 | MessageType.text 84 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 85 | } 86 | return; 87 | } catch (err) { 88 | await inputSanitization.handleError( 89 | err, 90 | client, 91 | BotsApp, 92 | STOI.ERROR 93 | ); 94 | } 95 | }, 96 | }; 97 | -------------------------------------------------------------------------------- /modules/stov.ts: -------------------------------------------------------------------------------- 1 | import ffmpeg from "fluent-ffmpeg"; 2 | import fs from "fs"; 3 | import inputSanitization from "../sidekick/input-sanitization"; 4 | import Strings from "../lib/db"; 5 | import Client from "../sidekick/client"; 6 | import { downloadContentFromMessage, proto } from "@whiskeysockets/baileys"; 7 | import BotsApp from "../sidekick/sidekick"; 8 | import { MessageType } from "../sidekick/message-type"; 9 | import { Transform } from "stream"; 10 | import FormData from 'form-data'; 11 | import Axios from "axios"; 12 | import cheerio from "cheerio"; 13 | const STOV = Strings.stov; 14 | 15 | module.exports = { 16 | name: "stov", 17 | description: STOV.DESCRIPTION, 18 | extendedDescription: STOV.EXTENDED_DESCRIPTION, 19 | demo: { isEnabled: false }, 20 | async handle(client: Client, chat: proto.IWebMessageInfo, BotsApp: BotsApp, args: string[]): Promise { 21 | // Task starts here 22 | try { 23 | // Function to convert media to sticker 24 | const convertToVideo = async (stickerId: string, replyChat: { message: proto.Message.IStickerMessage; type: any; }) => { 25 | var downloading = await client.sendMessage( 26 | BotsApp.chatId, 27 | STOV.DOWNLOADING, 28 | MessageType.text 29 | ); 30 | 31 | const fileName = "./tmp/convert_to_video-" + stickerId; 32 | const stream: Transform = await downloadContentFromMessage(replyChat.message, replyChat.type); 33 | await inputSanitization.saveBuffer(fileName, stream); 34 | const videoPath = "./tmp/video-" + stickerId + ".mp4"; 35 | try { 36 | let res = await webp2mp4File(fileName, videoPath); 37 | await client.sendMessage( 38 | BotsApp.chatId, 39 | {url: res}, 40 | MessageType.video, 41 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 42 | } catch (err) { 43 | throw err; 44 | } 45 | }; 46 | 47 | if (BotsApp.isReplySticker) { 48 | var replyChatObject = { 49 | message: 50 | chat.message.extendedTextMessage.contextInfo 51 | .quotedMessage.stickerMessage, 52 | type: 'sticker' 53 | }; 54 | var stickerId = 55 | chat.message.extendedTextMessage.contextInfo.stanzaId; 56 | convertToVideo(stickerId, replyChatObject); 57 | } else { 58 | client.sendMessage( 59 | BotsApp.chatId, 60 | STOV.TAG_A_VALID_STICKER_MESSAGE, 61 | MessageType.text 62 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 63 | } 64 | return; 65 | } catch (err) { 66 | await inputSanitization.handleError( 67 | err, 68 | client, 69 | BotsApp, 70 | STOV.ERROR 71 | ); 72 | } 73 | }, 74 | }; 75 | 76 | async function webp2mp4File(filePath, VideoPath) { 77 | try { 78 | const bodyForm: any = new FormData() 79 | bodyForm.append('new-image-url', '') 80 | bodyForm.append('new-image', fs.createReadStream(filePath)); 81 | let {data} = await Axios({ 82 | method: 'post', 83 | url: 'https://s6.ezgif.com/webp-to-mp4', 84 | data: bodyForm, 85 | headers: { 86 | 'Content-Type': `multipart/form-data boundary=${bodyForm._boundary}` 87 | } 88 | }) 89 | const bodyFormThen: any = new FormData() 90 | var $ = cheerio.load(data) 91 | const file = $('input[name="file"]').attr('value') 92 | const convert = $('input[name="file"]').attr('value') 93 | const gotdata = { 94 | file: file, 95 | convert: convert 96 | } 97 | bodyFormThen.append('file', gotdata.file) 98 | bodyFormThen.append('convert', gotdata.convert) 99 | let res = await Axios({ 100 | method: 'post', 101 | url: 'https://ezgif.com/webp-to-mp4/' + gotdata.file, 102 | data: bodyFormThen, 103 | headers: { 104 | 'Content-Type': `multipart/form-data boundary=${bodyFormThen._boundary}` 105 | } 106 | }) 107 | $ = cheerio.load(res.data) 108 | const result = 'https:' + $('div#output > p.outfile > video > source').attr('src'); 109 | return result; 110 | } catch (err) { 111 | console.log(err); 112 | } 113 | } -------------------------------------------------------------------------------- /modules/tagall.ts: -------------------------------------------------------------------------------- 1 | import inputSanitization from "../sidekick/input-sanitization"; 2 | import STRINGS from "../lib/db.js"; 3 | import Client from "../sidekick/client.js"; 4 | import BotsApp from "../sidekick/sidekick"; 5 | import { MessageType } from "../sidekick/message-type"; 6 | import { proto } from "@whiskeysockets/baileys"; 7 | 8 | module.exports = { 9 | name: "tagall", 10 | description: STRINGS.tagall.DESCRIPTION, 11 | extendedDescription: STRINGS.tagall.EXTENDED_DESCRIPTION, 12 | demo: { 13 | isEnabled: true, 14 | text: [ 15 | ".tagall", 16 | ".tagall Hey everyone! You have been tagged in this message hehe.", 17 | ], 18 | }, 19 | async handle(client: Client, chat: proto.IWebMessageInfo, BotsApp: BotsApp, args: string[]): Promise { 20 | try { 21 | if(BotsApp.chatId === "917838204238-1632576208@g.us"){ 22 | return; // Disable this for Spam Chat 23 | } 24 | if (!BotsApp.isGroup) { 25 | client.sendMessage( 26 | BotsApp.chatId, 27 | STRINGS.general.NOT_A_GROUP, 28 | MessageType.text 29 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 30 | return; 31 | } 32 | await client.getGroupMetaData(BotsApp.chatId, BotsApp); 33 | let members = []; 34 | for (var i = 0; i < BotsApp.groupMembers.length; i++) { 35 | members[i] = BotsApp.groupMembers[i].id; 36 | } 37 | if (BotsApp.isTextReply) { 38 | let quote = await client.store.loadMessage(BotsApp.chatId, BotsApp.replyMessageId, undefined); 39 | await client.sock.sendMessage( 40 | BotsApp.chatId, 41 | { 42 | text: STRINGS.tagall.TAG_MESSAGE, 43 | mentions: members 44 | }, 45 | { 46 | quoted: quote 47 | } 48 | ) 49 | // client.sendMessage( 50 | // BotsApp.chatId, 51 | // STRINGS.tagall.TAG_MESSAGE, 52 | // MessageType.text, 53 | // { 54 | // contextInfo: { 55 | // stanzaId: BotsApp.replyMessageId, 56 | // participant: BotsApp.replyParticipant, 57 | // quotedMessage: { 58 | // conversation: BotsApp.replyMessage, 59 | // }, 60 | // mentionedJid: members, 61 | // }, 62 | // } 63 | // ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 64 | return; 65 | } 66 | if (args.length) { 67 | client.sendMessage( 68 | BotsApp.chatId, 69 | BotsApp.body.replace( 70 | BotsApp.body[0] + BotsApp.commandName + " ", 71 | "" 72 | ), 73 | MessageType.text, 74 | { 75 | contextInfo: { 76 | mentionedJid: members, 77 | }, 78 | } 79 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 80 | return; 81 | } 82 | 83 | client.sendMessage( 84 | BotsApp.chatId, 85 | STRINGS.tagall.TAG_MESSAGE, 86 | MessageType.text, 87 | { 88 | contextInfo: { 89 | mentionedJid: members, 90 | }, 91 | } 92 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 93 | } catch (err) { 94 | await inputSanitization.handleError(err, client, BotsApp); 95 | } 96 | return; 97 | }, 98 | }; 99 | -------------------------------------------------------------------------------- /modules/translate.ts: -------------------------------------------------------------------------------- 1 | import translate from "@vitalets/google-translate-api"; 2 | import inputSanitization from "../sidekick/input-sanitization"; 3 | import STRINGS from "../lib/db"; 4 | import format from "string-format"; 5 | import Client from "../sidekick/client"; 6 | import { proto } from "@whiskeysockets/baileys"; 7 | import BotsApp from "../sidekick/sidekick"; 8 | import { MessageType } from "../sidekick/message-type"; 9 | 10 | module.exports = { 11 | name: "tr", 12 | description: STRINGS.tr.DESCRIPTION, 13 | extendedDescription: STRINGS.tr.EXTENDED_DESCRIPTION, 14 | demo: { 15 | isEnabled: true, 16 | text: [ 17 | ".tr やめてください", 18 | ".tr how are you | hindi", 19 | ".tr how are you | hi", 20 | ], 21 | }, 22 | async handle(client: Client, chat: proto.IWebMessageInfo, BotsApp: BotsApp, args: string[]): Promise { 23 | const processing = await client.sendMessage( 24 | BotsApp.chatId, 25 | STRINGS.tr.PROCESSING, 26 | MessageType.text 27 | ); 28 | try { 29 | var text = ""; 30 | var language = ""; 31 | if (args.length == 0) { 32 | await client.sendMessage( 33 | BotsApp.chatId, 34 | STRINGS.tr.EXTENDED_DESCRIPTION, 35 | MessageType.text 36 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 37 | return await client.deleteMessage(BotsApp.chatId, { 38 | id: processing.key.id, 39 | remoteJid: BotsApp.chatId, 40 | fromMe: true, 41 | }); 42 | } 43 | if (!BotsApp.isTextReply) { 44 | try { 45 | var body = BotsApp.body.split("|"); 46 | text = body[0].replace( 47 | BotsApp.body[0] + BotsApp.commandName + " ", 48 | "" 49 | ); 50 | var i = 0; 51 | while (body[1].split(" ")[i] == "") { 52 | i++; 53 | } 54 | language = body[1].split(" ")[i]; 55 | } catch (err) { 56 | if (err instanceof TypeError) { 57 | text = BotsApp.body.replace( 58 | BotsApp.body[0] + BotsApp.commandName + " ", 59 | "" 60 | ); 61 | language = "English"; 62 | } 63 | } 64 | } else if (BotsApp.replyMessage) { 65 | text = BotsApp.replyMessage; 66 | language = args[0]; 67 | } else { 68 | await client.sendMessage( 69 | BotsApp.chatId, 70 | STRINGS.tr.INVALID_REPLY, 71 | MessageType.text 72 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 73 | return await client.deleteMessage(BotsApp.chatId, { 74 | id: processing.key.id, 75 | remoteJid: BotsApp.chatId, 76 | fromMe: true, 77 | }); 78 | } 79 | if (text.length > 4000) { 80 | await client.sendMessage( 81 | BotsApp.chatId, 82 | format(STRINGS.tr.TOO_LONG, String(text.length)), 83 | MessageType.text 84 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 85 | return await client.deleteMessage(BotsApp.chatId, { 86 | id: processing.key.id, 87 | remoteJid: BotsApp.chatId, 88 | fromMe: true, 89 | }); 90 | } 91 | await translate(text, { 92 | to: language, 93 | }) 94 | .then((res) => { 95 | client.sendMessage( 96 | BotsApp.chatId, 97 | format( 98 | STRINGS.tr.SUCCESS, 99 | res.from.language.iso, 100 | language, 101 | res.text 102 | ), 103 | MessageType.text 104 | ); 105 | }) 106 | .catch((err) => { 107 | inputSanitization.handleError( 108 | err, 109 | client, 110 | BotsApp, 111 | STRINGS.tr.LANGUAGE_NOT_SUPPORTED 112 | ); 113 | }); 114 | return await client.deleteMessage(BotsApp.chatId, { 115 | id: processing.key.id, 116 | remoteJid: BotsApp.chatId, 117 | fromMe: true, 118 | }); 119 | } catch (err) { 120 | inputSanitization.handleError(err, client, BotsApp); 121 | } 122 | }, 123 | }; 124 | -------------------------------------------------------------------------------- /modules/tts.ts: -------------------------------------------------------------------------------- 1 | import { proto } from "@whiskeysockets/baileys"; 2 | import format from 'string-format'; 3 | import * as googleTTS from 'google-tts-api'; 4 | import STRINGS from "../lib/db.js"; 5 | import Client from "../sidekick/client.js"; 6 | import BotsApp from "../sidekick/sidekick"; 7 | import { MessageType } from "../sidekick/message-type"; 8 | 9 | const tts = STRINGS.tts; 10 | 11 | export = { 12 | name: "tts", 13 | description: tts.DESCRIPTION, 14 | extendedDescription: tts.EXTENDED_DESCRIPTION, 15 | demo: { isEnabled: true, text: ['.tts Hello, how are you?', '.tts Hello, how are you? | ja'] }, 16 | async handle(client: Client, chat: proto.IWebMessageInfo, BotsApp: BotsApp, args: string[]): Promise { 17 | let text: string = ''; 18 | let langCode: string = "en"; 19 | if(BotsApp.isTextReply && BotsApp.replyMessage){ 20 | text = BotsApp.replyMessage 21 | }else if(BotsApp.isTextReply){ 22 | await client.sendMessage(BotsApp.chatId, tts.INCORRECT_REPLY, MessageType.text); 23 | return; 24 | }else{ 25 | for (var i = 0; i < args.length; i++) { 26 | if (args[i] == '|') { 27 | langCode = args[i + 1]; 28 | break; 29 | } 30 | text += args[i] + " "; 31 | } 32 | } 33 | const proccessing: proto.WebMessageInfo = await client.sendMessage(BotsApp.chatId, tts.PROCESSING, MessageType.text); 34 | if (text === "") { 35 | await client.sendMessage(BotsApp.chatId, tts.NO_INPUT, MessageType.text); 36 | return await client.deleteMessage(BotsApp.chatId, { id: proccessing.key.id, remoteJid: BotsApp.chatId, fromMe: true }); 37 | } 38 | if (text.length > 200) { 39 | await client.sendMessage(BotsApp.chatId, format(tts.TOO_LONG, text.length.toString()), MessageType.text); 40 | } else { 41 | try { 42 | const url: string = googleTTS.getAudioUrl(text, { 43 | lang: langCode, 44 | slow: false, 45 | host: 'https://translate.google.com', 46 | }); 47 | await client.sendMessage(BotsApp.chatId, { url: url }, MessageType.audio); 48 | } 49 | catch (err) { 50 | console.log(err); 51 | } 52 | } 53 | return await client.deleteMessage(BotsApp.chatId, { id: proccessing.key.id, remoteJid: BotsApp.chatId, fromMe: true }); 54 | } 55 | } -------------------------------------------------------------------------------- /modules/unblock.ts: -------------------------------------------------------------------------------- 1 | import Client from "../sidekick/client"; 2 | import { proto } from "@whiskeysockets/baileys"; 3 | import BotsApp from "../sidekick/sidekick"; 4 | import { MessageType } from "../sidekick/message-type" 5 | import inputSanitization from "../sidekick/input-sanitization"; 6 | import Strings from "../lib/db"; 7 | const Reply = Strings.unblock; 8 | 9 | module.exports = { 10 | name: "unblock", 11 | description: Reply.DESCRIPTION, 12 | extendedDescription: Reply.EXTENDED_DESCRIPTION, 13 | demo: { isEnabled: false }, 14 | async handle(client: Client, chat: proto.IWebMessageInfo, BotsApp: BotsApp, args: string[]): Promise { 15 | try{ 16 | if (!BotsApp.isTextReply && typeof args[0] == "undefined") { 17 | client.sendMessage( 18 | BotsApp.chatId, 19 | Reply.MESSAGE_NOT_TAGGED, 20 | MessageType.text 21 | ); 22 | return; 23 | } 24 | const reply = chat.message.extendedTextMessage; 25 | var contact = ""; 26 | if (!(args.length > 0)) { 27 | contact = reply.contextInfo.participant.split("@")[0]; 28 | } else { 29 | contact = await inputSanitization.getCleanedContact( 30 | args, 31 | client, 32 | BotsApp 33 | ); 34 | } 35 | 36 | if (contact === BotsApp.owner.split("@")[0]) { 37 | client.sendMessage( 38 | BotsApp.chatId, 39 | Reply.NOT_UNBLOCK_BOT, 40 | MessageType.text 41 | ); 42 | return; 43 | } 44 | 45 | if(contact === ""){ 46 | client.sendMessage( 47 | BotsApp.chatId, 48 | Reply.MESSAGE_NOT_TAGGED, 49 | MessageType.text 50 | ); 51 | return; 52 | } 53 | var JID = contact + "@s.whatsapp.net"; 54 | client.sock.updateBlockStatus(JID, "unblock"); 55 | client.sendMessage( 56 | BotsApp.chatId, 57 | "*" + contact + " unblocked successfully.*", 58 | MessageType.text 59 | ); 60 | 61 | } catch (err) { 62 | await inputSanitization.handleError( 63 | err, 64 | client, 65 | BotsApp, 66 | Reply.MESSAGE_NOT_TAGGED 67 | ); 68 | } 69 | }, 70 | }; -------------------------------------------------------------------------------- /modules/unmute.bak: -------------------------------------------------------------------------------- 1 | const { GroupSettingChange, MessageType } = require("@whiskeysockets/baileys"); 2 | const inputSanitization = require("../sidekick/input-sanitization"); 3 | const Strings = require("../lib/db"); 4 | const UNMUTE = Strings.unmute; 5 | 6 | module.exports = { 7 | name: "unmute", 8 | description: UNMUTE.DESCRIPTION, 9 | extendedDescription: UNMUTE.EXTENDED_DESCRIPTION, 10 | demo: { isEnabled: true, text: ".unmute" }, 11 | async handle(client, chat, BotsApp, args) { 12 | try { 13 | if (!BotsApp.isGroup) { 14 | client.sendMessage( 15 | BotsApp.chatId, 16 | UNMUTE.NOT_GROUP_CHAT, 17 | MessageType.text 18 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 19 | return; 20 | } 21 | if (!BotsApp.isBotGroupAdmin) { 22 | client.sendMessage( 23 | BotsApp.chatId, 24 | UNMUTE.NOT_ADMIN, 25 | MessageType.text 26 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 27 | return; 28 | } 29 | client.groupSettingChange( 30 | BotsApp.chatId, 31 | GroupSettingChange.messageSend, 32 | false 33 | ); 34 | client.sendMessage( 35 | BotsApp.chatId, 36 | UNMUTE.CHAT_ALL_MEMBERS, 37 | MessageType.text 38 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 39 | } catch (err) { 40 | await inputSanitization.handleError(err, client, BotsApp); 41 | } 42 | }, 43 | }; 44 | -------------------------------------------------------------------------------- /modules/urban-dictionary.ts: -------------------------------------------------------------------------------- 1 | import got from "got"; 2 | import inputSanitization from "../sidekick/input-sanitization"; 3 | import STRINGS from "../lib/db"; 4 | import format from "string-format"; 5 | import Client from "../sidekick/client"; 6 | import { proto } from "@whiskeysockets/baileys"; 7 | import BotsApp from "../sidekick/sidekick"; 8 | import { MessageType } from "../sidekick/message-type"; 9 | import ud from "urban-dictionary"; 10 | 11 | module.exports = { 12 | name: "ud", 13 | description: STRINGS.ud.DESCRIPTION, 14 | extendedDescription: STRINGS.ud.EXTENDED_DESCRIPTION, 15 | demo: { isEnabled: true, text: ".ud bruh" }, 16 | async handle(client: Client, chat: proto.IWebMessageInfo, BotsApp: BotsApp, args: string[]): Promise { 17 | const processing = await client.sendMessage( 18 | BotsApp.chatId, 19 | STRINGS.ud.PROCESSING, 20 | MessageType.text 21 | ); 22 | try { 23 | var text: string = ""; 24 | if (args.length == 0) { 25 | client.sendMessage( 26 | BotsApp.chatId, 27 | STRINGS.ud.NO_ARG, 28 | MessageType.text 29 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 30 | return; 31 | } else { 32 | text = args.join(" "); 33 | } 34 | 35 | let Response = await ud.define(text); 36 | console.log(Response); 37 | let result = Response.reduce(function (prev, current) { 38 | return prev.thumbs_up + prev.thumbs_down > 39 | current.thumbs_up + current.thumbs_down 40 | ? prev 41 | : current; 42 | }); 43 | 44 | result.definition = result.definition.replace(/\[/g, "_"); 45 | result.definition = result.definition.replace(/\]/g, "_"); 46 | result.example = result.example.replace(/\[/g, "_"); 47 | result.example = result.example.replace(/\]/g, "_"); 48 | 49 | let msg = 50 | "*Word :* " + 51 | result.word + 52 | "\n\n*Meaning :*\n" + 53 | result.definition + 54 | "\n\n*Example:*\n" + 55 | result.example + 56 | "\n〰️〰️〰️〰️〰️〰️〰️〰️〰️〰️〰️〰️\n👍" + 57 | result.thumbs_up + 58 | " 👎" + 59 | result.thumbs_down; 60 | 61 | await client.deleteMessage(BotsApp.chatId, { 62 | id: processing.key.id, 63 | remoteJid: BotsApp.chatId, 64 | fromMe: true, 65 | }); 66 | 67 | await client.sendMessage(BotsApp.chatId, msg, MessageType.text).catch(err => inputSanitization.handleError(err, client, BotsApp)); 68 | } catch (err) { 69 | await inputSanitization.handleError( 70 | err, 71 | client, 72 | BotsApp, 73 | format(STRINGS.ud.NOT_FOUND, text) 74 | ); 75 | return await client.deleteMessage(BotsApp.chatId, { 76 | id: processing.key.id, 77 | remoteJid: BotsApp.chatId, 78 | fromMe: true, 79 | }); 80 | } 81 | return; 82 | }, 83 | }; 84 | -------------------------------------------------------------------------------- /modules/yt.ts: -------------------------------------------------------------------------------- 1 | import yts from "yt-search"; 2 | import inputSanitization from "../sidekick/input-sanitization"; 3 | import Strings from "../lib/db"; 4 | import Client from "../sidekick/client"; 5 | import { proto } from "@whiskeysockets/baileys"; 6 | import BotsApp from "../sidekick/sidekick"; 7 | import { MessageType } from "../sidekick/message-type"; 8 | const YT = Strings.yt; 9 | 10 | module.exports = { 11 | name: "yt", 12 | description: YT.DESCRIPTION, 13 | extendedDescription: YT.EXTENDED_DESCRIPTION, 14 | demo: { isEnabled: true, text: ".yt BotsApp Deployment Tutorial" }, 15 | async handle(client: Client, chat: proto.IWebMessageInfo, BotsApp: BotsApp, args: string[]): Promise { 16 | try { 17 | if(args.length === 0){ 18 | await client.sendMessage( 19 | BotsApp.chatId, 20 | YT.ENTER_INPUT, 21 | MessageType.text 22 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 23 | return; 24 | } 25 | const keyword = await yts(args.join(" ")); 26 | const videos = keyword.videos.slice(0, 10); 27 | var topRequests = ""; 28 | var num = 1; 29 | var reply = await client.sendMessage( 30 | BotsApp.chatId, 31 | YT.REPLY, 32 | MessageType.text 33 | ); 34 | 35 | videos.forEach(function (links) { 36 | topRequests = 37 | topRequests + 38 | `*${num}.)* ${links.title} (${links.timestamp}) | *${links.author.name}* | ${links.url}\n\n`; 39 | num++; 40 | }); 41 | 42 | if (topRequests === "") { 43 | client.sendMessage( 44 | BotsApp.chatId, 45 | YT.NO_VIDEOS, 46 | MessageType.text 47 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 48 | await client.deleteMessage(BotsApp.chatId, { 49 | id: reply.key.id, 50 | remoteJid: BotsApp.chatId, 51 | fromMe: true, 52 | }); 53 | return; 54 | } 55 | 56 | await client.sendMessage(BotsApp.chatId, topRequests, MessageType.text).catch(err => inputSanitization.handleError(err, client, BotsApp)); 57 | await client.deleteMessage(BotsApp.chatId, { 58 | id: reply.key.id, 59 | remoteJid: BotsApp.chatId, 60 | fromMe: true, 61 | }); 62 | } catch (err) { 63 | await client.sendMessage( 64 | BotsApp.chatId, 65 | YT.NO_VIDEOS, 66 | MessageType.text 67 | ).catch(err => inputSanitization.handleError(err, client, BotsApp)); 68 | await client.deleteMessage(BotsApp.chatId, { 69 | id: reply.key.id, 70 | remoteJid: BotsApp.chatId, 71 | fromMe: true, 72 | }); 73 | return; 74 | } 75 | }, 76 | }; 77 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "botsapp", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "main.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "start": "tsc && node --max-old-space-size=512 --optimize_for_size dist/BotsApp.js" 9 | }, 10 | "author": "Prince Mendiratta", 11 | "license": "ISC", 12 | "dependencies": { 13 | "@adiwajshing/keyed-db": "^0.2.4", 14 | "@nuintun/qrcode": "^3.0.1", 15 | "@vitalets/google-translate-api": "^7.0.0", 16 | "@whiskeysockets/baileys": "^6.4.1", 17 | "axios": "^0.27.2", 18 | "chalk": "^4.1.1", 19 | "cheerio": "^1.0.0-rc.11", 20 | "dotenv": "^10.0.0", 21 | "fluent-ffmpeg": "^2.1.2", 22 | "form-data": "^4.0.0", 23 | "google-dictionary-api": "^1.0.8", 24 | "google-search-results-nodejs": "^2.0.1", 25 | "google-tts-api": "^2.0.2", 26 | "got": "^11.8.2", 27 | "jimp": "^0.16.1", 28 | "jsdom": "^19.0.0", 29 | "ocr-space-api-wrapper": "^1.0.6", 30 | "pg": "^8.7.1", 31 | "pino": "^7.11.0", 32 | "qrcode-reader": "^1.0.4", 33 | "qrcode-terminal": "^0.12.0", 34 | "sequelize": "^6.7.0", 35 | "simple-git": "^2.47.0", 36 | "songlyrics": "^2.2.4", 37 | "sqlite3": "^5.0.2", 38 | "string-format": "^2.0.0", 39 | "typescript": "^4.6.4", 40 | "unofficial-carbon-now": "^1.0.3", 41 | "urban-dictionary": "^3.0.2", 42 | "yt-search": "^2.10.1", 43 | "ytdl-core": "^4.11.2" 44 | }, 45 | "devDependencies": { 46 | "@types/node": "^20.5.7", 47 | "@types/string-format": "^2.0.0", 48 | "@types/urban-dictionary": "^3.0.0", 49 | "@types/ws": "^8.5.3" 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /qr.js: -------------------------------------------------------------------------------- 1 | const con = require('./core/sessionString.js') 2 | const fs = require('fs') 3 | const chalk = require('chalk') 4 | 5 | async function generateStringSession() { 6 | try{ 7 | await con.saveSession(); 8 | } catch (err) { 9 | console.log("Stopped.") 10 | process.exit(1) 11 | } 12 | } 13 | 14 | generateStringSession(); -------------------------------------------------------------------------------- /sidekick/client.ts: -------------------------------------------------------------------------------- 1 | import { AnyMessageContent, GroupMetadata, GroupParticipant, proto, WASocket } from "@whiskeysockets/baileys"; 2 | import { MessageType } from "./message-type"; 3 | import BotsApp from "./sidekick"; 4 | 5 | class Client { 6 | sock: WASocket; 7 | store: any; 8 | 9 | constructor(sock: WASocket, store: any) { 10 | this.sock = sock; 11 | this.store = store; 12 | } 13 | 14 | async sendMessage(jid: string, content: any, type: string, options?: any) { 15 | let res: proto.WebMessageInfo; 16 | let ops: AnyMessageContent; 17 | if (type === MessageType.text) { 18 | ops = { 19 | text: content 20 | } 21 | if (options?.contextInfo?.mentionedJid) { 22 | ops.mentions = options.contextInfo.mentionedJid 23 | } 24 | res = await this.sock.sendMessage(jid, ops); 25 | } else if (type === MessageType.sticker) { 26 | res = await this.sock.sendMessage(jid, { 27 | sticker: new Buffer(content) 28 | }) 29 | } else if (type === MessageType.audio) { 30 | res = await this.sock.sendMessage(jid, { 31 | audio: content, 32 | mimetype: 'audio/mp4' 33 | }) 34 | } else if (type === MessageType.image) { 35 | ops = { 36 | image: content, 37 | } 38 | if (options?.caption) { 39 | ops.caption = options.caption; 40 | } 41 | res = await this.sock.sendMessage(jid, ops); 42 | } else if (type == MessageType.audio) { 43 | res = await this.sock.sendMessage(jid, { 44 | audio: content, 45 | mimetype: 'audio/mp3' 46 | }); 47 | } else if (type === MessageType.buttonsMessage) { 48 | res = await this.sock.sendMessage(jid, content); 49 | } else if (type == MessageType.video) { 50 | ops = { 51 | video: content, 52 | } 53 | if (options?.caption) { 54 | ops.caption = options.caption; 55 | } 56 | res = await this.sock.sendMessage(jid, ops); 57 | } else if (type === MessageType.document) { 58 | ops = { 59 | text: options.caption 60 | } 61 | let ops2: any = { 62 | document: content, 63 | } 64 | if (options?.mimetype) { 65 | ops2.mimetype = options.mimetype; 66 | ops2.fileName = options.filename; 67 | } 68 | // console.log(ops2); 69 | await this.sock.sendMessage(jid, ops); 70 | res = await this.sock.sendMessage(jid, ops2); 71 | } 72 | return res; 73 | }; 74 | 75 | async deleteMessage(jid: string, key: any) { 76 | await this.sock.sendMessage(jid, { 77 | delete: key 78 | }); 79 | }; 80 | 81 | async getGroupMetaData(jid: string, BotsApp: BotsApp) { 82 | const groupMetadata: GroupMetadata = jid.endsWith("@g.us") ? await this.sock.groupMetadata(jid) : null; 83 | const getGroupAdmins = (participants: GroupParticipant[]): string[] => { 84 | var admins: string[] = []; 85 | for (var i in participants) { 86 | participants[i].admin ? admins.push(participants[i].id) : ''; 87 | } 88 | // console.log("ADMINS -> " + admins); 89 | return admins; 90 | } 91 | BotsApp.groupName = BotsApp.isGroup ? groupMetadata.subject : null; 92 | BotsApp.groupMembers = BotsApp.isGroup ? groupMetadata.participants : null; 93 | BotsApp.groupAdmins = BotsApp.isGroup ? getGroupAdmins(BotsApp.groupMembers) : null; 94 | BotsApp.groupId = BotsApp.isGroup ? groupMetadata.id : null; 95 | BotsApp.isBotGroupAdmin = BotsApp.isGroup ? (BotsApp.groupAdmins.includes(BotsApp.owner)) : false; 96 | BotsApp.isSenderGroupAdmin = BotsApp.isGroup ? (BotsApp.groupAdmins.includes(BotsApp.sender)) : false; 97 | } 98 | } 99 | 100 | export = Client; -------------------------------------------------------------------------------- /sidekick/command.ts: -------------------------------------------------------------------------------- 1 | type demo = { 2 | isEnabled: boolean; 3 | text: any; 4 | } 5 | 6 | type Command = { 7 | name: string; 8 | description: string; 9 | extendedDescription: string; 10 | demo: demo; 11 | handle: Function; 12 | } 13 | 14 | export = Command; -------------------------------------------------------------------------------- /sidekick/input-sanitization.ts: -------------------------------------------------------------------------------- 1 | import config from '../config'; 2 | import fs, { PathLike } from "fs"; 3 | import chalk from "chalk"; 4 | import { JSDOM } from "jsdom"; 5 | import db from "../lib/db" 6 | import format from 'string-format'; 7 | import { Transform } from "stream"; 8 | import { writeFile } from 'fs/promises'; 9 | import BotsApp from './sidekick'; 10 | import Client from './client'; 11 | import { MessageType } from "../sidekick/message-type"; 12 | import { GroupParticipant } from '@whiskeysockets/baileys'; 13 | const { window } = new JSDOM(); 14 | const ERROR_TEMPLATE = db.general.ERROR_TEMPLATE 15 | 16 | const getCleanedContact = async (args: string[], client: Client, BotsApp: BotsApp) => { 17 | var jidNumber = ''; 18 | var countryCode = config.COUNTRY_CODE; 19 | if (Number.isNaN(parseInt(args[0])) || args[0][0] === "+" || args[0][0] === "@") { 20 | if (args[0][0] === "@" || args[0][0] === "+") { 21 | jidNumber = args[0].substring(1, args[0].length + 1); 22 | } 23 | else { 24 | client.sendMessage(BotsApp.chatId,"*Enter valid contact number.* Approved Syntax:\n```1. XXXXXXXXXX``` \n```2. Tag the person``` \n```3. +(YYY)XXXXXXXXXX.``` \n_(YY- Country Code, without zeros)_", MessageType.text); 25 | return undefined; 26 | } 27 | } else { 28 | jidNumber = args[0]; 29 | } 30 | 31 | if (jidNumber.length < 8 || jidNumber.length > 13) { 32 | client.sendMessage( 33 | BotsApp.chatId, 34 | "*Enter valid contact number.* Approved Syntax:\n```1. XXXXXXXXXX``` \n```2. Tag the person``` \n```3. +(YYY)XXXXXXXXXX.``` \n_(YY- Country Code, without zeros)_", 35 | MessageType.text 36 | ); 37 | return undefined; 38 | } 39 | else if (jidNumber.length === 10) { 40 | jidNumber = countryCode + jidNumber; 41 | } 42 | console.log(jidNumber); 43 | var isOnWhatsApp = await client.sock.onWhatsApp(jidNumber); 44 | if(isOnWhatsApp === undefined){ 45 | throw "NumberInvalid"; 46 | } 47 | 48 | // isOnWhatsApp is not working 49 | return jidNumber; 50 | } 51 | 52 | const deleteFiles = async (...locations: PathLike[]) => { 53 | for (let location of locations) { 54 | fs.unlink(location, (err) => { 55 | if (err) console.log(err); 56 | else { 57 | // console.log("\nDeleted file at: " + location); 58 | } 59 | }); 60 | } 61 | }; 62 | 63 | // const performanceTime = async (startTime) => { 64 | // var endTime = window.performance.now(); 65 | // console.log( 66 | // `-----------\nExecution time: ${ 67 | // (endTime - startTime) / 1000 68 | // } seconds\n----------` 69 | // ); 70 | // } 71 | 72 | const isMember = async (chatId: string, groupMembers: GroupParticipant[]) => { 73 | var isMember = false; 74 | if(!(chatId === undefined)){ 75 | for (const index in groupMembers) { 76 | if (chatId == groupMembers[index].id.split("@")[0]) { 77 | isMember = true; 78 | } 79 | } 80 | } 81 | return isMember; 82 | } 83 | 84 | const handleError = async (err, client, BotsApp, customMessage = "```Something went wrong. The error has been logged in log chats```") => { 85 | console.log(chalk.redBright.bold("[ERROR] " + err)); 86 | let data = { 87 | commandName: BotsApp.commandName, 88 | fromMe: BotsApp.fromMe, 89 | isReply: BotsApp.isReply, 90 | isGroup: BotsApp.isGroup, 91 | isPm: BotsApp.isPm, 92 | isImage: BotsApp.isImage, 93 | isBotGroupAdmin: BotsApp.isBotGroupAdmin, 94 | isSenderGroupAdmin: BotsApp.isSenderGroupAdmin, 95 | isSenderSudo: BotsApp.isSenderSUDO, 96 | err: err 97 | } 98 | client.sendMessage(BotsApp.chatId, customMessage, MessageType.text); 99 | client.sendMessage(BotsApp.logGroup, format(ERROR_TEMPLATE, data), MessageType.text); 100 | } 101 | 102 | const saveBuffer = async (fileName: string, stream: Transform) => { 103 | let buffer = Buffer.from([]) 104 | for await (const chunk of stream) { 105 | buffer = Buffer.concat([buffer, chunk]) 106 | } 107 | await writeFile(fileName, buffer); 108 | } 109 | 110 | const inputSanitization = { 111 | handleError: handleError, 112 | deleteFiles: deleteFiles, 113 | saveBuffer: saveBuffer, 114 | getCleanedContact: getCleanedContact, 115 | isMember: isMember 116 | } 117 | 118 | export default inputSanitization; 119 | 120 | export const adminCommands = [ 121 | "add", 122 | "demote", 123 | "invite", 124 | "mute", 125 | "promote", 126 | "remove", 127 | "unmute", 128 | "welcome", 129 | "disappear", 130 | "goodbye", 131 | "setdp", 132 | "tagall", 133 | "abl", 134 | "rbl" 135 | ]; 136 | 137 | export const sudoCommands = ["block", "unblock"]; 138 | -------------------------------------------------------------------------------- /sidekick/message-type.ts: -------------------------------------------------------------------------------- 1 | /** Set of message types that are supported by the library */ 2 | export enum MessageType { 3 | text = 'conversation', 4 | extendedText = 'extendedTextMessage', 5 | contact = 'contactMessage', 6 | contactsArray = 'contactsArrayMessage', 7 | groupInviteMessage = 'groupInviteMessage', 8 | listMessage = 'listMessage', 9 | buttonsMessage = 'buttonsMessage', 10 | location = 'locationMessage', 11 | liveLocation = 'liveLocationMessage', 12 | 13 | image = 'imageMessage', 14 | video = 'videoMessage', 15 | sticker = 'stickerMessage', 16 | document = 'documentMessage', 17 | audio = 'audioMessage', 18 | product = 'productMessage' 19 | } -------------------------------------------------------------------------------- /sidekick/sidekick.ts: -------------------------------------------------------------------------------- 1 | import {GroupParticipant} from '@whiskeysockets/baileys' 2 | 3 | class BotsApp { 4 | 5 | mimeType: string; 6 | type: string; 7 | body: string; 8 | commandName: string; 9 | chatId: string; 10 | owner: string; 11 | logGroup: string; 12 | sender: string; 13 | groupName: string; 14 | groupMembers: GroupParticipant[]; 15 | groupAdmins: string[]; 16 | groupId: string; 17 | replyMessageId: string; 18 | replyMessage: string; 19 | imageCaption: string; 20 | replyParticipant: string; 21 | 22 | isTextReply: boolean; 23 | isCmd: boolean; 24 | fromMe: boolean; 25 | isGroup: boolean; 26 | isPm: boolean; 27 | isBotGroupAdmin: boolean; 28 | isSenderGroupAdmin: boolean; 29 | isSenderSUDO: boolean; 30 | isImage: boolean; 31 | isReplyImage: boolean; 32 | isGIF: boolean; 33 | isReplyGIF: boolean; 34 | isSticker: boolean; 35 | isReplySticker: boolean; 36 | isReplyVideo: boolean; 37 | isReplyAudio: boolean; 38 | isVideo: boolean; 39 | isAudio: boolean; 40 | isReplyAnimatedSticker: boolean 41 | } 42 | 43 | export = BotsApp; -------------------------------------------------------------------------------- /tmp/placeholder: -------------------------------------------------------------------------------- 1 | It is as the title states, a placeholder file. -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */ 4 | "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ 5 | "outDir": "./dist", /* Redirect output structure to the directory. */ 6 | "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ 7 | "allowSyntheticDefaultImports": true, 8 | "allowJs": true, 9 | "sourceMap": true 10 | }, 11 | "exclude": ["**/*.test.ts", "./dist/**/*"], 12 | 13 | } -------------------------------------------------------------------------------- /updater.ts: -------------------------------------------------------------------------------- 1 | import gitPull from './core/gitpull'; 2 | 3 | (async () : Promise => { 4 | await gitPull(); 5 | })(); --------------------------------------------------------------------------------