Skip to content

Commit

Permalink
initial greeting
Browse files Browse the repository at this point in the history
  • Loading branch information
Kry9toN committed Jan 17, 2021
1 parent 092bb88 commit 536f58a
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 5 deletions.
32 changes: 31 additions & 1 deletion 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 } = require('./utils/functions')
const { start, success, getGroupAdmins, getBuffer } = require('./utils/functions')
const { color } = require('./utils/color')
const fs = require('fs')
const moment = require('moment-timezone')
Expand Down Expand Up @@ -44,6 +44,36 @@ 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('chat-update', async (chat) => {
client.pingStart = Date.now()
if (!chat.hasNewMessage) return
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"chalk": "^4.1.0",
"discord.js": "^12.5.1",
"auto-changelog": "^2.2.1",
"moment-timezone": "^0.5.32"
"moment-timezone": "^0.5.32",
"axios": "^0.21.1"
},
"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@QL4rgcQ89akLLPCYg86qxTB8W/FBcnyB9vUEAkPs/FiKCFKf3JaXzFTc6B9ZpWGuOcisR+YGk5GEnw==",
"clientToken": "zYkyJ4MFUHP9wz5ODkIdqVLKi0wrPAIPhe1rm9KmycQ=",
"serverToken": "1@WxZP0VHxcykw4RJn8n0t2Uwcon5mN+geQYFh7afidl6NbYTPPg8oiWpcivEGRutU09R3y1SuaX2RHA==",
"clientToken": "jpvlOk7NZFZavIKJW8dce8fnKX8tsxFpOaqUikeXRxE=",
"encKey": "XmgE05UerNZpLDE2RFvE8/E4jnAkN+DGhib2P1R/gQY=",
"macKey": "ruFSFvGXjPPEfH00mvd6sYSJIEuAz1OPB5kK0x1c/Vo="
}
23 changes: 22 additions & 1 deletion utils/functions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const Spin = require('spinnies')
const moment = require('moment-timezone')
const axios = require('axios')

const spinner = {
interval: 120,
Expand Down Expand Up @@ -54,9 +55,29 @@ 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
getGroupAdmins,
getBuffer
}

0 comments on commit 536f58a

Please sign in to comment.