Skip to content

Commit

Permalink
fix welcome image and improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Kry9toN committed Jan 17, 2021
1 parent ce6c76d commit ca5137f
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 168 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ RUN apt-get update \
&& apt-get install wget gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 \
libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 \
libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 \
libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 python3 \
libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 python3 libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev \
ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget ffmpeg --yes --fix-missing --no-install-recommends\
&& wget --no-check-certificate https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb \
&& dpkg -i google-chrome-stable_current_amd64.deb || apt -y -f install \
Expand Down
31 changes: 11 additions & 20 deletions krypton.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const {
const { Collection } = require('discord.js')
const { readdirSync } = require('fs')
const { join } = require('path')
const { start, success, getGroupAdmins, getBuffer } = require('./utils/functions')
const { start, success, getGroupAdmins } = require('./utils/functions')
const { color } = require('./utils/color')
const fs = require('fs')
const moment = require('moment-timezone')
Expand Down Expand Up @@ -48,29 +48,20 @@ async function krypton () {
await client.on('group-participants-update', async (greeting) => {
try {
const mdata = await client.groupMetadata(greeting.jid)
console.log(greeting)
if (greeting.action == 'add') {
console.log(console.log('\x1b[1;31m~\x1b[1;37m>', '[\x1b[1;32mEXEC\x1b[1;37m]', time, 'client', color(greeting.participants[0].split('@')[0]), 'Masuk ke group', color(mdata.subject))
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) => {
ppimg = await client.getProfilePicture(`${greeting.participants[0].split('@')[0]}@c.us`)
await welcome('uwu', mdata.subject, ppimg).then(async (hasil) => {
await client.sendMessage(mdata.id, hasil, MessageType.image)
})
} else if (greeting.action == 'remove') {
console.log(console.log('\x1b[1;31m~\x1b[1;37m>', '[\x1b[1;32mEXEC\x1b[1;37m]', time, 'client', color(greeting.participants[0].split('@')[0]), 'Keluar dari group', color(mdata.subject))
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] } })
ppimg = await client.getProfilePicture(`${num.split('@')[0]}@c.us`)
await goodbye('uwu', mdata.subject, ppimg).then(async (hasil) => {
await client.sendMessage(mdata.id, hasil, MessageType.image)
})
}
} catch (e) {
console.log('Error : %s', color(e, 'red'))
Expand Down Expand Up @@ -176,8 +167,8 @@ async function krypton () {

try {
command.execute(client, args)
} catch (error) {
console.error(error)
} catch (e) {
console.log('Error : %s', color(e, 'red'))
client.sendMessage(client.from, 'Telah terjadi error setelah menggunakan command ini.', MessageType.text).catch(console.error)
}
})
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"auto-changelog": "^2.2.1",
"moment-timezone": "^0.5.32",
"axios": "^0.21.1",
"canvas": "^2.6.1"
"wa-canvas": "git+https://github.com/Kry9toN/wa-canvas.git"
},
"devDependencies": {
"babel-eslint": "^10.1.0",
Expand Down
4 changes: 2 additions & 2 deletions sessions/krypton-sessions.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"clientID": "GKLkqJPLYevrdohE3aqyLw==",
"serverToken": "1@7qS+bLikkKOuJNzAq80o1HeDbKbKVtFmGNaJQiiXh1FsP3tl0GRkD1vU7PXw03szDdVEXJ8RZJRBAw==",
"clientToken": "hN8cvVxXGTv4s6OGhvQ0HN1NgSY/qngMrrNXL1kdVvw=",
"serverToken": "1@gMJSi8aUaJeIQNEfTDUSNT1rGsV0osC0fJ3KrfNfZTksPapqxpWxVvzYJMq12CW8WrAkfRaZdpHE7Q==",
"clientToken": "8nbOWyiIu0jRtjx5RW9YTo7zD658mla+oYzaVz6sYYQ=",
"encKey": "XmgE05UerNZpLDE2RFvE8/E4jnAkN+DGhib2P1R/gQY=",
"macKey": "ruFSFvGXjPPEfH00mvd6sYSJIEuAz1OPB5kK0x1c/Vo="
}
22 changes: 1 addition & 21 deletions utils/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,29 +55,9 @@ const getGroupAdmins = (participants) => {
return admins
}

const getBuffer = async (url, options) => {
try {
options ? options : {}
const res = await axios({
method: "get",
url,
headers: {
'DNT': 1,
'Upgrade-Insecure-Request': 1
},
...options,
responseType: 'arraybuffer'
})
return res.data
} catch (e) {
console.log(`Error : ${e}`)
}
}

module.exports = {
start,
success,
processTime,
getGroupAdmins,
getBuffer
getGroupAdmins
}
160 changes: 37 additions & 123 deletions utils/greeting.js
Original file line number Diff line number Diff line change
@@ -1,133 +1,47 @@
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 Canvas = require('wa-canvas')

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()
async function welcome () {
const image = await new Canvas.Welcome()
.setUsername(pushname)
.setGuildName(gcname)
.setAvatar(picprofil)
.setColor("border", "#8015EA")
.setColor("username-box", "#8015EA")
.setColor("message-box", "#8015EA")
.setColor("title", "#8015EA")
.setColor("avatar", "#8015EA")
.toAttachment();

const buff = image.toBuffer()
const base64 = `data:image/png;base64,${buff.toString('base64')}`
resolve(base64)
return base64
}
welcome().then((hasil) => resolve(hasil)).catch((err) => {
reject(err)
})
})

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()
async function goodbye () {
const image = await new Canvas.Goodbye()
.setUsername(pushname)
.setGuildName(gcname)
.setAvatar(picprofil)
.setColor("border", "#8015EA")
.setColor("username-box", "#8015EA")
.setColor("message-box", "#8015EA")
.setColor("title", "#8015EA")
.setColor("avatar", "#8015EA")
.toAttachment();

const buff = image.toBuffer()
const base64 = `data:image/png;base64,${buff.toString('base64')}`
resolve(base64)
return base64
}
goodbye().then((hasil) => resolve(hasil)).catch((err) => {
reject(err)
})
})

module.exports = {
Expand Down

0 comments on commit ca5137f

Please sign in to comment.