Skip to content

Commit

Permalink
move to indonesian language and make method ping
Browse files Browse the repository at this point in the history
  • Loading branch information
Kry9toN committed Jan 16, 2021
1 parent 47ea7b8 commit 9473942
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# KryPtoN Whatsapp Bot
[![DeepScan grade](https://deepscan.io/api/teams/11540/projects/14446/branches/269535/badge/grade.svg)](https://deepscan.io/dashboard#view=project&tid=11540&pid=14446&bid=269535)
[![Version](https://img.shields.io/badge/version%20K--wa%20Bot-v2.8.8-brightgreen)](https://github.com/Kry9toN/KryPtoN-WhatsApp-Bot/releases)
[![Version](https://img.shields.io/badge/version%20K--wa%20Bot-v0.0.1-brightgreen)](https://github.com/Kry9toN/KryPtoN-WhatsApp-Bot/releases)

<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-2-orange.svg?style=flat-square)](#contributors-)
Expand Down
2 changes: 1 addition & 1 deletion command/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { MessageType } = require('@adiwajshing/baileys')
module.exports = {
name: 'help',
aliases: ['h'],
description: 'Display all commands and descriptions',
description: 'Menampilkan semua perintah dan deskripsi',
execute (client, from) {
const commands = client.cmd.array()
let text = 'Command di bot ini\n\nPrefix: !\n'
Expand Down
6 changes: 4 additions & 2 deletions command/ping.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
const { MessageType } = require('@adiwajshing/baileys')
const moment = require('moment-timezone')
const { processTime } = require('../utils/functions')

module.exports = {
name: 'ping',
cooldown: 10,
description: "Show the bot's average ping",
description: 'Menampilkan rata-rata bot merespon',
execute (client, from) {
client.sendMessage(from, 'oe', MessageType.text).catch(console.error)
client.sendMessage(from, `Pong!!\n${processTime(client.pingStart, moment())} _detik_`, MessageType.text).catch(console.error)
}
}
17 changes: 10 additions & 7 deletions krypton.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,34 @@ async function krypton () {
if (fs.existsSync('./sessions/krypton-sessions.json')) {
await client.loadAuthInfo('./sessions/krypton-sessions.json')
await client.on('connecting', () => {
start('1', ' [SERVER] Connecting to exist sessions...')
start('1', '[SERVER] Menyambungkan ke sessions yang sudah ada...')
})
}

// Server connecting
if (!fs.existsSync('./sessions/krypton-sessions.json')) {
await client.on('connecting', () => {
start('1', ' [SERVER] Waitting scan QR to connecting...')
start('1', '[SERVER] Menunggu scan code QR untuk menyambungkan...')
})
}

// Server connected
await client.on('open', () => {
success('1', ' [SERVER] Connected')
success('1', '[SERVER] Terhubung')
console.log('🤖',color('KryPtoN Bot Sudah siap!!', 'green'))
})

// Create file for sessions
await client.connect({ timeoutMs: 30 * 1000 })
fs.writeFileSync('./sessions/krypton-sessions.json', JSON.stringify(client.base64EncodedAuthInfo(), null, '\t'))

await client.on('chat-update', async (chat) => {
client.pingStart = Date.now()
if (!chat.hasNewMessage) return
const prefix = '!'
chat = JSON.parse(JSON.stringify(chat)).messages[0]
if (!chat.message) return
if (chat.key && chat.key.remoteJid == 'status@broadcast') return
if (chat.key.remoteJid == 'status@broadcast') return
if (chat.key.fromMe) return
const from = chat.key.remoteJid
const type = Object.keys(chat.message)[0]
Expand Down Expand Up @@ -86,8 +88,9 @@ async function krypton () {

if (now < expirationTime) {
const timeLeft = (expirationTime - now) / 1000
return message.reply(
`please wait ${timeLeft.toFixed(1)} more second(s) before reusing the \`${command.name}\` command.`
return client.sendMessage(from,
`Mohon tunggu lebih dari ${timeLeft.toFixed(1)} detik sebelum menggunakan perintah ini *${command.name}*.`,
MessageType.text
)
}
}
Expand All @@ -99,7 +102,7 @@ async function krypton () {
command.execute(client, from, args)
} catch (error) {
console.error(error)
client.sendMessage(from, 'There was an error executing that command.', MessageType.text).catch(console.error)
client.sendMessage(from, 'Telah terjadi error setelah menggunakan command ini.', MessageType.text).catch(console.error)
}
})
}
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
"@adiwajshing/baileys": "^3.4.1",
"spinnies": "^0.5.1",
"chalk": "^4.1.0",
"discord.js": "^12.5.1"
"discord.js": "^12.5.1",
"auto-changelog": "^2.2.1",
"moment-timezone": "^0.5.32"
},
"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@BbuGj/99Mi5JiKtNvNNgJXHXByq/ZDSXQLm0CY9MDSpw7egHszko3A7QAPLjZ3cfK2iF1bWcSbafiQ==",
"clientToken": "cv9PgK6hyyCYOzuOqF5Ts5HXkOpevS2ItX4Qf7M6API=",
"serverToken": "1@QL4rgcQ89akLLPCYg86qxTB8W/FBcnyB9vUEAkPs/FiKCFKf3JaXzFTc6B9ZpWGuOcisR+YGk5GEnw==",
"clientToken": "zYkyJ4MFUHP9wz5ODkIdqVLKi0wrPAIPhe1rm9KmycQ=",
"encKey": "XmgE05UerNZpLDE2RFvE8/E4jnAkN+DGhib2P1R/gQY=",
"macKey": "ruFSFvGXjPPEfH00mvd6sYSJIEuAz1OPB5kK0x1c/Vo="
}
14 changes: 13 additions & 1 deletion utils/functions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const Spin = require('spinnies')
const moment = require('moment-timezone')

const spinner = {
interval: 120,
Expand Down Expand Up @@ -35,7 +36,18 @@ const success = (id, text) => {
spins.succeed(id, { text: text })
}

/**
* Get Time duration
* @param {Date} timestamp
* @param {Date} now
*/
const processTime = (timestamp, now) => {
// timestamp => timestamp when message was received
return moment.duration(now - moment(timestamp)).asSeconds()
}

module.exports = {
start,
success
success,
processTime
}

0 comments on commit 9473942

Please sign in to comment.