Skip to content

Commit

Permalink
fix sticker and cooldown only not premium
Browse files Browse the repository at this point in the history
  • Loading branch information
Kry9toN committed Jan 21, 2021
1 parent f807b2c commit 6f81a4f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
48 changes: 29 additions & 19 deletions command/sticker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable no-mixed-operators */
const { MessageType } = require('@adiwajshing/baileys')
const { exec } = require('child_process')
const { getRandom } = require('../utils/functions')
const ffmpeg = require('fluent-ffmpeg')
Expand All @@ -7,57 +8,66 @@ const fs = require('fs')
module.exports = {
name: 'sticker',
aliases: ['s', 'st'],
cooldown: 600,
description: 'Untuk menyimpan note atau catatan di group\nPenggunaan: !notes <save/remove> <key> <value>',
async execute (client, chat, pesan, args) {
if (!client.isPmium && !client.isOwner) return client.reply(pesan.error.premium)
const encmedia = client.isQuotedImage ? JSON.parse(JSON.stringify(chat).replace('quotedM', 'm')).message.extendedTextMessage.contextInfo : chat
const media = await client.downloadAndSaveMediaMessage(encmedia)
ranw = getRandom('.webp')
ranp = getRandom('.png')
if ((client.isMedia && !chat.message.videoMessage || client.isQuotedImage) && args.length == 0) {
const encmedia = client.isQuotedImage ? JSON.parse(JSON.stringify(chat).replace('quotedM','m')).message.extendedTextMessage.contextInfo : chat
const media = await client.downloadAndSaveMediaMessage(encmedia)
ranw = getRandom('.webp')
client.reply(pesan.tunggu)
await ffmpeg(`./${media}`)
.input(media)
.on('start', function (cmd) {
console.log(`Started : ${cmd}`)
console.log(`[SERVER] Started : ${cmd}`)
})
.on('error', function (err) {
console.log(`Error : ${err}`)
console.log(`[SERVER] Error : ${err}`)
fs.unlinkSync(media)
client.reply(mess.error.stick)
client.reply('Error saat membuat sticker')
})
.on('end', function () {
console.log('Finish')
client.sendMessage(client.from, fs.readFileSync(ranw), sticker, { quoted: chat })
console.log('[SERVER] Berhasil membuat sticker')
client.sendMessage(client.from, fs.readFileSync(ranw), MessageType.sticker, { quoted: chat })
fs.unlinkSync(media)
fs.unlinkSync(ranw)
})
.addOutputOptions(['-vcodec', 'libwebp', '-vf', 'scale=\'min(320,iw)\':min\'(320,ih)\':force_original_aspect_ratio=decrease,fps=15, pad=320:320:-1:-1:[email protected], split [a][b]; [a] palettegen=reserve_transparent=on:transparency_color=ffffff [p]; [b][p] paletteuse'])
.toFormat('webp')
.save(ranw)
} else if ((client.isMedia && chat.message.videoMessage.seconds < 11 || client.isQuotedVideo && chat.message.extendedTextMessage.contextInfo.quotedMessage.videoMessage.seconds < 11) && args.length == 0) {
client.reply(mess.wait)
if (!client.isPmium && !client.isOwner) return client.reply(pesan.error.premium)
const encmedia = client.isQuotedVideo ? JSON.parse(JSON.stringify(chat).replace('quotedM','m')).message.extendedTextMessage.contextInfo : chat
const media = await client.downloadAndSaveMediaMessage(encmedia)
ranw = getRandom('.webp')
client.reply(pesan.tunggu)
await ffmpeg(`./${media}`)
.inputFormat(media.split('.')[1])
.on('start', function (cmd) {
console.log(`Started : ${cmd}`)
console.log(`[SERVER] Started : ${cmd}`)
})
.on('error', function (err) {
console.log(`Error : ${err}`)
console.log(`[SERVER] Error : ${err}`)
fs.unlinkSync(media)
tipe = media.endsWith('.mp4') ? 'video' : 'gif'
client.reply(`❌ Gagal, pada saat mengkonversi ${tipe} ke stiker`)
})
.on('end', function () {
console.log('Finish')
client.sendMessage(client.from, fs.readFileSync(ranw), sticker, { quoted: chat })
console.log('[SERVER] Berhasil membuat sticker')
client.sendMessage(client.from, fs.readFileSync(ranw), MessageType.sticker, { quoted: chat })
fs.unlinkSync(media)
fs.unlinkSync(ranw)
})
.addOutputOptions(['-vcodec', 'libwebp', '-vf', 'scale=\'min(320,iw)\':min\'(320,ih)\':force_original_aspect_ratio=decrease,fps=15, pad=320:320:-1:-1:[email protected], split [a][b]; [a] palettegen=reserve_transparent=on:transparency_color=ffffff [p]; [b][p] paletteuse'])
.toFormat('webp')
.save(ranw)
} else if ((client.isMedia || client.isQuotedImage) && args[0] == 'nobg') {
client.reply(mess.wait)
if (!client.isPmium && !client.isOwner) return client.reply(pesan.error.premium)
const encmedia = client.isQuotedImage ? JSON.parse(JSON.stringify(chat).replace('quotedM','m')).message.extendedTextMessage.contextInfo : chat
const media = await client.downloadAndSaveMediaMessage(encmedia)
ranw = getRandom('.webp')
ranp = getRandom('.png')
client.reply(pesan.tunggu)
keyrmbg = process.env.KEY_REMOVEBG
await removeBackgroundclient.fromImageFile({ path: media, apiKey: keyrmbg.result, size: 'auto', type: 'auto', ranp }).then(res => {
fs.unlinkSync(media)
Expand All @@ -67,8 +77,8 @@ module.exports = {
})
exec(`ffmpeg -i ${ranp} -vcodec libwebp -filter:v fps=fps=20 -lossless 1 -loop 0 -preset default -an -vsync 0 -s 512:512 ${ranw}`, (err) => {
fs.unlinkSync(ranp)
if (err) return client.reply(mess.error.stick)
client.sendMessage(client.from, fs.readFileSync(ranw), sticker, { quoted: chat })
if (err) return client.reply('Error saat membuat sticker')
client.sendMessage(client.from, fs.readFileSync(ranw), MessageType.sticker, { quoted: chat })
})
})
/* } else if ((client.isMedia || client.isQuotedImage) && colors.includes(args[0])) {
Expand All @@ -83,7 +93,7 @@ module.exports = {
.on('end', function () {
console.log('Finish')
fs.unlinkSync(media)
client.sendMessage(client.from, fs.readFileSync(ran), sticker, {quoted: chat})
client.sendMessage(client.from, fs.readFileSync(ran), MessageType.sticker, {quoted: chat})
fs.unlinkSync(ran)
})
.addOutputOptions([`-vcodec`,`libwebp`,`-vf`,`scale='min(320,iw)':min'(320,ih)':force_original_aspect_ratio=decrease,fps=15, pad=320:320:-1:-1:color=${args[0]}@0.0, split [a][b]; [a] palettegen=reserve_transparent=off; [b][p] paletteuse`])
Expand Down
2 changes: 2 additions & 0 deletions krypton.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ async function krypton () {
}

// Time durations
if (!client.isPmium || !client.isGmium) {
const now = Date.now()
const timestamps = cooldowns.get(command.name)
const cooldownAmount = (command.cooldown || 1) * 1000
Expand All @@ -189,6 +190,7 @@ async function krypton () {

timestamps.set(client.from, now)
setTimeout(() => timestamps.delete(client.from), cooldownAmount)
}

try {
command.execute(client, chat, pesan, args)
Expand Down

0 comments on commit 6f81a4f

Please sign in to comment.