-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_templateResponse.js
171 lines (169 loc) · 6.36 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
// @type {import('@whiskeysockets/baileys')}
const { proto, generateWAMessage, areJidsSameUser, decryptPollVote, } = (await import('@whiskeysockets/baileys')).default;
export async function all(m, chatUpdate) {
if (m.isBaileys) {
return
}
if (!m.message) {
return
}
if (!(m.message.buttonsResponseMessage || m.message.templateButtonReplyMessage || m.message.listResponseMessage || m.message.interactiveResponseMessage)) {
return
}
let id
if (m.message.buttonsResponseMessage) {
id = m.message.buttonsResponseMessage.selectedButtonId
} else if (m.message.templateButtonReplyMessage) {
id = m.message.templateButtonReplyMessage.selectedId
} else if (m.message.listResponseMessage) {
id = m.message.listResponseMessage.singleSelectReply?.selectedRowId;
} else if (m.message.interactiveResponseMessage) {
id = JSON.parse(m.message.interactiveResponseMessage.nativeFlowResponseMessage.paramsJson).id
}
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 ? [[_prefix.exec(id), _prefix]] : Array.isArray(_prefix) ? _prefix.map((p) => {
const re = p instanceof RegExp ? p : new RegExp(str2Regex(p));
return [re.exec(id), re]
}) :
typeof _prefix === '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 ?
plugin.command.test(command) :
Array.isArray(plugin.command) ?
plugin.command.some((cmd) => cmd instanceof RegExp ?
cmd.test(command) :
cmd === command,
) :
typeof plugin.command === '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)
}
/*const {
proto,
generateWAMessage,
areJidsSameUser
} = (await import('@whiskeysockets/baileys')).default
export async function all(m, chatUpdate) {
try {
if (m.isBaileys) return
if (!m.message) return
if (!(m.message.buttonsResponseMessage || m.message.templateButtonReplyMessage || m.message.listResponseMessage ||
m.message.interactiveResponseMessage)) return
let id = m.message.buttonsResponseMessage?.selectedButtonId || m.message.templateButtonReplyMessage?.selectedId ||
m.message.listResponseMessage?.singleSelectReply?.selectedRowId || JSON.parse(m.message
.interactiveResponseMessage?.nativeFlowResponseMessage?.paramsJson)?.id
let text = m.message.buttonsResponseMessage?.selectedDisplayText || m.message.templateButtonReplyMessage
?.selectedDisplayText || m.message.listResponseMessage?.title || m.message.interactiveResponseMessage?.body
?.text
let isIdMessage = false,
usedPrefix
for (let name in plugins) {
let plugin = 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, '\\$&')
let _prefix = plugin.customPrefix ? plugin.customPrefix : this.prefix ? this.prefix : prefix
let match = (_prefix instanceof RegExp ? // RegExp Mode?
[
[_prefix.exec(id), _prefix]
] : Array.isArray(_prefix) ? // Array?
_prefix.map(p => {
let 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])) {
let noPrefix = id.replace(usedPrefix, '')
let [command] = noPrefix.trim().split(' ').filter(v => v)
command = (command || '').toLowerCase()
let 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
}
}
let messages = await generateWAMessage(m.chat, {
text: isIdMessage ? id : text,
mentions: m.mentionedJid
}, {
userJid: this.user.id,
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
let msg = {
...chatUpdate,
messages: [proto.WebMessageInfo.fromObject(messages)].map(v => (v.conn = this, v)),
type: 'append'
}
this.ev.emit('messages.upsert', msg)
} catch (error) {
console.error('Error in processing message:', error);
}
}
*/