-
Notifications
You must be signed in to change notification settings - Fork 19
Ban Features and Commands
- Why is there a wall_e ban system?
- How bans are recorded
- Loading the ban list
- Prevent returning banned members from joining
- Converting discord ban to wall_e ban
- Deleting the messages from a banned user
- How auto-complete shows the banned users
- How a user is unbanned
Because discord, in their infinite wisedom [🙄] decided that a discord ban has to also ban the I.P associated with the user being banned. This does not work for us because the students on rez all share the same public IP cause that's how NAT works so we had to implement a custom ban so that we have a way to ban just that user and not take any action against their I.P.
bans are recorded in 2 ways:
- all bans are saved in the database for ensuring persistence via the long-term storage even after wall_e is restarted.
-
ban_list
is a dictionary that provides a faster way to access the list. It's basically the cache of the list of banned users in the database.
ban_list
is used:
- to check if a user is banned in places like when someone attempts to join the guild or if a Moderator accidentally does a discord ban or when a user is being banned or unbanned to ensure a valid user is specified.
- Also used when getting the list of banned users for the auto-complete menu
- It's finally also used to not start assigning the XP roles to a user when they join if they are about to be kicked out anyways
the ban list is loaded in the on_ready
function load
at the last line as a dictionary where the get_all_active_ban_user_ids
function uses the user_id
as the key and the value is the username
.
The value is only needed for the auto-complete menu used by the bans
command.
there is a watchdog
function that is called whenever the bot detects a signal that is sent when a member joins the guild that makes sure that if the "new" member is just a banned member, then they are kicked.
When the wall_e ban mechanism was created, there was a lot of discord bans so there was a need to automate the migration. hence the convertbans
command was born. And it's also a command that is not really useful after the initial transfer is complete but no reason to delete it 🤷🏿♀️
After the convertbans
is run, the discord ban still exists.
Which is why, if you want to wipe the discord ban completely, you need to also run purgebans
to complete the migration.
If a user that is banned was being particularly inflammatory, there might be a need to censor their words to hide what happened.
In addition, depending on how long they were being inflammatory before a Moderator stepped in, there might be quite alot of message to delete.
Which means there were 2 ways to go about that:
- have all the messages be deleted as part of the
ban
command which means theban
command might take a while to complete - have the
ban
command mark the user as being banned and store the necessary details to purge their messages at a later time
I went the second route just cause there have been times when the bot might take a few more seconds than usual to respond to a ban message, causing an impatient Moderator to call the ban
command more than once on the same user which can cause issues with the banning system.
This piece of logic records the fact the the user is banned and records how many of the messages to delete
This piece of logic, every 20 seconds, gets a list of all banned users whose messages have not yet been purged and goes through all their messages and removes any and all that were sent in any channel over the given window of purge_window_days
the auto-complete menu calls the get_banned_users
command which creates the banned_users
list using the ban_list
What differentiates a banned from an unbanned user is that an banned user has None
for the unban_date
. So once a user is unbanned, their ban is removed by setting the unban_date
rather then removing all record of their ban.