diff --git a/command/notes.js b/command/notes.js new file mode 100644 index 0000000..e6564d7 --- /dev/null +++ b/command/notes.js @@ -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 ', + 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}`)) + } + } +} diff --git a/krypton.js b/krypton.js index 57c6695..3b4e190 100644 --- a/krypton.js +++ b/krypton.js @@ -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() @@ -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 @@ -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)) @@ -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! ❌' } } @@ -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