Skip to content

Commit

Permalink
Fix sticker? (#76)
Browse files Browse the repository at this point in the history
* Delete nodemon module

* Update sticker.js
  • Loading branch information
BochilGaming authored Sep 1, 2021
1 parent e85b8a8 commit 0136fbf
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 35 deletions.
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.

0 comments on commit 0136fbf

Please sign in to comment.