Skip to content

Commit

Permalink
High res profile pic, log level 60
Browse files Browse the repository at this point in the history
Signed-off-by: Prince Mendiratta <[email protected]>
  • Loading branch information
Prince-Mendiratta committed Jul 24, 2022
1 parent f1ac81a commit 746fded
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 25 deletions.
2 changes: 1 addition & 1 deletion BotsApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
48 changes: 33 additions & 15 deletions modules/getdp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
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"),
Expand All @@ -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;
}
},
};
23 changes: 14 additions & 9 deletions modules/quote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export = {
demo: { isEnabled: false, },
async handle(client: Client, chat: proto.IWebMessageInfo, BotsApp: BotsApp, args: string[]): Promise<void> {
try {
if(!BotsApp.isTextReply || (BotsApp.isTextReply && !BotsApp.replyMessage)){
if (!BotsApp.isTextReply || (BotsApp.isTextReply && !BotsApp.replyMessage)) {
await client.sendMessage(
BotsApp.chatId,
quote.NO_REPLY,
Expand All @@ -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);
Expand Down Expand Up @@ -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");
}

0 comments on commit 746fded

Please sign in to comment.