diff --git a/lib/sticker.js b/lib/sticker.js index 0b35d9ce5..f28ba232f 100644 --- a/lib/sticker.js +++ b/lib/sticker.js @@ -7,6 +7,7 @@ const { spawn } = require('child_process') const uploadFile = require('./uploadFile') const { fromBuffer } = require('file-type') const uploadImage = require('./uploadImage') +const WSF = require('wa-sticker-formatter') const tmp = path.join(__dirname, '../tmp') /** @@ -123,6 +124,16 @@ async function sticker4(img, url) { ], 'jpeg', 'webp') } +async function sticker5(img, url, packname, author, categories = ['']) { + const stickerMetadata = { + type: 'full', + pack: packname, + author, + categories, + } + return await new WSF.Sticker(img ? img : url, stickerMetadata).build() +} + /** * Add WhatsApp JSON Exif Metadata * Taken from https://github.com/pedroslopez/whatsapp-web.js/pull/527/files @@ -157,7 +168,7 @@ module.exports = { async sticker(img, url, ...args) { let lastError for (let func of [ - sticker3, + sticker3, sticker5, this.support.ffmpeg && this.support.ffmpegWebp && sticker4, this.support.ffmpeg && (this.support.convert || this.support.magick || this.support.gm) && sticker2, sticker1 @@ -182,6 +193,7 @@ module.exports = { sticker2, sticker3, sticker4, + sticker5, addExif, support: { ffmpeg: true, @@ -191,4 +203,4 @@ module.exports = { magick: false, gm: false, }, -} +} \ No newline at end of file diff --git a/nodemon.json b/nodemon.json deleted file mode 100644 index 4764be3b0..000000000 --- a/nodemon.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "ignore": ["*.json", "plugins/*"] -} \ No newline at end of file diff --git a/package.json b/package.json index e6e5f9fa1..6bc448623 100644 --- a/package.json +++ b/package.json @@ -61,19 +61,13 @@ "syntax-error": "^1.4.0", "terminal-image": "^1.2.1", "translate-google-api": "^1.0.4", - "nodemon": "^2.0.7", "url-regex": "^5.0.0", "xmldom": "github:xmldom/xmldom#0.7.0", "warn": "^1.0.1", "yargs": "^16.2.0", "node-webpmux": "^2.0.3", + "wa-sticker-formatter": "4.0.3", "yt-search": "^2.7.6", "g-i-s": "^2.1.6" - }, - "nodemonConfig": { - "ignore": [ - "plugins/*", - "session.data.json" - ] } } diff --git a/plugins/sticker.js b/plugins/sticker.js index 4ce400bb4..29888d3fc 100644 --- a/plugins/sticker.js +++ b/plugins/sticker.js @@ -1,24 +1,44 @@ const { MessageType } = require('@adiwajshing/baileys') const { sticker } = require('../lib/sticker') -let handler = async (m, { conn, args }) => { +const uploadFile = require('../lib/uploadFile') +const uploadImage = require('../lib/uploadImage') +let { webp2png } = require('../lib/webp2mp4') +let handler = async (m, { conn, args, usedPrefix, command }) => { let stiker = false try { let q = m.quoted ? m.quoted : m let mime = (q.msg || q).mimetype || '' - if (/image|video/.test(mime)) { + if (/webp|image|video/g.test(mime)) { + if (/video/g.test(mime)) if ((q.msg || q).seconds > 11) return m.reply('Maksimal 10 detik!') let img = await q.download() - if (!img) throw 'Foto/Video tidak ditemukan' - stiker = await sticker(img, false, global.packname, global.author) - } else if (args[0]) stiker = await sticker(false, args[0], global.packname, global.author) + if (!img) throw `balas gambar/video/stiker dengan perintah ${usedPrefix + command}` + let out + try { + if (/webp/g.test(mime)) out = await webp2png(img) + else if (/image/g.test(mime)) out = await uploadImage(img) + else if (/video/g.test(mime)) out = await uploadFile(img) + stiker = await sticker(false, out, global.packname, global.author) + } catch (e) { + console.error(e) + stiker = await sticker(img, false, global.packname, global.author) + } + } else if (args[0]) { + if (isUrl(args[0])) stiker = await sticker(false, args[0], global.packname, global.author) + else return m.reply('URL tidak valid!') + } } finally { - if (stiker) conn.sendMessage(m.chat, stiker, MessageType.sticker, { + if (stiker) await conn.sendMessage(m.chat, stiker, MessageType.sticker, { quoted: m }) - else throw 'Conversion failed' + else throw `Gagal${m.isGroup ? ', balas gambarnya!' : ''}` } } -handler.help = ['stiker (caption|reply media)', 'stiker ', 'stikergif (caption|reply media)', 'stikergif '] +handler.help = ['stiker ', 'stiker '] handler.tags = ['sticker'] handler.command = /^s(tic?ker)?(gif)?(wm)?$/i module.exports = handler + +const isUrl = (text) => { + return text.match(new RegExp(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&/=]*)(jpe?g|gif|png)/, 'gi')) +} diff --git a/test2.js b/test2.js deleted file mode 100644 index 429784973..000000000 --- a/test2.js +++ /dev/null @@ -1,15 +0,0 @@ -var nodemon = require('nodemon') - -nodemon({ - script: 'index.js', - ext: 'js' -}) - -nodemon.on('start', function () { - console.log('App has started') -}).on('quit', function () { - console.log('App has quit') - process.exit() -}).on('restart', function (files) { - console.log('App restarted due to: ', files || '') -})