Skip to content

Commit

Permalink
add notes
Browse files Browse the repository at this point in the history
  • Loading branch information
Kry9toN committed Jan 20, 2021
1 parent b84e10e commit 0eb6234
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
38 changes: 38 additions & 0 deletions command/notes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const { databaseView, databaseInput } = require('../utils/db')

module.exports = {
name: 'notes',
aliases: ['nt'],
description: 'Untuk menyimpan note atau catatan di group\nPenggunaan: !notes <save/remove> <key> <value>',
async execute (client, chat, pesan, args) {
if (!client.isGroup) return client.reply(pesan.error.group)
if (!client.isGmium) return client.reply(pesan.error.premium)
if (!client.isGroupAdmins) return client.reply(pesan.hanya.admin)
if (!client.isBotGroupAdmins) return client.reply(pesan.hanya.botAdmin)
const key = args[1]
const res = args[2]
if (args == 0) {
await databaseView('SELECT * FROM notes')
.then((hasil) => {
let text = 'Daftar *notes* di group ini\n\n'
if (hasil.length > 0) {
for (const list of hasil) {
if (list.gid == client.groupId) {
text += `- *${list.key}*`
}
}
client.reply(text)
} else {
text += '_Belum ada notes_'
client.reply(text)
}
})
} else if (args > 0 && args[0] == 'save') {
databaseInput(`INSERT INTO notes(gid, key, res) VALUES ('${client.groupId}', '#${key}', '${res}')`)
.then(() => client.reply('Berhasil menambahkan notes'))
} else if (args > 0 && args[0] == 'remove') {
databaseInput(`DELETE FROM notes WHERE key = ${key} AND gid = ${client.groupId}`)
.then(() => client.reply(`Berhasil menghapus notes #${key}`))
}
}
}
16 changes: 13 additions & 3 deletions krypton.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const fs = require('fs')
const moment = require('moment-timezone')
const { welcome, goodbye } = require('./utils/greeting')
const time = moment.tz('Asia/Jakarta').format('DD/MM HH:mm:ss')
const { databaseView } = require('./utils/db')

async function krypton () {
const client = new WAConnection()
Expand Down Expand Up @@ -86,7 +87,6 @@ async function krypton () {
const isCmd = client.body.startsWith(prefix)
const commandName = client.body.slice(1).trim().split(/ +/).shift().toLowerCase()
const content = JSON.stringify(chat.message)

const botNumber = client.user.jid
const ownerNumber = process.env.OWNER_PHONE // Isi di .env
client.from = chat.key.remoteJid
Expand Down Expand Up @@ -115,12 +115,20 @@ async function krypton () {
(bolean == null || bolean == undefined || bolean == false) ? client.sendMessage(client.from, teks.trim(), MessageType.extendedText, { contextInfo: { mentionedJid: id } }) : client.sendMessage(client.from, teks.trim(), MessageType.extendedText, { quoted: chat, contextInfo: { mentionedJid: id } })
}

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')

// Premuim
const viewPm = await databaseView('SELECT * FROM pmium')
const pmWhiteList = JSON.stringify(viewPm)
client.isPmium = pmWhiteList.includes(client.sender)

const viewGc = await databaseView('SELECT * FROM gmium')
const gcWhiteList = JSON.stringify(viewGc)
client.isGmium = gcWhiteList.includes(client.groupId)

// Logging Message
if (!client.isGroup && isCmd) console.log('\x1b[1;31m~\x1b[1;37m>', '[\x1b[1;32mEXEC\x1b[1;37m]', time, color(commandName), 'client.from', color(client.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(client.sender.split('@')[0]), 'args :', color(args.length))
Expand All @@ -136,7 +144,8 @@ async function krypton () {
},
error: {
group: '❌ Perintah ini hanya bisa di gunakan dalam group! ❌',
args: '❌ Perintah anda salah! ❌'
args: '❌ Perintah anda salah! ❌',
premium: '❌ Perintah hanya untuk pelanggan premium! ❌'
}
}

Expand All @@ -161,6 +170,7 @@ async function krypton () {
cooldowns.set(command.name, new Collection())
}

// Time durations
const now = Date.now()
const timestamps = cooldowns.get(command.name)
const cooldownAmount = (command.cooldown || 1) * 1000
Expand Down

0 comments on commit 0eb6234

Please sign in to comment.