Skip to content

Commit

Permalink
New template Response 🐢
Browse files Browse the repository at this point in the history
support already 
edit msg
reply edit msg
  • Loading branch information
xxirfanx authored Jul 15, 2024
1 parent d0dc24d commit f3f40ec
Showing 1 changed file with 11 additions and 39 deletions.
50 changes: 11 additions & 39 deletions plugins/_templateResponse.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,13 @@ const {
export async function all(m, chatUpdate) {
if (m.isBaileys) return
if (!m.message) return
if (!(m.message.buttonsResponseMessage || m.message.templateButtonReplyMessage || m.message.listResponseMessage)) return
let id = m.message.buttonsResponseMessage?.selectedButtonId || m.message.templateButtonReplyMessage?.selectedId || m.message.listResponseMessage?.singleSelectReply?.selectedRowId
let text = m.message.buttonsResponseMessage?.selectedDisplayText || m.message.templateButtonReplyMessage?.selectedDisplayText || m.message.listResponseMessage?.title
let isIdMessage = false, usedPrefix
for (let name in global.plugins) {
let 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, '\\$&')
let _prefix = plugin.customPrefix ? plugin.customPrefix : this.prefix ? this.prefix : global.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 }, {
if (!(m.message.buttonsResponseMessage || m.message.templateButtonReplyMessage || m.message.listResponseMessage || m.message.interactiveResponseMessage || m.message.pollUpdateMessage || m.message.editedMessage)) return

let id = (m.mtype === 'conversation') ? m.message.conversation : (m.mtype == 'imageMessage') ? m.message.imageMessage.caption : (m.mtype == 'videoMessage') ? m.message.videoMessage.caption : (m.mtype == 'extendedTextMessage') ? m.message.extendedTextMessage.text : (m.mtype == 'buttonsResponseMessage') ? m.message.buttonsResponseMessage.selectedButtonId : (m.mtype == 'listResponseMessage') ? m.message.listResponseMessage.singleSelectReply.selectedRowId : (m.mtype == 'templateButtonReplyMessage') ? m.message.templateButtonReplyMessage.selectedId : (m.mtype == 'interactiveResponseMessage') ? JSON.parse(m.msg.nativeFlowResponseMessage.paramsJson).id : (m.mtype == 'templateButtonReplyMessage') ? appenTextMessage(m.msg.selectedId, chatUpdate) : (m.mtype === 'messageContextInfo') ? (m.message.buttonsResponseMessage?.selectedButtonId || m.message.listResponseMessage?.singleSelectReply.selectedRowId || m.text) : (m.mtype === 'editedMessage') ? m.message.editedMessage.message.protocolMessage.editedMessage.conversation ? m.message.editedMessage.message.protocolMessage.editedMessage.conversation : m.message.editedMessage.message.protocolMessage.editedMessage.extendedTextMessage.text : ''

try {

let messages = await generateWAMessage(m.chat, { text: id, mentions: m.mentionedJid }, {
userJid: this.user.id,
quoted: m.quoted && m.quoted.fakeObj
})
Expand All @@ -59,4 +28,7 @@ export async function all(m, chatUpdate) {
type: 'append'
}
this.ev.emit('messages.upsert', msg)
}
} catch (e) {
false
}
}

0 comments on commit f3f40ec

Please sign in to comment.