forked from yusufusta/WhatsAsena
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReplyMessage.js
80 lines (67 loc) · 3.09 KB
/
ReplyMessage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* Copyright (C) 2020 Yusuf Usta.
Licensed under the GPL-3.0 License;
you may not use this file except in compliance with the License.
WhatsAsena - Yusuf Usta
*/
const {MessageType, Presence, MessageOptions} = require('@adiwajshing/baileys');
const Base = require('./Base');
const Image = require('./Image');
class ReplyMessage extends Base {
constructor(client, data) {
super(client);
if (data) this._patch(data);
}
_patch(data) {
this.id = data.stanzaId;
this.jid = data.participant;
if (data.quotedMessage && data.quotedMessage.imageMessage) {
this.message = data.quotedMessage.imageMessage.caption === null ? data.message.imageMessage.caption : '';
this.caption = data.quotedMessage.imageMessage.caption === null ? data.message.imageMessage.caption : '';
this.url = data.quotedMessage.imageMessage.url;
this.mimetype = data.quotedMessage.imageMessage.mimetype;
this.height = data.quotedMessage.imageMessage.height;
this.width = data.quotedMessage.imageMessage.width;
this.mediaKey = data.quotedMessage.imageMessage.mediaKey;
this.image = true;
this.video = false;
} else if (data.quotedMessage && data.quotedMessage.videoMessage) {
this.message = data.quotedMessage.videoMessage.caption === null ? data.message.videoMessage.caption : '';
this.caption = data.quotedMessage.videoMessage.caption === null ? data.message.videoMessage.caption : '';
this.url = data.quotedMessage.videoMessage.url;
this.mimetype = data.quotedMessage.videoMessage.mimetype;
this.height = data.quotedMessage.videoMessage.height;
this.width = data.quotedMessage.videoMessage.width;
this.mediaKey = data.quotedMessage.videoMessage.mediaKey;
this.video = true;
} else if (data.quotedMessage && data.quotedMessage.conversation) {
this.message = data.quotedMessage.conversation;
this.text = data.quotedMessage.conversation;
this.image = false;
this.video = false;
}
this.data = data;
return super._patch(data);
}
async delete() {
return await this.client.deleteMessage(this.jid, {id: this.id, remoteJid: this.jid, fromMe: true});
}
async reply(text) {
var message = await this.client.sendMessage(this.jid, text, MessageType.text, {quoted: this.data});
return new Message(this.client, message)
}
async sendMessage(content, type, options) {
return await this.client.sendMessage(this.jid, content, type, options);
}
async sendTyping() {
return await this.client.updatePresence(this.jid, Presence.composing);
}
async download(location = this.id) {
if (this.image) {
await this.client.downloadAndSaveMediaMessage(this.data.quotedMessage.imageMessage, location);
return this.id + '.' + this.mimetype.split('/')[1];
} else {
return false;
}
}
};
module.exports = ReplyMessage;