diff --git a/BotsApp.ts b/BotsApp.ts index 2f40449..e13f43e 100644 --- a/BotsApp.ts +++ b/BotsApp.ts @@ -25,7 +25,7 @@ const sequelize: Sequelize = config.DATABASE; const GENERAL: any = STRINGS.general; const msgRetryCounterMap: MessageRetryMap = {}; const logger: Logger = P({ timestamp: () => `,"time":"${new Date().toJSON()}"` }).child({}) -logger.level = 'error' +logger.level = 'fatal' // the store maintains the data of the WA connection in memory // can be written out to a file & read from it diff --git a/modules/getdp.ts b/modules/getdp.ts index 53e30c4..e6e8eca 100644 --- a/modules/getdp.ts +++ b/modules/getdp.ts @@ -13,26 +13,34 @@ module.exports = { extendedDescription: GETDP.EXTENDED_DESCRIPTION, demo: { isEnabled: true, text: ".getdp" }, async handle(client: Client, chat: proto.IWebMessageInfo, BotsApp: BotsApp, args: string[]): Promise { + const getDp = async (jid: string) => { + let url: string; + try { + url = await client.sock.profilePictureUrl(jid, "image"); + } catch { + try { + url = await client.sock.profilePictureUrl(jid); + } catch(err) { + if (err.data === 404 || err.data === 401) { + return err; + } else { + console.log('Error in getting profile pic - ' + console.log(err)); + } + } + } + return url; + }; + try { let url: string; if (!args[0]) { - url = await client.sock.profilePictureUrl(BotsApp.chatId); + url = await getDp(BotsApp.chatId); } else { let jid: string = args[0].split("@")[1] + "@s.whatsapp.net"; - url = await client.sock.profilePictureUrl(jid); + url = await getDp(jid); } - await client.sendMessage( - BotsApp.chatId, - { url: url }, - MessageType.image, - { - caption: GETDP.IMAGE_CAPTION - } - ); - return - } catch (err) { - if (err.data === 404 || err.data === 401) { + if(typeof(url) === 'object'){ await client.sendMessage( BotsApp.chatId, fs.readFileSync("./images/default_dp.png"), @@ -41,11 +49,21 @@ module.exports = { caption: "```This is the display picture visible to me. :P```", } ); - } else { - await inputSanitization.handleError(err, client, BotsApp); + return; } + await client.sendMessage( + BotsApp.chatId, + { url: url }, + MessageType.image, + { + caption: GETDP.IMAGE_CAPTION + } + ); return + } catch (err) { + await inputSanitization.handleError(err, client, BotsApp); + return; } }, }; diff --git a/modules/quote.ts b/modules/quote.ts index 8879054..35ce47b 100644 --- a/modules/quote.ts +++ b/modules/quote.ts @@ -18,7 +18,7 @@ export = { demo: { isEnabled: false, }, async handle(client: Client, chat: proto.IWebMessageInfo, BotsApp: BotsApp, args: string[]): Promise { try { - if(!BotsApp.isTextReply || (BotsApp.isTextReply && !BotsApp.replyMessage)){ + if (!BotsApp.isTextReply || (BotsApp.isTextReply && !BotsApp.replyMessage)) { await client.sendMessage( BotsApp.chatId, quote.NO_REPLY, @@ -31,19 +31,24 @@ export = { quote.PROCESSING, MessageType.text ); - const contact = client.store.contacts[BotsApp.replyParticipant]; + console.log(JSON.stringify(chat)); + const contact = client.store?.contacts[BotsApp.replyParticipant] || undefined; let quotedReply = BotsApp.replyMessage.replace(/```/g, ''); let name = contact?.name || contact?.notify || (BotsApp.replyParticipant === BotsApp.owner ? client.sock.user.name : BotsApp.replyParticipant.split("@")[0]); let fileName = './tmp/quote-' + chat.key.id; let stickerPath = './tmp/quote-' + chat.key.id + ".webp"; let url: String; try { - url = await client.sock.profilePictureUrl(BotsApp.replyParticipant); - }catch(err){ - if (err.data === 404 || err.data === 401) { - url = "https://i.imgur.com/vjLIqgO.png"; - } else { - await inputSanitization.handleError(err, client, BotsApp); + url = await client.sock.profilePictureUrl(BotsApp.replyParticipant, "image"); + } catch (err) { + try { + url = await client.sock.profilePictureUrl(BotsApp.replyParticipant); + } catch { + if (err.data === 404 || err.data === 401) { + url = "https://i.imgur.com/vjLIqgO.png"; + } else { + await inputSanitization.handleError(err, client, BotsApp); + } } } let img = await getQuotly(quotedReply, name, url); @@ -114,5 +119,5 @@ const getQuotly = async (text: String, name: Object, url: String) => { ] } let res = await Axios.post('https://bot.lyo.su/quote/generate', body); - return Buffer.alloc(res.data.result.image.length ,res.data.result.image, "base64"); + return Buffer.alloc(res.data.result.image.length, res.data.result.image, "base64"); } \ No newline at end of file