Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sticker? #76

Merged
merged 7 commits into from
Sep 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions lib/sticker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
/**
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -182,6 +193,7 @@ module.exports = {
sticker2,
sticker3,
sticker4,
sticker5,
addExif,
support: {
ffmpeg: true,
Expand All @@ -191,4 +203,4 @@ module.exports = {
magick: false,
gm: false,
},
}
}
3 changes: 0 additions & 3 deletions nodemon.json

This file was deleted.

8 changes: 1 addition & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
}
36 changes: 28 additions & 8 deletions plugins/sticker.js
Original file line number Diff line number Diff line change
@@ -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 <url>', 'stikergif (caption|reply media)', 'stikergif <url>']
handler.help = ['stiker ', 'stiker <url>']
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'))
}
15 changes: 0 additions & 15 deletions test2.js

This file was deleted.