-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path_templateResponse.js
109 lines (108 loc) · 4.05 KB
/
_templateResponse.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/**
* @type {import('@whiskeysockets/baileys')}
*/
const {
proto,
generateWAMessage,
areJidsSameUser,
decryptPollVote,
} = (await import('@whiskeysockets/baileys')).default;
export async function all(m, chatUpdate) {
/* if (m.message.pollUpdateMessage) {
console.log(m.message.pollUpdateMessage)
console.log(m.message.pollUpdateMessage.pollCreationMessageKey)
let authcode = "eed1zxI49cxiovBTUFLIEWi1shD9HgIOghONuqPDGTk="
let xds = decryptPollVote({
encPayload: m.message.pollUpdateMessage.vote.encPayload,
encIv: m.message.pollUpdateMessage.vote.encIv,
}, {
pollCreatorJid: m.message.pollUpdateMessage.pollCreationMessageKey.participant,
pollMsgId: m.message.pollUpdateMessage.pollCreationMessageKey.id,
pollEncKey: authcode, //Uint8Array.from(authcode.split('').map(letter => letter.charCodeAt(0))),
voterJid: m.sender,
})
console.log(xds)
}*/
if (m.isBaileys) {
return;
}
if (!m.message) {
return;
}
if (!(m.message.buttonsResponseMessage || m.message.templateButtonReplyMessage || m.message.listResponseMessage)) {
return;
}
const id = m.message.buttonsResponseMessage?.selectedButtonId || m.message.templateButtonReplyMessage?.selectedId || m.message.listResponseMessage?.singleSelectReply?.selectedRowId;
const text = m.message.buttonsResponseMessage?.selectedDisplayText || m.message.templateButtonReplyMessage?.selectedDisplayText || m.message.listResponseMessage?.title;
let isIdMessage = false; let usedPrefix;
for (const name in global.plugins) {
const plugin = global.plugins[name];
if (!plugin) {
continue;
}
if (plugin.disabled) {
continue;
}
if (!opts['restrict']) {
if (plugin.tags && plugin.tags.includes('admin')) {
continue;
}
}
if (typeof plugin !== 'function') {
continue;
}
if (!plugin.command) {
continue;
}
const str2Regex = (str) => str.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&');
const _prefix = plugin.customPrefix ? plugin.customPrefix : this.prefix ? this.prefix : global.prefix;
const match = (_prefix instanceof RegExp ? // RegExp Mode?
[[_prefix.exec(id), _prefix]] :
Array.isArray(_prefix) ? // Array?
_prefix.map((p) => {
const re = p instanceof RegExp ? // RegExp in Array?
p :
new RegExp(str2Regex(p));
return [re.exec(id), re];
}) :
typeof _prefix === 'string' ? // String?
[[new RegExp(str2Regex(_prefix)).exec(id), new RegExp(str2Regex(_prefix))]] :
[[[], new RegExp]]
).find((p) => p[1]);
if ((usedPrefix = (match[0] || '')[0])) {
const noPrefix = id.replace(usedPrefix, '');
let [command] = noPrefix.trim().split` `.filter((v) => v);
command = (command || '').toLowerCase();
const isId = plugin.command instanceof RegExp ? // RegExp Mode?
plugin.command.test(command) :
Array.isArray(plugin.command) ? // Array?
plugin.command.some((cmd) => cmd instanceof RegExp ? // RegExp in Array?
cmd.test(command) :
cmd === command,
) :
typeof plugin.command === 'string' ? // String?
plugin.command === command :
false;
if (!isId) {
continue;
}
isIdMessage = true;
}
}
const messages = await generateWAMessage(m.chat, {text: isIdMessage ? id : text, mentions: m.mentionedJid}, {
userJid: this.user.id,
quoted: m.quoted && m.quoted.fakeObj,
});
messages.key.fromMe = areJidsSameUser(m.sender, this.user.id);
messages.key.id = m.key.id;
messages.pushName = m.name;
if (m.isGroup) {
messages.key.participant = messages.participant = m.sender;
}
const msg = {
...chatUpdate,
messages: [proto.WebMessageInfo.fromObject(messages)].map((v) => (v.conn = this, v)),
type: 'append',
};
this.ev.emit('messages.upsert', msg);
}