From 2631cca30fdb1fe670bd8e2bf98109ae2e1625ad Mon Sep 17 00:00:00 2001 From: Kry9toN Date: Tue, 19 Jan 2021 18:09:02 +0700 Subject: [PATCH] add new fiture nulis nulis2 slap --- command/help.js | 1 + command/nulis.js | 18 ++++++++++++++++++ command/nulis2.js | 17 +++++++++++++++++ command/slap.js | 24 +++++++++++++++++++++++ krypton.js | 17 +++++++++-------- package.json | 3 ++- utils/fetcher.js | 47 ++++++++++++++++++++++++++++++++++++++++++++++ utils/functions.js | 22 +++++++++++++++++++++- 8 files changed, 139 insertions(+), 10 deletions(-) create mode 100644 command/nulis.js create mode 100644 command/nulis2.js create mode 100644 command/slap.js create mode 100644 utils/fetcher.js diff --git a/command/help.js b/command/help.js index 3cc8343..e2be3b5 100644 --- a/command/help.js +++ b/command/help.js @@ -13,6 +13,7 @@ module.exports = { }) return client.reply(text) } else { + if (!client.cmd.has(args[0])) return client.reply('Perintah yang anda maksut tidak ada bro') const text = client.cmd.get(args[0]).description return client.reply(text) } diff --git a/command/nulis.js b/command/nulis.js new file mode 100644 index 0000000..2336752 --- /dev/null +++ b/command/nulis.js @@ -0,0 +1,18 @@ +const { MessageType } = require('@adiwajshing/baileys') +const { getBuffer } = require('../utils/functions') +const { fetchJson } = require('../utils/fetcher') + +module.exports = { + name: 'nulis', + aliases: ['n'], + description: 'Untuk menuliskan di buku bot\nPenggunaan !nulis _tulisan_', + execute (client, chat, pesan, args) { + const value = args.slice().join(' ') + fetchJson(`https://mhankbarbar.tech/nulis?text=${value}&apiKey=${client.apiKey}`, {method: 'get'}) + .then(async (hasil) => { + client.reply(pesan.tunggu) + const buffer = await getBuffer(hasil.result) + client.sendMessage(client.from, buffer, MessageType.image, {quoted: chat, caption: pesan.berhasil}) + }).catch((err) => console.log(err)) + } +} diff --git a/command/nulis2.js b/command/nulis2.js new file mode 100644 index 0000000..ba697b2 --- /dev/null +++ b/command/nulis2.js @@ -0,0 +1,17 @@ +const { MessageType } = require('@adiwajshing/baileys') +const { getBuffer } = require('../utils/functions') +const { fetchJson } = require('../utils/fetcher') + +module.exports = { + name: 'nulis2', + aliases: ['n2'], + description: 'Untuk menuliskan di buku bot\nPenggunaan !nulis _tulisan_', + execute (client, chat, pesan, args) { + const value = args.slice().join(' ') + getBuffer(`https://api.zeks.xyz/api/nulis?text=${value}&apikey=administrator`) + .then((hasil) => { + client.reply(pesan.tunggu) + client.sendMessage(client.from, hasil, MessageType.image, {quoted: chat, caption: pesan.berhasil}) + }).catch((err) => console.log(err)) + } +} diff --git a/command/slap.js b/command/slap.js new file mode 100644 index 0000000..003c40a --- /dev/null +++ b/command/slap.js @@ -0,0 +1,24 @@ +module.exports = { + name: 'slap', + description: 'Untuk menampol orang\nPenggunaan !slap _tag_', + execute (client, chat, pesan, args) { + if (!client.isGroup) return client.reply(pesan.error.group) + if (chat.message.extendedTextMessage === undefined || chat.message.extendedTextMessage === null) return client.reply('Tag target yang ingin di tonjok!') + mentioned = chat.message.extendedTextMessage.contextInfo.mentionedJid + const tagList = [] + const dari = client.sender + const target = mentioned[0] + tagList.push(dari, target) + const data = [ + `@${dari.split('@')[0]} melempar *pisang busuk* ke @${target.split('@')[0]}`, + `@${dari.split('@')[0]} bersiap-siap untuk melempar *sekop* ke @${target.split('@')[0]}`, + `@${dari.split('@')[0]} manapar dengan keras @${target.split('@')[0]} dengan *50jt TON truk*`, + `@${dari.split('@')[0]} mulai *memukul* @${target.split('@')[0]} dengan sendok`, + `@${dari.split('@')[0]} menjatuhkan *meteor* ke @${target.split('@')[0]}`, + `@${dari.split('@')[0]} bersiap-siap *me-rasengan* @${target.split('@')[0]}`, + `@${dari.split('@')[0]} menulis nama @${target.split('@')[0]} di *death note*` + ] + const dataslap = data[Math.floor(Math.random() * data.length)] + client.mentions(`${dataslap}`, tagList, true) + } +} diff --git a/krypton.js b/krypton.js index d7a2598..7e75d36 100644 --- a/krypton.js +++ b/krypton.js @@ -72,6 +72,7 @@ async function krypton () { await client.on('chat-update', async (chat) => { client.pingStart = chat.t + client.apiKey = 'EgUxT1qnZ8gtO8ArahNZ' if (!chat.hasNewMessage) return const prefix = '!' chat = JSON.parse(JSON.stringify(chat)).messages[0] @@ -91,7 +92,7 @@ async function krypton () { const ownerNumber = ['6285892766102@s.whatsapp.net'] // replace this with your number client.from = chat.key.remoteJid client.isGroup = client.from.endsWith('@g.us') - const sender = client.isGroup ? chat.participant : chat.key.remoteJid + client.sender = client.isGroup ? chat.participant : chat.key.remoteJid const groupMetadata = client.isGroup ? await client.groupMetadata(client.from) : '' const groupName = client.isGroup ? groupMetadata.subject : '' client.groupMembers = client.isGroup ? groupMetadata.participants : '' @@ -99,8 +100,8 @@ async function krypton () { client.groupId = client.isGroup ? groupMetadata.jid : '' client.isGroup = client.from.endsWith('@g.us') client.isBotGroupAdmins = groupAdmins.includes(botNumber) || false - client.isGroupAdmins = groupAdmins.includes(sender) || false - client.isOwner = ownerNumber.includes(sender) + client.isGroupAdmins = groupAdmins.includes(client.sender) || false + client.isOwner = ownerNumber.includes(client.sender) client.isUrl = (url) => { // eslint-disable-next-line prefer-regex-literals return url.match(new RegExp(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&/=]*)/, 'gi')) @@ -122,10 +123,10 @@ async function krypton () { client.isQuotedSticker = type === 'extendedTextMessage' && content.includes('stickerMessage') // Logging Message - if (!client.isGroup && isCmd) console.log('\x1b[1;31m~\x1b[1;37m>', '[\x1b[1;32mEXEC\x1b[1;37m]', time, color(commandName), 'client.from', color(sender.split('@')[0]), 'args :', color(args.length)) - if (!client.isGroup && !isCmd) console.log('\x1b[1;31m~\x1b[1;37m>', '[\x1b[1;31mRECV\x1b[1;37m]', time, color('Message'), 'client.from', color(sender.split('@')[0]), 'args :', color(args.length)) - if (isCmd && client.isGroup) console.log('\x1b[1;31m~\x1b[1;37m>', '[\x1b[1;32mEXEC\x1b[1;37m]', time, color(commandName), 'client.from', color(sender.split('@')[0]), 'in', color(groupName), 'args :', color(args.length)) - if (!isCmd && client.isGroup) console.log('\x1b[1;31m~\x1b[1;37m>', '[\x1b[1;31mRECV\x1b[1;37m]', time, color('Message'), 'client.from', color(sender.split('@')[0]), 'in', color(groupName), 'args :', color(args.length)) + if (!client.isGroup && isCmd) console.log('\x1b[1;31m~\x1b[1;37m>', '[\x1b[1;32mEXEC\x1b[1;37m]', time, color(commandName), 'client.from', color(client.sender.split('@')[0]), 'args :', color(args.length)) + if (!client.isGroup && !isCmd) console.log('\x1b[1;31m~\x1b[1;37m>', '[\x1b[1;31mRECV\x1b[1;37m]', time, color('Message'), 'client.from', color(client.sender.split('@')[0]), 'args :', color(args.length)) + if (isCmd && client.isGroup) console.log('\x1b[1;31m~\x1b[1;37m>', '[\x1b[1;32mEXEC\x1b[1;37m]', time, color(commandName), 'client.from', color(client.sender.split('@')[0]), 'in', color(groupName), 'args :', color(args.length)) + if (!isCmd && client.isGroup) console.log('\x1b[1;31m~\x1b[1;37m>', '[\x1b[1;31mRECV\x1b[1;37m]', time, color('Message'), 'client.from', color(client.sender.split('@')[0]), 'in', color(groupName), 'args :', color(args.length)) pesan = { tunggu: '⌛ Sedang di Prosess ⌛', @@ -189,4 +190,4 @@ async function krypton () { }) } -krypton().catch((err) => console.log(err)) +krypton().catch((err) => console.log('Error : %s', color(err, 'red'))) diff --git a/package.json b/package.json index 7dec7fa..16edd8d 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,8 @@ "axios": "^0.21.1", "wa-canvas": "git+https://github.com/Kry9toN/wa-canvas.git", "release-it": "^14.2.2", - "cfonts": "^2.9.1" + "cfonts": "^2.9.1", + "node-fetch": "^2.6.1" }, "devDependencies": { "babel-eslint": "^10.1.0", diff --git a/utils/fetcher.js b/utils/fetcher.js new file mode 100644 index 0000000..b7c701c --- /dev/null +++ b/utils/fetcher.js @@ -0,0 +1,47 @@ +const fetch = require('node-fetch') +const fs = require('fs') + +exports.getBase64 = getBase64 = async (url) => { + const response = await fetch(url, { headers: { 'User-Agent': 'okhttp/4.5.0' } }); + if (!response.ok) throw new Error(`unexpected response ${response.statusText}`); + const buffer = await response.buffer(); + const videoBase64 = `data:${response.headers.get('content-type')};base64,` + buffer.toString('base64'); + if (buffer) + return videoBase64; +}; + +exports.getBuffer = getBuffer = async (url) => { + const res = await fetch(url, {headers: { 'User-Agent': 'okhttp/4.5.0'}, method: 'GET' }) + const anu = fs.readFileSync('./src/emror.jpg') + if (!res.ok) return { type: 'image/jpeg', result: anu } + const buff = await res.buffer() + if (buff) + return { type: res.headers.get('content-type'), result: buff } +} + +exports.fetchJson = fetchJson = (url, options) => new Promise(async (resolve, reject) => { + fetch(url, options) + .then(response => response.json()) + .then(json => { + // console.log(json) + resolve(json) + }) + .catch((err) => { + reject(err) + }) +}) + + +exports.fetchText = fetchText = (url, options) => new Promise(async (resolve, reject) => { + fetch(url, options) + .then(response => response.text()) + .then(text => { + // console.log(text) + resolve(text) + }) + .catch((err) => { + reject(err) + }) +}) + +//exports.getBase64 = getBase64; diff --git a/utils/functions.js b/utils/functions.js index b532e99..29b5a10 100644 --- a/utils/functions.js +++ b/utils/functions.js @@ -63,10 +63,30 @@ const banner = cfonts.render(('KRYPTON|WHATSAPP|BOT'), { lineHeight: 2 }) +const getBuffer = async (url, options) => { + try { + options ? options : {} + const res = await axios({ + method: "get", + url, + headers: { + 'DNT': 1, + 'Upgrade-Insecure-Request': 1 + }, + ...options, + responseType: 'arraybuffer' + }) + return res.data + } catch (e) { + console.log(`Error : ${e}`) + } +} + module.exports = { start, success, processTime, getGroupAdmins, - banner + banner, + getBuffer }