Skip to content

Commit

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

module.exports = {
name: 'gmium',
aliases: ['gm'],
description: 'Untuk mengelola member premium group _only owner_',
async execute (client, chat, pesan, args) {
if (!client.isOwner && !client.isSudo) return client.reply(pesan.hanya.owner)
const gid = args[2]
if (args[0] === 'add') {
if (args[1] === 'unlimited') {
if (chat.message.extendedTextMessage === undefined || chat.message.extendedTextMessage === null) return client.reply('Tag yang bersangkutan!')
mentioned = chat.message.extendedTextMessage.contextInfo.mentionedJid
const sign = mentioned[0]
databaseInput(`INSERT INTO gmium(gid, lifetime, signature) VALUES('${gid}', 'unlimited', '${sign}')`)
.then(() => {
client.reply(pesan.berhasil)
}).catch((err) => {
client.reply(pesan.gagal)
console.log(err)
})
} else {
databaseInput(`INSERT INTO gmium(gid, lifetime, signature) VALUES('${gid}', 'standard', '${sign}')`)
.then(() => {
client.reply(pesan.berhasil)
}).catch((err) => {
client.reply(pesan.gagal)
console.log(err)
})
}
} else if (args[0] === 'del') {
databaseInput(`DELETE FROM gmium WHERE gid = '${gid}'`)
.then(() => {
client.reply(pesan.berhasil)
}).catch((err) => {
client.reply(pesan.gagal)
console.log(err)
})
} else if (args.length === 0) {
await databaseView('SELECT * FROM gmium')
.then((result) => {
let text = '📝 Daftar *Premium* di bot ini\n'
if (result.length > 0) {
for (let i = 0; i < result.length; i++) {
const gid = result[i].gid
const waktu = result[i].waktu
const sign = result[i].signature.replace('@c.us', '')
const life = result[i].lifetime
text += `${i}. *GID*: ${gid}\n`
text += ` ├> *Lifetime*: ${life}\n`
text += ` ├> *Bersangkutan*: @${sign}\n`
text += ` └> *Mulai*: ${waktu}\n`
}
client.mentions(`${text}`, mentioned, true)
} else {
text += '- Belum ada member'
client.reply(from, text, id)
}
}).catch((err) => {
client.reply('Error mengambil database')
console.log(err)
})
}
}
}
41 changes: 23 additions & 18 deletions krypton.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const time = moment.tz('Asia/Jakarta').format('DD/MM HH:mm:ss')
const { databaseView, databaseInput } = require('./utils/db')

async function krypton () {

/***
* Initial Database
**/
Expand Down Expand Up @@ -160,6 +159,10 @@ async function krypton () {
const gcWhiteList = JSON.stringify(viewGc)
client.isGmium = gcWhiteList.includes(client.groupId)

const sudo = await databaseView('SELECT * FROM sudo')
const sList = JSON.stringify(sudo)
client.isSudo = sList.includes(sender.id)

// 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 @@ -168,10 +171,12 @@ async function krypton () {

pesan = {
tunggu: '⌛ Sedang di Prosess ⌛',
gagal: '❌ Gagal melaksanakan perintah ❌',
berhasil: '✔️ Berhasil ✔️',
hanya: {
admin: '❌ Perintah ini hanya bisa di gunakan oleh admin group! ❌',
botAdmin: '❌ Perintah ini hanya bisa di gunakan ketika bot menjadi admin! ❌'
botAdmin: '❌ Perintah ini hanya bisa di gunakan ketika bot menjadi admin! ❌',
owner: '❌ Perintah hanya untuk owner/sudo! ❌'
},
error: {
group: '❌ Perintah ini hanya bisa di gunakan dalam group! ❌',
Expand Down Expand Up @@ -203,24 +208,24 @@ async function krypton () {

// Time durations
if (!client.isPmium || !client.isGmium || !client.isOwner) {
const now = Date.now()
const timestamps = cooldowns.get(command.name)
const cooldownAmount = (command.cooldown || 1) * 1000

if (timestamps.has(client.from)) {
const expirationTime = timestamps.get(client.from) + cooldownAmount

if (now < expirationTime) {
const timeLeft = (expirationTime - now) / 1000
return client.sendMessage(client.from,
`Mohon tunggu lebih dari ${timeLeft.toFixed(1)} detik sebelum menggunakan perintah ini *${command.name}*.`,
MessageType.text
)
const now = Date.now()
const timestamps = cooldowns.get(command.name)
const cooldownAmount = (command.cooldown || 1) * 1000

if (timestamps.has(client.from)) {
const expirationTime = timestamps.get(client.from) + cooldownAmount

if (now < expirationTime) {
const timeLeft = (expirationTime - now) / 1000
return client.sendMessage(client.from,
`Mohon tunggu lebih dari ${timeLeft.toFixed(1)} detik sebelum menggunakan perintah ini *${command.name}*.`,
MessageType.text
)
}
}
}

timestamps.set(client.from, now)
setTimeout(() => timestamps.delete(client.from), cooldownAmount)
timestamps.set(client.from, now)
setTimeout(() => timestamps.delete(client.from), cooldownAmount)
}

try {
Expand Down

0 comments on commit 9f07e40

Please sign in to comment.