diff --git a/.all-contributorsrc b/.all-contributorsrc new file mode 100644 index 0000000..54b8bf7 --- /dev/null +++ b/.all-contributorsrc @@ -0,0 +1,33 @@ +{ + "files": [ + "README.md" + ], + "imageSize": 100, + "commit": false, + "contributors": [ + { + "login": "Kry9toN", + "name": "Dhimas Bagus Prayoga", + "avatar_url": "https://avatars1.githubusercontent.com/u/44697929?v=4", + "profile": "http://kry9ton.tech", + "contributions": [ + "code" + ] + }, + { + "login": "rzlamrr", + "name": "dαvιѕтα", + "avatar_url": "https://avatars3.githubusercontent.com/u/46296998?v=4", + "profile": "http://rzlamrr.github.io", + "contributions": [ + "bug" + ] + } + ], + "contributorsPerLine": 7, + "projectName": "KryPtoN-WhatsApp-Bot", + "projectOwner": "Kry9toN", + "repoType": "github", + "repoHost": "https://github.com", + "skipCi": true +} diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..b512c09 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +node_modules \ No newline at end of file diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..233a220 --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,29 @@ +module.exports = { + env: { + commonjs: true, + es6: true, + node: true + }, + extends: 'standard', + globals: { + Atomics: 'readonly', + SharedArrayBuffer: 'readonly' + }, + parser: 'babel-eslint', + parserOptions: { + ecmaVersion: 2018 + }, + rules: { + eqeqeq: 0, + indent: [2, 4], + 'no-var': 2, + 'no-unused-vars': 1, + 'no-unused-expressions': 0, + 'no-self-assign': 0, + 'no-undef': 0, + 'no-case-declarations': 0, + 'prefer-promise-reject-errors': 1, + 'object-property-newline': 0, + 'no-useless-escape': 0 + } +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a1b0581 --- /dev/null +++ b/.gitignore @@ -0,0 +1,17 @@ +node_modules +.idea +debug.log +premium.js +quotemsg.js +lib/quran.js +util/flat.json +util/getScreenshot.js +utils/canvas.js +utils/flat.json +utils/getScreenshot.js +.node-persist +*.code-workspace +lib/instaStory.js +lib/jiwa.js +package-lock.json +.env diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4c73996 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,27 @@ +FROM node:lts + +RUN apt-get update \ +&& apt-get install wget gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 \ +libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 \ +libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 \ +libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 python3 \ +ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget ffmpeg --yes --fix-missing --no-install-recommends\ +&& wget --no-check-certificate https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb \ +&& dpkg -i google-chrome-stable_current_amd64.deb || apt -y -f install \ +&& rm google-chrome-stable_current_amd64.deb \ +&& apt-get clean \ +&& rm -rf /var/lib/apt/lists/* \ +&& apt autoremove --yes + +EXPOSE 8080 + +# +# Clone repo and prepare working directory +# +RUN git clone -b master https://Kry9toN:468213790d@github.com/Kry9toN/KryPtoN-WhatsApp-Bot /home/wabot +WORKDIR /home/wabot +COPY sessions/session.data.json /home/wabot/session.data.json + +RUN npm i + +CMD ["npm", "start"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..242e6e4 --- /dev/null +++ b/README.md @@ -0,0 +1,135 @@ +
+ +# KryPtoN Whatsapp Bot +[![DeepScan grade](https://deepscan.io/api/teams/11540/projects/14446/branches/269535/badge/grade.svg)](https://deepscan.io/dashboard#view=project&tid=11540&pid=14446&bid=269535) +[![Version](https://img.shields.io/badge/version%20K--wa%20Bot-v2.8.8-brightgreen)](https://github.com/Kry9toN/KryPtoN-WhatsApp-Bot/releases) + + +[![All Contributors](https://img.shields.io/badge/all_contributors-2-orange.svg?style=flat-square)](#contributors-) + + +[![Heroku](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/Kry9toN/KryPtoN-WhatsApp-Bot/tree/master) + +
+ +## Features + +| Sticker Creator| Feature | +| :------------: | :---------------------------------------------: | +| ✅ | Send Photo with Caption | +| ✅ | Reply A Photo | +| ✅ | Image Url | +| ✅ | Animated sticker using giphy url | +| ✅ | sticker with no background | +| WIP | sticker meme | + +| Downloader | Feature | +| :------------: | :---------------------------------------------: | +| ✅ | Tiktok Downloader (No WM & WM) | +| ✅ | Twitter Video Downloader | +| ✅ | Facebook Video Downloader (SD & HD) | +| BUG | Instagram Video Downloader | +| ✅ | Youtube MP3 Downloader | +| ✅ | Youtube MP4 Downloader | + +| Edukasi | Feature | +| :------------: | :---------------------------------------------: | +| ✅ | Translate text (quote only) | +| ✅ | Brainly search engine | +| ✅ | Wiki search engine | + +| Other | Feature | +| :------------: | :---------------------------------------------: | +| ✅ | Create Custom meme (top text & bottom text) | +| ✅ | check data on the spread of Covid-19 in certain locations| +| ✅ | Check Shipping info (indonesia only) | +| ✅ | Anti Spam | + +| Grup Only | Feature | +| :------------: | :---------------------------------------------: | +| ✅ | Promote User | +| ✅ | Demote User | +| ✅ | Kick User | +| ✅ | Delete bot message | +| ✅ | Mention All User | +| ✅ | Global Banned | +| ✅ | Filters Message | + +#### Suport Postgrasql database + +## To-Do + - Add More Feature + - More refactoring + +--- + +## Getting Started + +This project require NodeJS v12 (Ubuntu 20.04+). + +### Install +Clone this project + +```bash +> git clone https://github.com/Kry9toN/KryPtoN-WhatsApp-Bot +> cd KryPtoN-WhatsApp-Bot +``` + +Install the dependencies: + +```bash +> npm install +``` + +### Usage +1. run the Whatsapp bot + +```bash +> npm start +``` + +after running it you need to scan the qr + +## Before deoloy heroku + +You must run this bot on your PC/laptop to generate a session +after being authorized, in your folder there will be a file called +``` +session.data.json +``` +please copy on the `sessions` folder with the same name (don't change it) + +## Troubleshooting +Make sure all the necessary dependencies are installed: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md + +Fix Stuck on linux, install google chrome stable: +```bash +> wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb +> sudo apt install ./google-chrome-stable_current_amd64.deb +``` + +## Donate + +### Buy me coffee +[Saweria](https://saweria.co/donate/Kry9toN) + +[Paypal.me](https://www.paypal.me/KomodoOS) + + +## Contributors ✨ + +Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)): + + + + + + + + + +

Dhimas Bagus Prayoga

💻

dαvιѕтα

🐛
+ + + + diff --git a/app.json b/app.json new file mode 100644 index 0000000..b2be3c8 --- /dev/null +++ b/app.json @@ -0,0 +1,25 @@ +{ + "name": "KryPtoN WhatsApp Bot", + "description": "WhatsApp Bot running on Javascript", + "keywords": [ + "whatsapp", + "bot", + "plugin", + "modular", + "productivity" + ], + "repository": "https://github.com/Kry9toN/KryPtoN-WhatsApp-Bot", + "website": "", + "stack": "container", + "env": { + "UserAgent": { + "description": "UserAgne Browser", + "value": "WhatsApp/2.2029.4 Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36", + "required": true + }, + "OWNER_PHONE": { + "description": "Enter your phone number.", + "required": true + } + } +} diff --git a/command/help.js b/command/help.js new file mode 100644 index 0000000..e31f3ce --- /dev/null +++ b/command/help.js @@ -0,0 +1,15 @@ +const { MessageType } = require('@adiwajshing/baileys') + +module.exports = { + name: 'help', + aliases: ['h'], + description: 'Display all commands and descriptions', + execute (client, from) { + const commands = client.cmd.array() + let text = 'Command di bot ini\n\nPrefix: !\n' + commands.forEach((cmd) => { + text += `- *${cmd.name}* ${cmd.aliases ? `(${cmd.aliases})` : ''}\n${cmd.description}\n` + }) + return client.sendMessage(from, text, MessageType.text) + } +} diff --git a/command/ping.js b/command/ping.js new file mode 100644 index 0000000..292da0d --- /dev/null +++ b/command/ping.js @@ -0,0 +1,10 @@ +const { MessageType } = require('@adiwajshing/baileys') + +module.exports = { + name: 'ping', + cooldown: 10, + description: "Show the bot's average ping", + execute (client, from) { + client.sendMessage(from, 'oe', MessageType.text).catch(console.error) + } +} diff --git a/heroku.yml b/heroku.yml new file mode 100644 index 0000000..a1ea733 --- /dev/null +++ b/heroku.yml @@ -0,0 +1,5 @@ +build: + docker: + worker: Dockerfile +run: + worker: npm start diff --git a/krypton.js b/krypton.js new file mode 100644 index 0000000..a755a10 --- /dev/null +++ b/krypton.js @@ -0,0 +1,107 @@ +const { + WAConnection, MessageType +} = require('@adiwajshing/baileys') +const { Collection } = require('discord.js') +const { readdirSync } = require('fs') +const { join } = require('path') +const { start, success } = require('./utils/functions') +const { color } = require('./utils/color') +const fs = require('fs') + +async function krypton () { + const client = new WAConnection() + client.cmd = new Collection() + const cooldowns = new Collection() + client.logger.level = 'warn' + // console.log(banner.string) + await client.on('qr', () => { + console.log(color('[', 'white'), color('!', 'red'), color(']', 'white'), color(' Scan the QR code above')) + }) + + // Connect to sessions if already exist + if (fs.existsSync('./sessions/krypton-sessions.json')) { + await client.loadAuthInfo('./sessions/krypton-sessions.json') + await client.on('connecting', () => { + start('1', ' [SERVER] Connecting to exist sessions...') + }) + } + + // Server connecting + if (!fs.existsSync('./sessions/krypton-sessions.json')) { + await client.on('connecting', () => { + start('1', ' [SERVER] Waitting scan QR to connecting...') + }) + } + + // Server connected + await client.on('open', () => { + success('1', ' [SERVER] Connected') + }) + + // Create file for sessions + await client.connect({ timeoutMs: 30 * 1000 }) + fs.writeFileSync('./sessions/krypton-sessions.json', JSON.stringify(client.base64EncodedAuthInfo(), null, '\t')) + + await client.on('chat-update', async (chat) => { + if (!chat.hasNewMessage) return + const prefix = '!' + chat = JSON.parse(JSON.stringify(chat)).messages[0] + if (!chat.message) return + if (chat.key && chat.key.remoteJid == 'status@broadcast') return + if (chat.key.fromMe) return + const from = chat.key.remoteJid + const type = Object.keys(chat.message)[0] + body = (type === 'conversation' && chat.message.conversation.startsWith(prefix)) ? chat.message.conversation : (type == 'imageMessage') && chat.message.imageMessage.caption.startsWith(prefix) ? chat.message.imageMessage.caption : (type == 'videoMessage') && chat.message.videoMessage.caption.startsWith(prefix) ? chat.message.videoMessage.caption : (type == 'extendedTextMessage') && chat.message.extendedTextMessage.text.startsWith(prefix) ? chat.message.extendedTextMessage.text : '' + const args = body.trim().split(/ +/).slice(1) + const isCmd = body.startsWith(prefix) + const commandName = body.slice(1).trim().split(/ +/).shift().toLowerCase() + + /** + * Import all commands + */ + const commandFiles = readdirSync(join(__dirname, 'command')).filter((file) => file.endsWith('.js')) + for (const file of commandFiles) { + const command = require(join(__dirname, 'command', `${file}`)) + client.cmd.set(command.name, command) + } + + if (!isCmd) return + + const command = + client.cmd.get(commandName) || + client.cmd.find((cmd) => cmd.aliases && cmd.aliases.includes(commandName)) + + if (!command) return + + if (!cooldowns.has(command.name)) { + cooldowns.set(command.name, new Collection()) + } + + const now = Date.now() + const timestamps = cooldowns.get(command.name) + const cooldownAmount = (command.cooldown || 1) * 1000 + + if (timestamps.has(from)) { + const expirationTime = timestamps.get(from) + cooldownAmount + + if (now < expirationTime) { + const timeLeft = (expirationTime - now) / 1000 + return message.reply( + `please wait ${timeLeft.toFixed(1)} more second(s) before reusing the \`${command.name}\` command.` + ) + } + } + + timestamps.set(from, now) + setTimeout(() => timestamps.delete(from), cooldownAmount) + + try { + command.execute(client, from, args) + } catch (error) { + console.error(error) + client.sendMessage(from, 'There was an error executing that command.', MessageType.text).catch(console.error) + } + }) +} + +krypton().catch((err) => console.log(err)) diff --git a/package.json b/package.json new file mode 100644 index 0000000..baa7ae2 --- /dev/null +++ b/package.json @@ -0,0 +1,51 @@ +{ + "name": "krypton-whatsapp-bot", + "version": "0.0.1", + "private": true, + "description": "KryPtoN Whatsapp Bot", + "main": "krypton.js", + "scripts": { + "start": "node krypton.js", + "changelog": "auto-changelog -p && git add CHANGELOG.md", + "release": "read -p 'GITHUB_TOKEN: ' GITHUB_TOKEN && export GITHUB_TOKEN=$GITHUB_TOKEN && release-it" + }, + "author": "KryPtoN", + "repository": { + "type": "git", + "url": "https://github.com/Kry9toN/KryPtoN-WhatsApp-Bot" + }, + "keywords": [ + "Whatsapp", + "WhatsApp-Bot", + "bot", + "wabot" + ], + "release-it": { + "github": { + "release": true + } + }, + "auto-changelog": { + "commitLimit": false + }, + "bugs": { + "url": "https://github.com/Kry9toN/KryPtoN-WhatsApp-Bot/issues" + }, + "homepage": "https://github.com/Kry9toN/KryPtoN-WhatsApp-Bot", + "license": "ISC", + "dependencies": { + "@adiwajshing/baileys": "^3.4.1", + "spinnies": "^0.5.1", + "chalk": "^4.1.0", + "discord.js": "^12.5.1" + }, + "devDependencies": { + "babel-eslint": "^10.1.0", + "eslint": "^7.14.0", + "eslint-config-standard": "^16.0.2", + "eslint-plugin-import": "^2.22.1", + "eslint-plugin-node": "^11.1.0", + "eslint-plugin-promise": "^4.2.1", + "eslint-plugin-standard": "^5.0.0" + } +} diff --git a/sessions/krypton-sessions.json b/sessions/krypton-sessions.json new file mode 100644 index 0000000..931e03e --- /dev/null +++ b/sessions/krypton-sessions.json @@ -0,0 +1,7 @@ +{ + "clientID": "GKLkqJPLYevrdohE3aqyLw==", + "serverToken": "1@BbuGj/99Mi5JiKtNvNNgJXHXByq/ZDSXQLm0CY9MDSpw7egHszko3A7QAPLjZ3cfK2iF1bWcSbafiQ==", + "clientToken": "cv9PgK6hyyCYOzuOqF5Ts5HXkOpevS2ItX4Qf7M6API=", + "encKey": "XmgE05UerNZpLDE2RFvE8/E4jnAkN+DGhib2P1R/gQY=", + "macKey": "ruFSFvGXjPPEfH00mvd6sYSJIEuAz1OPB5kK0x1c/Vo=" +} \ No newline at end of file diff --git a/utils/color.js b/utils/color.js new file mode 100644 index 0000000..9576bdd --- /dev/null +++ b/utils/color.js @@ -0,0 +1,14 @@ +const chalk = require('chalk') + +const color = (text, color) => { + return !color ? chalk.green(text) : chalk.keyword(color)(text) +} + +const bgcolor = (text, bgcolor) => { + return !bgcolor ? chalk.green(text) : chalk.bgKeyword(bgcolor)(text) +} + +module.exports = { + color, + bgcolor +} diff --git a/utils/functions.js b/utils/functions.js new file mode 100644 index 0000000..779668c --- /dev/null +++ b/utils/functions.js @@ -0,0 +1,41 @@ +const Spin = require('spinnies') + +const spinner = { + interval: 120, + frames: [ + '🕐', + '🕑', + '🕒', + '🕓', + '🕔', + '🕕', + '🕖', + '🕗', + '🕘', + '🕙', + '🕚', + '🕛' + ] +} + +let globalSpinner + +const getGlobalSpinner = (disableSpins = false) => { + if (!globalSpinner) globalSpinner = new Spin({ color: 'blue', succeedColor: 'green', spinner, disableSpins }) + return globalSpinner +} + +spins = getGlobalSpinner(false) + +const start = (id, text) => { + spins.add(id, { text: text }) +} + +const success = (id, text) => { + spins.succeed(id, { text: text }) +} + +module.exports = { + start, + success +}