First, install it with npm or your favourite package manager
npm install openblacklist
pnpm add openblacklist
yarn add openblacklist
And import it in your app like so:
import { BlacklistClient } from "openblacklist"
Now, let's use it !
The syntax is very inspired by !
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 !