Skip to content

Blacklist!

Mihou edited this page Jul 2, 2021 · 1 revision

⚔️ Velen Blacklist

Velen also supports another simple feature that will assist you in blacklisting specific users from using any command of your bot with VelenBlacklist which supports both persistent and non-persistent blacklists (persistent requires a database).

To get started, first, you have to create a blacklist instance and integrate it with Velen, an example usage would be (non-persistent blacklist):

Velen velen = Velen.builder().setBlacklist(new VelenBlacklist()).build();

If you want to blacklist a user, all you have to do is simply:

velen.getBlacklist().add(userId);

To remove, all you have to do is:

velen.getBlacklist().remove(userId);

The two methods above will only modify the internal blacklist and won't touch your database which means, if you are using a persistent database, additional means are needed. For example, if you are making changes onto your database through a method like add, you have to use either methods as well to apply the changes to internal list.

You can also opt to refreshing it which uses the loader you set when building the blacklist, the method to refresh the user is simply:

velen.getBlacklist().refresh(userId);

BUT the method above as I mentioned, requires a loader which you can quickly build when constructing the blacklist, for example (MongoDB with a Helper Class):

new VelenBlacklist(aLong -> MongoDB.collection("blacklists", "someBot").find(Filters.eq("userId", aLong)).first() != null);

The reason why we are using != null on the above is because the blacklist expects a boolean as a return, and so, the database is expected to be something similar like: If the user is on the database, then the user is blacklisted otherwise not.

We recommend placing null or not adding setBlacklist() at all if you are not using the blacklist since a null blacklist is a signal to the application that we are not using a blacklist (to stop the application from heading to the blacklist and getting the value and instead assume no one is blacklisted).