forked from Prince-Mendiratta/BotsApp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modified 'getdp' module to display tagged person's display image. (Pr…
…ince-Mendiratta#72) * Reincluded qr and decodeqr files. Signed-off-by: Johann <johannjose@msn.com> * Reformat code Signed-off-by: Prince Mendiratta <prince.mendi@gmail.com> Co-authored-by: Prince Mendiratta <prince.mendi@gmail.com>
- Loading branch information
1 parent
c9fcc6e
commit 0e5e161
Showing
4 changed files
with
239 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
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,140 @@ | ||
const { MessageType } = require("@adiwajshing/baileys"); | ||
const Jimp = require("jimp"); | ||
const fs = require("fs"); | ||
const ffmpeg = require("fluent-ffmpeg"); | ||
const { JSDOM } = require("jsdom"); | ||
const { window } = new JSDOM(); | ||
const inputSanitization = require("../sidekick/input-sanitization"); | ||
const qrCode = require("qrcode-reader"); | ||
const Strings = require("../lib/db"); | ||
const DECODE = Strings.decodeqr; | ||
|
||
module.exports = { | ||
name: "dqr", | ||
description: DECODE.DESCRIPTION, | ||
extendedDescription: DECODE.EXTENDED_DESCRIPTION, | ||
demo: { isEnabled: false }, | ||
|
||
async handle(client, chat, BotsApp, args) { | ||
var startTime = window.performance.now(); | ||
|
||
var processing, filePath; | ||
|
||
// Function to convert qr to text | ||
const qrToText = async (imagePath, processing) => { | ||
var buffer = fs.readFileSync(imagePath); | ||
Jimp.read(buffer, function (err, image) { | ||
if (err) { | ||
console.error(err); | ||
} | ||
let qrcode = new qrCode(); | ||
qrcode.callback = async function (err, value) { | ||
if (err) { | ||
console.error(err); | ||
} else { | ||
// Printing the decrypted value | ||
console.log(value.result); | ||
await client | ||
.sendMessage(BotsApp.chatId, value.result, MessageType.text) | ||
.catch((err) => | ||
inputSanitization.handleError(err, client, BotsApp) | ||
); | ||
} | ||
}; | ||
|
||
// Decoding the QR code | ||
qrcode.decode(image.bitmap); | ||
}); | ||
|
||
//Image and message deletion | ||
await inputSanitization.deleteFiles(imagePath); | ||
return await client | ||
.deleteMessage(BotsApp.chatId, { | ||
id: processing.key.id, | ||
remoteJid: BotsApp.chatId, | ||
fromMe: true, | ||
}) | ||
.catch((err) => inputSanitization.handleError(err, client, BotsApp)); | ||
}; | ||
|
||
// Function to convert sticker to image | ||
const convertToImage = async (stickerId, replyChat, processing) => { | ||
const fileName = "./tmp/convert_to_image-" + stickerId; | ||
const filePath = await client | ||
.downloadAndSaveMediaMessage(replyChat, fileName) | ||
.catch((err) => inputSanitization.handleError(err, client, BotsApp)); | ||
const imagePath = "./tmp/image-" + stickerId + ".png"; | ||
|
||
try { | ||
ffmpeg(filePath) | ||
.save(imagePath) | ||
.on("error", async function (err, stdout, stderr) { | ||
inputSanitization.deleteFiles(filePath); | ||
inputSanitization.performanceTime(startTime); | ||
throw err; | ||
}) | ||
.on("end", async () => { | ||
inputSanitization.deleteFiles(filePath); | ||
inputSanitization.performanceTime(startTime); | ||
qrToText(imagePath, processing); | ||
}); | ||
|
||
} catch (err) { | ||
await inputSanitization.handleError(err, client, BotsApp); | ||
} | ||
}; | ||
|
||
try { | ||
if (BotsApp.isReply && (BotsApp.isReplyAudio || BotsApp.isReplyVideo || BotsApp.isReplyAnimatedSticker)) { | ||
|
||
await client | ||
.sendMessage(BotsApp.chatId, DECODE.INVALID_REPLY, MessageType.text) | ||
.catch((err) => inputSanitization.handleError(err, client, BotsApp)); | ||
inputSanitization.performanceTime(startTime); | ||
return; | ||
|
||
} else if (BotsApp.isReplySticker) { | ||
|
||
processing = await client | ||
.sendMessage(BotsApp.chatId, DECODE.PROCESSING, MessageType.text) | ||
.catch((err) => inputSanitization.handleError(err, client, BotsApp)); | ||
var replyChatObject = { | ||
message: chat.message.extendedTextMessage.contextInfo.quotedMessage, | ||
}; | ||
var stickerId = chat.message.extendedTextMessage.contextInfo.stanzaId; | ||
filePath = await convertToImage(stickerId, replyChatObject, processing); | ||
|
||
} else if (BotsApp.isReplyImage) { | ||
|
||
processing = await client | ||
.sendMessage(BotsApp.chatId, DECODE.PROCESSING, MessageType.text) | ||
.catch((err) => inputSanitization.handleError(err, client, BotsApp)); | ||
var imageId = chat.key.id; | ||
const fileName = "./tmp/qr_pic" + imageId; | ||
filePath = await client | ||
.downloadAndSaveMediaMessage( | ||
{ | ||
message: | ||
chat.message.extendedTextMessage.contextInfo.quotedMessage, | ||
}, | ||
fileName | ||
) | ||
.catch((err) => inputSanitization.handleError(err, client, BotsApp)); | ||
|
||
qrToText(filePath, processing); | ||
|
||
} else if (!BotsApp.isImage) { | ||
|
||
await client | ||
.sendMessage(BotsApp.chatId, DECODE.INVALID_INPUT, MessageType.text) | ||
.catch((err) => inputSanitization.handleError(err, client, BotsApp)); | ||
inputSanitization.performanceTime(startTime); | ||
return; | ||
|
||
} | ||
|
||
} catch (err) { | ||
await inputSanitization.handleError(err, client, BotsApp); | ||
} | ||
}, | ||
}; |
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,81 @@ | ||
const { MessageType, Mimetype } = require("@adiwajshing/baileys"); | ||
const inputSanitization = require("../sidekick/input-sanitization"); | ||
const Strings = require("../lib/db"); | ||
const QR = Strings.qr; | ||
const { Encoder, QRByte, ErrorCorrectionLevel } = require("@nuintun/qrcode"); | ||
const fs = require("fs"); | ||
|
||
module.exports = { | ||
name: "qr", | ||
description: QR.DESCRIPTION, | ||
extendedDescription: QR.EXTENDED_DESCRIPTION, | ||
demo: { isEnabled: true, text: ".qr Hey, I am BotsApp." }, | ||
async handle(client, chat, BotsApp, args) { | ||
try { | ||
if (args.length === 0 && !BotsApp.isReply) { | ||
await client | ||
.sendMessage(BotsApp.chatId, QR.INVALID_INPUT, MessageType.text) | ||
.catch((err) => inputSanitization.handleError(err, client, BotsApp)); | ||
return; | ||
} | ||
|
||
const processing = await client | ||
.sendMessage(BotsApp.chatId, QR.PROCESSING, MessageType.text) | ||
.catch((err) => inputSanitization.handleError(err, client, BotsApp)); | ||
|
||
let message; | ||
if (!BotsApp.isReply) { | ||
message = args.join(" "); | ||
} else { | ||
message = BotsApp.replyMessage; | ||
} | ||
|
||
const qrcode = new Encoder(); | ||
|
||
qrcode.setEncodingHint(true); | ||
qrcode.setErrorCorrectionLevel(ErrorCorrectionLevel.Q); | ||
qrcode.write(new QRByte(message)); | ||
qrcode.make(); | ||
const output = qrcode.toDataURL().split(",")[1]; | ||
|
||
const imagePath = "./tmp/qr.png"; | ||
fs.writeFileSync( | ||
imagePath, | ||
output, | ||
{ encoding: "base64" }, | ||
function (err) { | ||
if (err) { | ||
console.log(err); | ||
} | ||
} | ||
); | ||
|
||
await client.sendMessage( | ||
BotsApp.chatId, | ||
fs.readFileSync(imagePath), | ||
MessageType.image, | ||
{ | ||
mimetype: Mimetype.png, | ||
caption: QR.IMAGE_CAPTION, | ||
}).catch((err) => | ||
inputSanitization.handleError(err, client, BotsApp) | ||
); | ||
|
||
inputSanitization.deleteFiles(imagePath); | ||
|
||
await client | ||
.deleteMessage(BotsApp.chatId, { | ||
id: processing.key.id, | ||
remoteJid: BotsApp.chatId, | ||
fromMe: true, | ||
}) | ||
.catch((err) => | ||
inputSanitization.handleError(err, client, BotsApp) | ||
); | ||
return; | ||
|
||
} catch (err) { | ||
await inputSanitization.handleError(err, client, BotsApp); | ||
} | ||
} | ||
}; |
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