Nurutomo / wabot-aq

WhatsApp Bot
GNU General Public License v3.0
709 stars 1.38k forks source link

Member premium hilang setelah bot di restart #470

Closed adulalhy closed 3 years ago

ghost commented 3 years ago

Taro diconfig makanya

adulalhy commented 3 years ago

Taro diconfig makanya

tau, cuma mau ngasih tau aja ke nurutomo biar di fix

ariffb25 commented 3 years ago

emang cuma sementara karena pake global, kalo mau pake json. berikut langkah-langkahnya

  1. membuat file premium.json di folder src (opsi ini bebas, terserah kamu) isinya terserah kamu juga
    ["62831xxx", "62831xxx"] 
  2. mengubah config.js , jangan lupa pindahin fs nya jadi diatas, karena sblmnya sudah diinisiasi dibawah
    global.prems = JSON.parse(fs.readFileSync('./src/premium.json'))
  3. addprem.js
    let fs = require('fs')
    let handler = async (m, { conn, text, isOwner }) => {
    if (!isOwner) throw false
    const dbprem = JSON.parse(fs.readFileSync('./src/premium.json'))
    let who
    if (m.isGroup) who = m.mentionedJid[0] ? m.mentionedJid[0] : m.quoted ? m.quoted.sender : text
    else who = text ? text : m.chat
    if (dbprem.includes(who)) throw 'Sudah premium!'
    dbprem.push(`${who.split('@')[0]}`)
    fs.writeFileSync('./src/premium.json', JSON.stringify(dbprem))
    conn.reply(m.chat, `Hai, @${who.split('@')[0]}. Kamu sudah premium!`, m, {
        contextInfo: {
            mentionedJid: [who]
        }
    })
    delete require.cache[require.resolve('../config')]
    require('../config')
    }
    handler.help = ['+prem *@user*']
    handler.tags = ['owner']
    handler.command = /^(add|tambah|\+)prem$/i
    module.exports = handler
  4. delprem.js
    let fs = require('fs')
    let handler = async (m, { conn, text, isOwner }) => {
    if (!isOwner) throw false
    const dbprem = JSON.parse(fs.readFileSync('./src/premium.json'))
    let who
    if (m.isGroup) who = m.mentionedJid[0] ? m.mentionedJid[0] : m.quoted ? m.quoted.sender : text
    else who = text ? text : m.chat
    if (dbprem.includes(who)) throw 'Belum premium!'
    let index = dbprem.findIndex(v => (v.replace(/[^0-9]/g, '') + '@s.whatsapp.net') === (who.replace(/[^0-9]/g, '') + '@s.whatsapp.net'))
    dbprem.splice(index, 1)
    fs.writeFileSync('./src/premium.json', JSON.stringify(dbprem))
    conn.reply(m.chat, `Hai, @${who.split`@`[0]}. Masa premium kamu sudah berakhir!`, m, {
        contextInfo: {
            mentionedJid: [who]
        }
    })
    delete require.cache[require.resolve('../config')]
    require('../config')
    }
    handler.help = ['-prem *@user*']
    handler.tags = ['owner']
    handler.command = /^(remove|hapus|-|del)prem$/i
    module.exports = handler
github-actions[bot] commented 3 years ago

stale issue