Node.js Module

Install the package

First, install it with npm or your favourite package manager

npm install openblacklist

And import it in your app like so:

import { BlacklistClient } from "openblacklist"

Now, let's use it !

The syntax is very inspired by discord.js !

Create a Client with the BlacklistClient class

import { BlacklistClient } from "openblacklist"

const client = new BlacklistClient({ // Create your client
    key: "your-obl-key",
    path: "/urlpath",
    pass: "urlpass"
})

Recieve Post Requests

Listen on a port to recieve POST requests

client.listen(3000) : Promise<void> // 3000, or the port your app runs !

And listen for event like, ready, add or remove !

client.on("ready", (port) => {
    console.log(`OpenBlacklist is now ready on port ${port} !`
})

client.on("add", (bl) => {
    console.log(`Member ${bl.user.username} (${bl.user.id}) was blacklisted !`)
})

Send Get Requests

There is actually only one method for that and it's the client.checkUser function !

Here is how to use it:

client.checkUser(id) : Promise<Blacklist>
// Check if user is blacklisted
const response = await client.checkUser("840749770221682689")

/*
{
  isBlacklisted: true,
  user: { id: '840749770221682689', username: 'kingqs' },
  reasons: {
    fr: 'Raid, spam, massping',
    en: 'Raid, spam, massping',
    es: 'Incursión, spam, envío masivo'
  }
}
*/

if(!response.isBlacklisted) console.log("User is not blacklisted...")
else console.log(`User ${response.user.username} is blacklisted for the reason:
"${response.reasons.en}" !`)

And that's pretty much it !

Yeah it's short but organises your code and makes it simple for you !

JS API Documentation

Methods

Method
Description
Returns

on(event, callback)

Listens for an event

off(event)

Unlistens for an event

listen(port)

Listen api calls to a port

Promise<void>

checkUser(id)

Checks if an user is blacklisted

Promise<Blacklist>

Events

Name
Description
Fields

ready

Emits when express is ready

port : number

add

Emits when someone is added to the blacklist

blacklist : Blacklist

remove

Emits when someone is removed from the blacklist

blacklist : Blacklist

Types

type BlacklistReasons = {
    fr: string;
    en?: string;
    es?: string;
};

type BlacklistUser = {
    id: string;
    username?: string;
    displayname?: string;
};

type Blacklist = {
    isBlacklisted: boolean;
    user: BlacklistUser;
    reasons?: BlacklistReasons;
};

Last updated