Skip to content

Commit

Permalink
Fixed issue vasani-arpit#334
Browse files Browse the repository at this point in the history
  • Loading branch information
Kashvigandhi committed Oct 17, 2023
1 parent d0c6e84 commit b3aebdb
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 29 deletions.
4 changes: 2 additions & 2 deletions bot.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"downloadMedia": true,
"replyUnreadMsg": false,
"CustomInjectionFolder": "",
"quoteMessageInReply": true
"quoteMessageInReply": false
},
"bot": [{
"contains": [],
Expand Down Expand Up @@ -70,7 +70,7 @@
"contains": [],
"exact": ["github"],
"response": "Git Hub Logo",
"file":"{github.png|github-two.png}",
"file":["github.png","github-two.png"],
"responseAsCaption": false
},
{
Expand Down
3 changes: 2 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 31 additions & 26 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ async function getResponse(msg, message) {
}



async function sendReply({ msg, client, data, noMatch }) {


Expand Down Expand Up @@ -252,21 +253,40 @@ async function sendReply({ msg, client, data, noMatch }) {
captionStatus = false;
}

files = await spintax.unspin(data.file);

// files = await spintax.unspin(data.file);
files = data.file
if(Array.isArray(files))
{
files.forEach(file => {
sendFile(msg,client,file,response,captionStatus)
})
}
else{
sendFile(msg,client,files,response,captionStatus)
}
// if responseAsCaption is true, send image with response as a caption
// else send image and response seperately
await client.sendMessage(msg.from, response);
} else {
if (!configs.appconfig.quoteMessageInReply) {
await client.sendMessage(msg.from, response);
}
else {
await msg.reply(response);
}
}
function sendFile(file){
if (captionStatus == true) {
utils
.getFileData(files)
.getFileData(file)
.then(async ({ fileMime, base64 }) => {

// console.log(fileMime);
// send response in place of caption as a last argument in below function call
var media = await new MessageMedia(
fileMime,
base64,
files
file
);
if (!configs.appconfig.quoteMessageInReply) {
await client.sendMessage(msg.from, media, { caption: response });
Expand All @@ -288,16 +308,16 @@ async function sendReply({ msg, client, data, noMatch }) {
console.log(
"Either the responseAsCaption is undefined or false, Make it true to allow caption to a file"
);

utils
.getFileData(files)
.getFileData(file)
.then(async ({ fileMime, base64 }) => {
// console.log(fileMime);
// send blank in place of caption as a last argument in below function call
var media = await new MessageMedia(
fileMime,
base64,
files
file
);
if (!configs.appconfig.quoteMessageInReply) {
await client.sendMessage(msg.from, media);
Expand All @@ -308,26 +328,11 @@ async function sendReply({ msg, client, data, noMatch }) {
})
.catch((error) => {
console.log("Error in sending file\n" + error);
}).finally(async () => {
if (!configs.appconfig.quoteMessageInReply) {
await client.sendMessage(msg.from, response);
}
else {
await msg.reply(response);
}
})
}
} else {
if (!configs.appconfig.quoteMessageInReply) {
await client.sendMessage(msg.from, response);
}
else {
await msg.reply(response);
}
}
}}

}


async function processWebhook({ msg, client }) {


Expand Down Expand Up @@ -443,4 +448,4 @@ async function checkForUpdate() {
}
}

Main();
Main();

0 comments on commit b3aebdb

Please sign in to comment.