-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d930e3d
commit 624a9c4
Showing
6 changed files
with
5,830 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Ignore node_modules folder | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"WABrowserId":"\"4BdzFRgqHjdCkplOmxziKg==\"","WASecretBundle":"{\"key\":\"1UmdkDQ5V66HQ55tcJfDsrb1jl4J4g6VMxI5ghfg0PE=\",\"encKey\":\"ONVlzYv20C2qE8cFiv43d1HEJsGAu1v+F508kLj36QY=\",\"macKey\":\"1UmdkDQ5V66HQ55tcJfDsrb1jl4J4g6VMxI5ghfg0PE=\"}","WAToken1":"\"pu1/+R+a+sGgOIwrFIM67RjVTLcv0e9xBzZH7OMuz84=\"","WAToken2":"\"1@umdmsP1yE8EtAEjRtdepUiyQzF46mEf5Fn0C/7vYABt2J7xkbdSfvYb8yUFaWc/sMWMsnuXJN29jDA==\""} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
const { create, decryptMedia } = require('@open-wa/wa-automate') | ||
const fs = require('fs-extra') | ||
const moment = require('moment') | ||
|
||
const serverOption = { | ||
headless: true, | ||
qrRefreshS: 20, | ||
qrTimeout: 0, | ||
authTimeout: 0, | ||
autoRefresh: true, | ||
devtools: false, | ||
cacheEnabled:false, | ||
chromiumArgs: [ | ||
'--no-sandbox', | ||
'--disable-setuid-sandbox' | ||
] | ||
} | ||
|
||
const opsys = process.platform; | ||
if (opsys == "win32" || opsys == "win64") { | ||
serverOption['executablePath'] = 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe'; | ||
} else if (opsys == "linux") { | ||
serverOption['browserRevision'] = '737027'; | ||
} else if (opsys == "darwin") { | ||
serverOption['executablePath'] = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'; | ||
} | ||
|
||
const startServer = async (from) => { | ||
create('Imperial', serverOption) | ||
.then(client => { | ||
console.log('[SERVER] Server Started!') | ||
|
||
// Force it to keep the current session | ||
client.onStateChanged(state => { | ||
console.log('[State Changed]', state) | ||
if (state === 'CONFLICT') client.forceRefocus() | ||
}) | ||
|
||
client.onMessage((message) => { | ||
msgHandler(client, message) | ||
}) | ||
}) | ||
} | ||
|
||
async function msgHandler (client, message) { | ||
try { | ||
// console.log(message) | ||
const { type, body, from, t, sender, isGroupMsg, chat, caption, isMedia, mimetype, quotedMsg } = message | ||
const { id, pushname } = sender | ||
const { name } = chat | ||
const time = moment(t * 1000).format('DD/MM HH:mm:ss') | ||
const commands = ['#sticker', '#stiker', '#hello','#info','#commands','#God','#Thank you','#I love you','#seasonal anime',] | ||
const cmds = commands.map(x => x + '\\b').join('|') | ||
const cmd = type === 'chat' ? body.match(new RegExp(cmds, 'gi')) : type === 'image' && caption ? caption.match(new RegExp(cmds, 'gi')) : '' | ||
|
||
if (cmd) { | ||
if (!isGroupMsg) console.log(color('[EXEC]'), color(time, 'yellow'), color(cmd[0]), 'from', color(pushname)) | ||
if (isGroupMsg) console.log(color('[EXEC]'), color(time, 'yellow'), color(cmd[0]), 'from', color(pushname), 'in', color(name)) | ||
const args = body.trim().split(' ') | ||
switch (cmd[0]) { | ||
case '#sticker': | ||
case '#stiker': | ||
if (isMedia) { | ||
const mediaData = await decryptMedia(message) | ||
const imageBase64 = `data:${mimetype};base64,${mediaData.toString('base64')}` | ||
await client.sendImageAsSticker(from, imageBase64) | ||
} else if (quotedMsg && quotedMsg.type == 'image') { | ||
const mediaData = await decryptMedia(quotedMsg) | ||
const imageBase64 = `data:${quotedMsg.mimetype};base64,${mediaData.toString('base64')}` | ||
await client.sendImageAsSticker(from, imageBase64) | ||
} else if (args.length == 2) { | ||
var isUrl = new RegExp(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/gi); | ||
const url = args[1] | ||
if (url.match(isUrl)) { | ||
await client.sendStickerfromUrl(from, url, { method: 'get' }) | ||
.catch(err => console.log('Caught exception: ', err)) | ||
} else { | ||
client.sendText(from, 'Url is invalid') | ||
} | ||
} else { | ||
client.sendText(from, 'You did not quote a picture, Baka! To make a sticker, send an image with "#sticker" as caption') | ||
} | ||
break | ||
case '#hello': | ||
client.sendText(from, 'Hello there, How can I help?') | ||
break | ||
case '#I love you': | ||
client.sendText(from, 'Aww, I love you too') | ||
break | ||
case '#God': | ||
client.sendText(from, '@Hooman|Neko is God') | ||
break | ||
case '#commands': | ||
client.sendText(from, 'Hi there, These are the usable commands \n #sticker - turns images into stickers \n #Sesonal anime - Displays the anime titles currently airing') | ||
break | ||
case '#Seasonal anime': | ||
client.sendText(from, 'Summer 2020 \n Re:Zero kara Hajimeru Isekai Seikatsu 2nd Season \n Yahari Ore no Seishun Love Comedy wa Machigatteiru. Kan \n The God of High School \n Sword Art Online: Alicization - War of Underworld 2nd Season \n Enen no Shouboutai: Ni no Shou \n Maou Gakuin no Futekigousha: Shijou Saikyou no Maou no Shiso, Tensei shite Shison-tachi no Gakkou e \n Kanojo, Okarishimasu \n Deca-Dence \n Uzaki-chan wa Asobitai! \n Monster Musume no Oishasan') | ||
break | ||
case '#Thank you': | ||
client.sendText(from, 'Its not like I like you or anything, baka!') | ||
break | ||
case '#info': | ||
client.sendText(from, 'This is an open-source program written in Javascript. \n \nBy using the bot you agreeing to our Terms and Conditions \n \nTerms and conditions \n \nYour texts and your whatsapp username will be stored on our servers as long as the bot is active, your data will be erased when the bot goes offline. We do NOT store the images, videos, audio files and documents you send. We will never ask you to sign up or ask you for any of your passwords, OTPs or PINs. \n \n Thank you, Have a great day!') | ||
} | ||
} else { | ||
if (!isGroupMsg) console.log('[RECV]', color(time, 'yellow'), 'Message from', color(pushname)) | ||
if (isGroupMsg) console.log('[RECV]', color(time, 'yellow'), 'Message from', color(pushname), 'in', color(name)) | ||
} | ||
} catch (err) { | ||
console.log(color('[ERROR]', 'red'), err) | ||
} | ||
} | ||
|
||
process.on('Something went wrong', function (err) { | ||
console.log('Caught exception: ', err); | ||
}); | ||
|
||
function color (text, color) { | ||
switch (color) { | ||
case 'red': return '\x1b[31m' + text + '\x1b[0m' | ||
case 'yellow': return '\x1b[33m' + text + '\x1b[0m' | ||
default: return '\x1b[32m' + text + '\x1b[0m' // default is green | ||
} | ||
} | ||
|
||
startServer() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const fetch = require('node-fetch'); | ||
|
||
const 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.getBase64 = getBase64; |
Oops, something went wrong.