npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

safety-safe

v3.0.0

Published

Firewall cerdas untuk Bot WhatsApp untuk mendeteksi dan memfilter pesan bug/crash/spam (Baileys).

Readme

safety-safe

Firewall Cerdas buat Bot WhatsApp Lu.

NPM Version NPM License

Bot lu sering crash atau nge-lag parah gara-gara dikirimin pesan aneh? Sering mati total diserang orang iseng? Tenang, safety-safe ini gue bikin buat jadi tameng bot lu. Ini firewall super ringan yang bakal nyaring semua pesan masuk dari berbagai macem bug, spam, atau pesan perusak lainnya.


Kenapa Lu Wajib Pake Ini?

  • 🛡️ Keamanan Berlapis: Gue udah tanamkan deteksi buat macem-macem serangan, dari teks super panjang, mention ribuan orang, sampe bug dokumen dan lokasi yang paling sering bikin aplikasi WhatsApp crash.
  • ⚡ Enteng Banget: Gak ada dependensi sama sekali. Gak bakal bikin folder node_modules lu jadi bengkak. Fokusnya cuma satu: keamanan.
  • 🔧 Atur Sendiri Aturannya: Bosen sama paket yang kaku? Di sini, lu yang jadi bos. Atur sendiri batas toleransi bot lu buat tiap jenis serangan.
  • 🔌 Langsung Pasang: Didesain khusus buat nyambung mulus sama @whiskeysockets/baileys.

Instalasi

Gak pake ribet, cukup satu baris di terminal lu:

npm install safety-safe

Cara Kerjanya Gimana?

Gini, safety-safe itu ibarat alarm mobil. Tugasnya cuma teriak sekenceng-kencengnya kalo ada maling (isMalicious: true). Dia gak bertugas buat nangkep malingnya. Nah, lu sebagai pemilik mobil (bot), yang mutusin mau ngapain: mau ngejar malingnya, mau nelpon polisi, atau mau cuekin aja.

Pemisahan tugas ini bikin safety-safe tetep enteng dan ngasih lu kontrol penuh buat nentuin aksi apa yang paling pas buat bot lu.

Cara Pake Paling Gampang (Copy-Paste Aja)

Ini contoh paling umum. Kalo ada pesan bahaya, kita langsung hapus pesannya, blokir pengirimnya, dan lapor ke nomor admin (nomor lu sendiri).

import { makeWASocket } from '@whiskeysockets/baileys';
import { analyzeMessage } from 'safety-safe';

// 1. Setup client Baileys lu kayak biasa
const client = makeWASocket({ /* ...konfigurasi lu di sini */ });
const myNumber = "6281234567890"; // Ganti pake nomor admin/owner

// 2. Terapkan di dalam event 'messages.upsert'
client.ev.on('messages.upsert', async (m) => {
    const msg = m.messages;

    // Cek dasar, abaikan kalo pesan gak valid, dari diri sendiri, atau dari grup
    if (!msg.message || msg.key.fromMe || msg.key.remoteJid.endsWith('@g.us')) {
        return;
    }

    // 3. Analisis pesannya pake safety-safe
    const { isMalicious, reason, severity } = analyzeMessage(msg.message);

    // 4. Kalo ternyata berbahaya, ambil tindakan!
    if (isMalicious) {
        console.log(`[!] Ancaman Terdeteksi dari ${msg.pushName} (${msg.key.remoteJid})`);
        console.log(`    Alasan: ${reason} | Level Bahaya: ${severity}`);
        
        try {
            // CONTOH AKSI: Hapus pesan, blokir, dan lapor ke Admin
            await client.sendMessage(msg.key.remoteJid, { delete: msg.key });
            await client.updateBlockStatus(msg.key.remoteJid, "block");

            await client.sendMessage(`${myNumber}@s.whatsapp.net`, { 
                text: `🔒 User *${msg.pushName}* (${msg.key.remoteJid}) udah gue blokir otomatis.\nAlasan: *${reason}*.`
            });

        } catch (err) {
            console.error('[!] Gagal ngambil tindakan blokir/hapus:', err);
        }
        return; // Penting: Hentikan pemrosesan pesan ini lebih lanjut
    }

    // Kalo pesan aman, lanjutkan logika bot normal lu di sini...
    console.log(`[+] Pesan aman dari ${msg.pushName}`);
    // ...
});

Mau Lebih Canggih? Pake Konfigurasi!

Lu bisa atur sendiri "tingkat kesabaran" bot lu. Cukup kasih objek konfigurasi di argumen kedua. Gampang kan?

import { analyzeMessage } from 'safety-safe';

// Aturan custom yang lebih ketat dari default
const myRules = {
    maxTextLength: 4096,
    maxMentions: 25
};

const { isMalicious } = analyzeMessage(msg.message, myRules);

Daftar Konfigurasi Lengkap:

| Opsi | Default | Deskripsi | | :--- | :--- | :--- | | maxTextLength | 10000 | Panjang teks/caption maksimal yang diizinkan. | | maxMentions | 100 | Jumlah mention maksimal dalam satu pesan. | | maxFileLength | 2147483648 (2 GB) | Ukuran file (dalam byte) maksimal yang tertera di properti pesan. | | maxPageCount | 10000 | Jumlah halaman maksimal di properti dokumen. | | maxCharacterFlood | 20000 | Jumlah karakter maksimal di pesan interaktif (buat nangkal bug flood). |

Pahamin Hasil Analisisnya

Fungsi analyzeMessage ngasih lu objek berisi info penting:

| Properti | Tipe | Penjelasan | | :--- | :--- | :--- | | isMalicious| boolean | true kalo berbahaya, false kalo aman. Ini yang paling penting. | | reason | string | Alasan kenapa pesan ditandai berbahaya. | | severity | string | Tingkat bahayanya: CRITICAL, HIGH, atau MEDIUM. | | threatType| string | Jenis ancamannya: CRASH, LAG, atau SPAM. |

Daftar Ancaman yang Gue Tangkal

  • [x] Teks atau Caption yang Panjangnya Gak Wajar
  • [x] Banjir Karakter di Pesan Interaktif
  • [x] Mention Massal (Ribuan Orang)
  • [x] Dokumen dengan Properti Palsu (fileLength, pageCount)
  • [x] Lokasi dengan Koordinat Gak Valid (Bikin Crash)
  • [x] Dan berbagai bug perusak lainnya.

Kontribusi

Nemuin bug baru yang lolos? Atau punya ide buat bikin ini lebih GG? Langsung aja buka Issue atau kirim Pull Request di GitHub. Bantuan dari lu sangat gue hargai!

Lisensi

Proyek ini pake Lisensi MIT. Santai aja pakenya.