diff --git a/assets/fonts/KeepCalm-Medium.ttf b/assets/fonts/KeepCalm-Medium.ttf new file mode 100644 index 0000000..5b16cc5 Binary files /dev/null and b/assets/fonts/KeepCalm-Medium.ttf differ diff --git a/assets/fonts/LuckiestGuy-Regular.ttf b/assets/fonts/LuckiestGuy-Regular.ttf new file mode 100644 index 0000000..5ca663c Binary files /dev/null and b/assets/fonts/LuckiestGuy-Regular.ttf differ diff --git a/assets/fonts/SketchMatch.ttf b/assets/fonts/SketchMatch.ttf new file mode 100644 index 0000000..8cfb5f7 Binary files /dev/null and b/assets/fonts/SketchMatch.ttf differ diff --git a/assets/fonts/theboldfont.ttf b/assets/fonts/theboldfont.ttf new file mode 100644 index 0000000..2985b05 Binary files /dev/null and b/assets/fonts/theboldfont.ttf differ diff --git a/assets/img/1px.png b/assets/img/1px.png new file mode 100644 index 0000000..063be68 Binary files /dev/null and b/assets/img/1px.png differ diff --git a/assets/img/default-avatar.png b/assets/img/default-avatar.png new file mode 100644 index 0000000..e2dc1e4 Binary files /dev/null and b/assets/img/default-avatar.png differ diff --git a/command/help.js b/command/help.js index d7a285c..8da4ed2 100644 --- a/command/help.js +++ b/command/help.js @@ -4,12 +4,12 @@ module.exports = { name: 'help', aliases: ['h'], description: 'Menampilkan semua perintah dan deskripsi', - execute (client, from) { + execute (client) { const commands = client.cmd.array() let text = 'Command di bot ini\n\nPrefix: !\n' commands.forEach((cmd) => { text += `- *${cmd.name}* ${cmd.aliases ? `(${cmd.aliases})` : ''}\n${cmd.description}\n` }) - return client.sendMessage(from, text, MessageType.text) + return client.sendMessage(client.from, text, MessageType.text) } } diff --git a/command/ping.js b/command/ping.js index bef0542..24007fe 100644 --- a/command/ping.js +++ b/command/ping.js @@ -6,7 +6,7 @@ module.exports = { name: 'ping', cooldown: 10, description: 'Menampilkan rata-rata bot merespon', - execute (client, from) { - client.sendMessage(from, `Pong!!\n${processTime(client.pingStart, moment())} _detik_`, MessageType.text).catch(console.error) + execute (client) { + client.sendMessage(client.from, `Pong!!\n${processTime(client.pingStart, moment())} _detik_`, MessageType.text).catch(console.error) } } diff --git a/krypton.js b/krypton.js index 99a58c8..ee39d2a 100644 --- a/krypton.js +++ b/krypton.js @@ -8,6 +8,7 @@ const { start, success, getGroupAdmins, getBuffer } = require('./utils/functions const { color } = require('./utils/color') const fs = require('fs') const moment = require('moment-timezone') +const { welcome, goodbye } = require('./utils/greeting') async function krypton () { const client = new WAConnection() @@ -44,35 +45,37 @@ async function krypton () { await client.connect({ timeoutMs: 30 * 1000 }) fs.writeFileSync('./sessions/krypton-sessions.json', JSON.stringify(client.base64EncodedAuthInfo(), null, '\t')) - await client.on('group-participants-update', async (greeting) => { - try { - const mdata = await client.groupMetadata(greeting.jid) - console.log(greeting) - if (greeting.action == 'add') { - num = greeting.participants[0] - try { - ppimg = await client.getProfilePicture(`${greeting.participants[0].split('@')[0]}@c.us`) - } catch { - ppimg = 'https://i0.wp.com/www.gambarunik.id/wp-content/uploads/2019/06/Top-Gambar-Foto-Profil-Kosong-Lucu-Tergokil-.jpg' - } - teks = `Halo @${num.split('@')[0]}\nSelamat datang di group *${mdata.subject}*` - let buff = await getBuffer(ppimg) - client.sendMessage(mdata.id, buff, MessageType.image, {caption: teks, contextInfo: {"mentionedJid": [num]}}) - } else if (greeting.action == 'remove') { - num = greeting.participants[0] - try { - ppimg = await client.getProfilePicture(`${num.split('@')[0]}@c.us`) - } catch { - ppimg = 'https://i0.wp.com/www.gambarunik.id/wp-content/uploads/2019/06/Top-Gambar-Foto-Profil-Kosong-Lucu-Tergokil-.jpg' - } - teks = `Sayonara @${num.split('@')[0]}👋` - let buff = await getBuffer(ppimg) - client.sendMessage(mdata.id, buff, MessageType.image, {caption: teks, contextInfo: {"mentionedJid": [num]}}) - } - } catch (e) { - console.log('Error : %s', color(e, 'red')) - } - }) + await client.on('group-participants-update', async (greeting) => { + try { + const mdata = await client.groupMetadata(greeting.jid) + console.log(greeting) + if (greeting.action == 'add') { + num = greeting.participants[0] + try { + ppimg = await client.getProfilePicture(`${greeting.participants[0].split('@')[0]}@c.us`) + } catch { + ppimg = 'https://i0.wp.com/www.gambarunik.id/wp-content/uploads/2019/06/Top-Gambar-Foto-Profil-Kosong-Lucu-Tergokil-.jpg' + } + // teks = `Halo @${num.split('@')[0]}\nSelamat datang di group *${mdata.subject}*` + const buff = await getBuffer(ppimg) + await welcome('uwu', mdata.subject, buff).then(async (hasil) => { + await client.sendMessage(mdata.id, hasil, MessageType.image) + }) + } else if (greeting.action == 'remove') { + num = greeting.participants[0] + try { + ppimg = await client.getProfilePicture(`${num.split('@')[0]}@c.us`) + } catch { + ppimg = 'https://i0.wp.com/www.gambarunik.id/wp-content/uploads/2019/06/Top-Gambar-Foto-Profil-Kosong-Lucu-Tergokil-.jpg' + } + teks = `Sayonara @${num.split('@')[0]}👋` + const buff = await getBuffer(ppimg) + client.sendMessage(mdata.id, buff, MessageType.image, { caption: teks, contextInfo: { mentionedJid: [num] } }) + } + } catch (e) { + console.log('Error : %s', color(e, 'red')) + } + }) await client.on('chat-update', async (chat) => { client.pingStart = Date.now() @@ -84,7 +87,6 @@ async function krypton () { if (chat.key.fromMe) return // Variable - const from = chat.key.remoteJid const type = Object.keys(chat.message)[0] body = (type === 'conversation' && chat.message.conversation.startsWith(prefix)) ? chat.message.conversation : (type == 'imageMessage') && chat.message.imageMessage.caption.startsWith(prefix) ? chat.message.imageMessage.caption : (type == 'videoMessage') && chat.message.videoMessage.caption.startsWith(prefix) ? chat.message.videoMessage.caption : (type == 'extendedTextMessage') && chat.message.extendedTextMessage.text.startsWith(prefix) ? chat.message.extendedTextMessage.text : '' const args = body.trim().split(/ +/).slice(1) @@ -94,41 +96,43 @@ async function krypton () { const content = JSON.stringify(chat.message) const botNumber = client.user.jid - const ownerNumber = ["6285892766102@s.whatsapp.net"] // replace this with your number - const isGroup = from.endsWith('@g.us') - const sender = isGroup ? chat.participant : chat.key.remoteJid - const groupMetadata = isGroup ? await client.groupMetadata(from) : '' - const groupName = isGroup ? groupMetadata.subject : '' - const groupId = isGroup ? groupMetadata.jid : '' - const groupMembers = isGroup ? groupMetadata.participants : '' - const groupAdmins = isGroup ? getGroupAdmins(groupMembers) : '' - const isBotGroupAdmins = groupAdmins.includes(botNumber) || false - const isGroupAdmins = groupAdmins.includes(sender) || false - const isOwner = ownerNumber.includes(sender) - const isUrl = (url) => { - return url.match(new RegExp(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&/=]*)/, 'gi')) - } - const reply = (teks) => { - client.sendMessage(from, teks, text, {quoted:chat}) - } - const sendMess = (hehe, teks) => { - client.sendMessage(hehe, teks, text) - } - const mentions = (teks, memberr, id) => { - (id == null || id == undefined || id == false) ? client.sendMessage(from, teks.trim(), extendedText, {contextInfo: {"mentionedJid": memberr}}) : client.sendMessage(from, teks.trim(), extendedText, {quoted: chat, contextInfo: {"mentionedJid": memberr}}) - } - - colors = ['red','white','black','blue','yellow','green'] - const isMedia = (type === 'imageMessage' || type === 'videoMessage') - const isQuotedImage = type === 'extendedTextMessage' && content.includes('imageMessage') - const isQuotedVideo = type === 'extendedTextMessage' && content.includes('videoMessage') - const isQuotedSticker = type === 'extendedTextMessage' && content.includes('stickerMessage') + const ownerNumber = ['6285892766102@s.whatsapp.net'] // replace this with your number + const sender = client.isGroup ? chat.participant : chat.key.remoteJid + const groupMetadata = client.isGroup ? await client.groupMetadata(client.from) : '' + const groupName = client.isGroup ? groupMetadata.subject : '' + const groupMembers = client.isGroup ? groupMetadata.participants : '' + const groupAdmins = client.isGroup ? getGroupAdmins(groupMembers) : '' + client.from = chat.key.remoteJid + client.isGroup = client.from.endsWith('@g.us') + client.groupId = client.isGroup ? groupMetadata.jid : '' + client.isBotGroupAdmins = groupAdmins.includes(botNumber) || false + client.isGroupAdmins = groupAdmins.includes(sender) || false + client.isOwner = ownerNumber.includes(sender) + client.isUrl = (url) => { + // eslint-disable-next-line prefer-regex-literals + return url.match(new RegExp(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&/=]*)/, 'gi')) + } + client.reply = (teks) => { + client.sendMessage(client.from, teks, text, { quoted: chat }) + } + client.sendMess = (hehe, teks) => { + client.sendMessage(hehe, teks, text) + } + client.mentions = (teks, memberr, id) => { + (id == null || id == undefined || id == false) ? client.sendMessage(client.from, teks.trim(), extendedText, { contextInfo: { mentionedJid: memberr } }) : client.sendMessage(client.from, teks.trim(), extendedText, { quoted: chat, contextInfo: { mentionedJid: memberr } }) + } + + colors = ['red', 'white', 'black', 'blue', 'yellow', 'green'] + client.isMedia = (type === 'imageMessage' || type === 'videoMessage') + client.isQuotedImage = type === 'extendedTextMessage' && content.includes('imageMessage') + client.isQuotedVideo = type === 'extendedTextMessage' && content.includes('videoMessage') + client.isQuotedSticker = type === 'extendedTextMessage' && content.includes('stickerMessage') // Logging Message - if (!isGroup && isCmd) console.log('\x1b[1;31m~\x1b[1;37m>', '[\x1b[1;32mEXEC\x1b[1;37m]', time, color(commandName), 'from', color(sender.split('@')[0]), 'args :', color(args.length)) - if (!isGroup && !isCmd) console.log('\x1b[1;31m~\x1b[1;37m>', '[\x1b[1;31mRECV\x1b[1;37m]', time, color('Message'), 'from', color(sender.split('@')[0]), 'args :', color(args.length)) - if (isCmd && isGroup) console.log('\x1b[1;31m~\x1b[1;37m>', '[\x1b[1;32mEXEC\x1b[1;37m]', time, color(commandName), 'from', color(sender.split('@')[0]), 'in', color(groupName), 'args :', color(args.length)) - if (!isCmd && isGroup) console.log('\x1b[1;31m~\x1b[1;37m>', '[\x1b[1;31mRECV\x1b[1;37m]', time, color('Message'), 'from', color(sender.split('@')[0]), 'in', color(groupName), 'args :', color(args.length)) + if (!client.isGroup && isCmd) console.log('\x1b[1;31m~\x1b[1;37m>', '[\x1b[1;32mEXEC\x1b[1;37m]', time, color(commandName), 'client.from', color(sender.split('@')[0]), 'args :', color(args.length)) + if (!client.isGroup && !isCmd) console.log('\x1b[1;31m~\x1b[1;37m>', '[\x1b[1;31mRECV\x1b[1;37m]', time, color('Message'), 'client.from', color(sender.split('@')[0]), 'args :', color(args.length)) + if (isCmd && client.isGroup) console.log('\x1b[1;31m~\x1b[1;37m>', '[\x1b[1;32mEXEC\x1b[1;37m]', time, color(commandName), 'client.from', color(sender.split('@')[0]), 'in', color(groupName), 'args :', color(args.length)) + if (!isCmd && client.isGroup) console.log('\x1b[1;31m~\x1b[1;37m>', '[\x1b[1;31mRECV\x1b[1;37m]', time, color('Message'), 'client.from', color(sender.split('@')[0]), 'in', color(groupName), 'args :', color(args.length)) /** * Import all commands @@ -155,26 +159,26 @@ async function krypton () { const timestamps = cooldowns.get(command.name) const cooldownAmount = (command.cooldown || 1) * 1000 - if (timestamps.has(from)) { - const expirationTime = timestamps.get(from) + cooldownAmount + if (timestamps.has(client.from)) { + const expirationTime = timestamps.get(client.from) + cooldownAmount if (now < expirationTime) { const timeLeft = (expirationTime - now) / 1000 - return client.sendMessage(from, + return client.sendMessage(client.from, `Mohon tunggu lebih dari ${timeLeft.toFixed(1)} detik sebelum menggunakan perintah ini *${command.name}*.`, MessageType.text ) } } - timestamps.set(from, now) - setTimeout(() => timestamps.delete(from), cooldownAmount) + timestamps.set(client.from, now) + setTimeout(() => timestamps.delete(client.from), cooldownAmount) try { - command.execute(client, from, args) + command.execute(client, args) } catch (error) { console.error(error) - client.sendMessage(from, 'Telah terjadi error setelah menggunakan command ini.', MessageType.text).catch(console.error) + client.sendMessage(client.from, 'Telah terjadi error setelah menggunakan command ini.', MessageType.text).catch(console.error) } }) } diff --git a/package.json b/package.json index 815dc02..8043cbd 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,8 @@ "discord.js": "^12.5.1", "auto-changelog": "^2.2.1", "moment-timezone": "^0.5.32", - "axios": "^0.21.1" + "axios": "^0.21.1", + "canvas": "^2.6.1" }, "devDependencies": { "babel-eslint": "^10.1.0", diff --git a/sessions/krypton-sessions.json b/sessions/krypton-sessions.json index 11502b1..94afe70 100644 --- a/sessions/krypton-sessions.json +++ b/sessions/krypton-sessions.json @@ -1,7 +1,7 @@ { "clientID": "GKLkqJPLYevrdohE3aqyLw==", - "serverToken": "1@WxZP0VHxcykw4RJn8n0t2Uwcon5mN+geQYFh7afidl6NbYTPPg8oiWpcivEGRutU09R3y1SuaX2RHA==", - "clientToken": "jpvlOk7NZFZavIKJW8dce8fnKX8tsxFpOaqUikeXRxE=", + "serverToken": "1@7qS+bLikkKOuJNzAq80o1HeDbKbKVtFmGNaJQiiXh1FsP3tl0GRkD1vU7PXw03szDdVEXJ8RZJRBAw==", + "clientToken": "hN8cvVxXGTv4s6OGhvQ0HN1NgSY/qngMrrNXL1kdVvw=", "encKey": "XmgE05UerNZpLDE2RFvE8/E4jnAkN+DGhib2P1R/gQY=", "macKey": "ruFSFvGXjPPEfH00mvd6sYSJIEuAz1OPB5kK0x1c/Vo=" } \ No newline at end of file diff --git a/utils/greeting.js b/utils/greeting.js new file mode 100644 index 0000000..53e4bc3 --- /dev/null +++ b/utils/greeting.js @@ -0,0 +1,136 @@ +const Canvas = require('canvas') +const path = require('path') +const { applyText } = require('../utils') + +// Font +// Register Bold font +Canvas.registerFont(path.join(__dirname, '/../assets/fonts/theboldfont.ttf'), { family: 'Bold' }) +// Register SketchMatch font +Canvas.registerFont(path.join(__dirname, '/../assets/fonts/SketchMatch.ttf'), { family: 'SketchMatch' }) +// Register SketchMatch font +Canvas.registerFont(path.join(__dirname, '/../assets/fonts/LuckiestGuy-Regular.ttf'), { family: 'luckiest guy' }) +// Register KeepCalm font +Canvas.registerFont(path.join(__dirname, '/../assets/fonts/KeepCalm-Medium.ttf'), { family: 'KeepCalm' }) + +const welcome = (pushname, gcname, picprofil) => new Promise((resolve, reject) => { + // Create canvas + const canvas = Canvas.createCanvas(1024, 450) + const ctx = canvas.getContext('2d') + + const gcName = `Welcome in ${gcname}` + + // Draw background + ctx.fillStyle = '000000' + ctx.fillRect(0, 0, canvas.width, canvas.height) + const background = Canvas.loadImage(path.join(__dirname, '/../assets/img/1px.png')) + ctx.drawImage(background, 0, 0, canvas.width, canvas.height) + + // Draw layer + ctx.fillStyle = '#000000' + ctx.globalAlpha = '0.4' + ctx.fillRect(0, 0, 25, canvas.height) + ctx.fillRect(canvas.width - 25, 0, 25, canvas.height) + ctx.fillRect(25, 0, canvas.width - 50, 25) + ctx.fillRect(25, canvas.height - 25, canvas.width - 50, 25) + ctx.fillStyle = '#000000' + ctx.globalAlpha = '0.4' + ctx.fillRect(344, canvas.height - 296, 625, 65) + ctx.fillRect(308, canvas.height - 160, 672, 65) + + // Draw username + ctx.globalAlpha = 1 + ctx.fillStyle = '#ffffff' + ctx.font = applyText(canvas, pushname, 48, 600, 'Bold') + ctx.fillText(pushname, canvas.width - 660, canvas.height - 248) + + // Draw guild name + ctx.fillStyle = '#ffffff' + ctx.font = applyText(canvas, gcName, 53, 600, 'Bold') + ctx.fillText(gcName, canvas.width - 690, canvas.height - 110) + + // Draw title + ctx.font = '90px Bold' + ctx.strokeStyle = '#000000' + ctx.lineWidth = 15 + ctx.strokeText('WELCOME', canvas.width - 620, canvas.height - 330) + ctx.fillStyle = '#df0909' + ctx.fillText('WELCOME', canvas.width - 620, canvas.height - 330) + + // Draw avatar circle + ctx.beginPath() + ctx.lineWidth = 10 + ctx.arc(180, 225, 135, 0, Math.PI * 2, true) + ctx.stroke() + ctx.closePath() + ctx.clip() + const avatar = Canvas.loadImage(picprofil) + ctx.drawImage(avatar, 45, 90, 270, 270) + + const buff = canvas.toBuffer() + const base64 = `data:image/png;base64,${buff.toString('base64')}` + resolve(base64) +}) + +const goodbye = (pushname, gcname, picprofil) => new Promise((resolve, reject) => { + // Create canvas + const canvas = Canvas.createCanvas(1024, 450) + const ctx = canvas.getContext('2d') + + const gcName = `Leaving from ${gcname}` + + // Draw background + ctx.fillStyle = '000000' + ctx.fillRect(0, 0, canvas.width, canvas.height) + const background = Canvas.loadImage(path.join(__dirname, '/../assets/img/1px.png')) + ctx.drawImage(background, 0, 0, canvas.width, canvas.height) + + // Draw layer + ctx.fillStyle = '#000000' + ctx.globalAlpha = '0.4' + ctx.fillRect(0, 0, 25, canvas.height) + ctx.fillRect(canvas.width - 25, 0, 25, canvas.height) + ctx.fillRect(25, 0, canvas.width - 50, 25) + ctx.fillRect(25, canvas.height - 25, canvas.width - 50, 25) + ctx.fillStyle = '#000000' + ctx.globalAlpha = '0.4' + ctx.fillRect(344, canvas.height - 296, 625, 65) + ctx.fillRect(308, canvas.height - 160, 672, 65) + + // Draw username + ctx.globalAlpha = 1 + ctx.fillStyle = '#ffffff' + ctx.font = applyText(canvas, pushname, 48, 600, 'Bold') + ctx.fillText(pushname, canvas.width - 660, canvas.height - 248) + + // Draw guild name + ctx.fillStyle = '#ffffff' + ctx.font = applyText(canvas, gcName, 53, 600, 'Bold') + ctx.fillText(gcName, canvas.width - 690, canvas.height - 110) + + // Draw title + ctx.font = '90px Bold' + ctx.strokeStyle = '#000000' + ctx.lineWidth = 15 + ctx.strokeText('GOODBYE', canvas.width - 620, canvas.height - 330) + ctx.fillStyle = '#df0909' + ctx.fillText('GOODBYE', canvas.width - 620, canvas.height - 330) + + // Draw avatar circle + ctx.beginPath() + ctx.lineWidth = 10 + ctx.arc(180, 225, 135, 0, Math.PI * 2, true) + ctx.stroke() + ctx.closePath() + ctx.clip() + const avatar = Canvas.loadImage(picprofil) + ctx.drawImage(avatar, 45, 90, 270, 270) + + const buff = canvas.toBuffer() + const base64 = `data:image/png;base64,${buff.toString('base64')}` + resolve(base64) +}) + +module.exports = { + welcome, + goodbye +}