Electoric banner

Electoric

28 devlogs
38h 1m 8s

Updated Project: Complete rewrite and refactor of an old non-hackclub project.
This is a discord bot made for large friend groups of ~10+ people.

Demo Repository

Loading README...

Trey

Banner!

There is now a project banner. Ignore the lapse video, I forgot I renamed this project to electoric (the old name was electorial). Idk comment if the old name was better.

0
Trey

Wrapping up

Mostly bug fixes before I ship. I missed a few return statements and a few ephemeral=True statements. Notable changes:

  • /vc rename was removed, use /vc modify instead
  • /startelection was renamed to /resign
  • Elected leader can no longer select a bot/themselves as vice (bugfix, i missed the return statement)
  • UwUify now works if the user has no avatar, and dosent throw an error anymore
    I cant really show much proof, but the changes were released as v1.0.3
Attachment
0
Trey

Containers!

The app is now built and published as ghcr container images! A docker-compose.yml is provided in the readme.md for anyone interested in running their own version of the bot. It is built from every commit and tagged on version releases.

Attachment
0
Trey

TODO: fix

I have completed all the TODOs in my code, so there are many new features!

Voice rooms manager

There is now a /vc modify command for changing settings of your room. It contains a few settings:

  • Rename
  • Extra people (people who can join regardless of permission level)
  • Banned people (same as extra people but in reverse, people who could normally join would no longer be allowed to join)
  • Change allowed features
  • Change max people
    The /vc create command now also allows setting invited people directly via the modal, which is useful for the “just me” permission level.

Other

  • You can now set a custom ping message for elections
  • The backend now (mostly) uses get_or_fetch to avoid unneeded API calls
  • After someone leaves the server (or is kicked), any vote channel that mentions them (excluding elections) is deleted.
  • If the leader fails to pick a vice, the election can be restarted.
  • You can now set the grace period for the leader to pick a vice leader
  • Being UwUified no longer causes buggy autoreplies
  • Sending a message while UwUified no longer throws an error message
  • Autoreplies now use discord.MessageReference.from_message(message) so they don’t throw warnings on every use
Attachment
Attachment
0
Trey

I choose you!

After an election, the new leader can pick a vice-leader that is granted permission level 3. By default this prevents them from getting kicked, and a few other things. You can also make it so that the leader is required to set a vice-leader. You can also disable picking a vice entirely.

Elections 3

Elections are now automatically started when the leader leaves. This is reliant on the pycord cache, so while it should work most of the time, sometimes the on_member_remove function may not be called. To my knowledge, I cannot fix this, however this should only be a problem with abnormally large servers and an overthrow passing right after bot start. I may try a fix at a later time.

Other

  • The docs were improved a little bit
  • Admin logs now include the date/time of the event at the bottom

Bugfixes

  • Overthrow votes where the leader was not found no longer throw an error.
  • Probably more that I am forgetting
Attachment
Attachment
Attachment
0
Trey

Works on my machine

There are now install docs, not much else to put here.

Attachment
0
Trey

Thou shalt not rule

You can now overthrow the current leader with a vote, I cannot calculate majority due to a lot of factors, so the required votes is a config value.

Config options

  • Set the required vote count
  • Should they be kicked from the server, or just have their role removed
  • Should a new election start after an overthrow
0
Trey

Election 2

More logic has been added, including settings for some existing functions, and scheduling elections.

Scheduling

You can now set a day of week and hour to automatically start an election.

Logging

The bot now logs when an election restore is attempted, and the state id it is recovering from.

New config options

You can now change the target end hour for elections.

New features

The election channel is now automatically deleted, and force_vice is now enforced, but there is currently no way to pick a vice leader.

Restoring state improvements

Every state of an election can now be restored (to my knowledge). The bot now saves who has won the vote before deleting the messages. The only downside is once the bot is back up, it does not have enough information to play the animation, but roles are still given out.

Overthrow

This is work in progress, the feature does not fully work yet, but the channel is now automatically created. More info will be shown probably next log.

bugfixes

Whoever is being voted on can no longer see the vote channel, e.g. the person being votekicked/promoted can not see that they are in a vote (unless you give them audit log/administrator perms, this is a reminder that most bot features will not work if anyone has administrator perms).
Important messages are now pinned.

Attachment
Attachment
0
Trey

hackatime was down so this is pretty long

Election

I couldn’t think of a good name for this devlog, but it includes a pretty important feature. The groundwork for leader elections is now here, and contains a lot of features.

Start

There is no actual way to start an election right now, the demo video just creates a fake save state that the bot assumes is correct. However, when there is a way to start an election, the start function allows a reason to be passed in. When the channel is made, it is locked to everyone until all the messages are set up, then it is unlocked and an @everyone is sent.

Save state

The bot can be turned off or terminated (except during tallying), and pick up from where it left off when turned back on. I set a challenge for myself to not store any data on disk, so the current election state is stored within invisible characters in the channel topic. I have a function that takes a decimal input, and converts it into binary, then converts the binary into a string of invisible characters that can be put in the channel topic, and is invisible. The characters can only be seen by opening the channel topic, then highlighting all text.

Exceptions

If no votes are cast the leader and vice-leader stay the same.

Election end

All messages should be deleted, the demo video shows one getting past because it was recorded before the fix. There is a little “animation” that plays when the election finishes that shows the top 3 placements. If there is a tie for first, the leader is randomly chosen. The channel is deleted an hour after the vote concludes, but a simple <user> is the new leader! message is sent in the public channel, and a log of the top 3 places are sent in the log channel. The send message permission is also locked to leader and vice leader after the vote is over.

Lock

A few features can be locked during elections, like kick, votekick, and promote.
Hopefully hackatime works today so I can post shorter devlogs.

Attachment
0
Trey

Opened rooms

Rooms now have more features! You can manually add/remove members from your channel. This also means the Just me vc option has a reason to exist now. When you add a user, they are given connect permission. When you remove a member, you can choose to kick them from vc, or keep them in, but their connect permission is removed. Also, /vc rename exists now, you can rename your channel after it has been made.

Attachment
Attachment
0
Trey

Closed rooms

You can now end your vc, and either kick everyone out or move them to another call. If you chose to move members, it respects permissions, but you must have permission for it to move anyone else. If someone is not able to join the vc, you will be told.

Bugfixes

The max number of rooms was fixed, I forgot to actually save the amount of rooms you have, so it always thought you had zero.
Starting the bot while people are in rooms no longer throws an error

Attachment
0
Trey

Small changes

This devlog contains many small changes that I don’t think need their own devlog. These changes are:

  • load_config now uses os.path.join instead of raw strings
  • /features/plusvote/required_wait is now enforced. Members must wait 48 hours before being eligible to be promoted. The vote is still required.
  • Only one votekick/promotion vote for a user can be made at a time
  • Most if not all completed TODOs have been removed
  • If the bot gets shut down or killed after a vote has concluded, but during the 60-second period where it has not been deleted, it will be deleted the next time the bot starts.
Attachment
Attachment
0
Trey

Kick them out 2

Leader and vice leader now have permission to kick people. This is different from giving leader the kick members permission for three reasons:

  • It is logged
  • You can set permissions on who they can kick
  • You can set a cooldown
Attachment
Attachment
Attachment
Attachment
0
Trey

Nametag 2

Leaders can now rename permission roles (including theirs). Any other role will give an error. The permissions can still be changed, but no matter the permissions set, people are not allowed to change the name of levels above theirs.

Attachment
Attachment
0
Trey

Nametag

The server details can now be changed by people. Vice leader and up can rename the server, and leader can change the icon.

Why not give leader Manage Server

Manage server comes with more permissions than just details, that you usually dont want people having.

Attachment
Attachment
Attachment
Attachment
0
Trey

:3

You can now “uwuify” people. That’s basically it. The settings are the basically same as timeout.

backend

more things are logged in the log channel

Attachment
0
Trey

Ping pong

You can now set up regex for messages you want the bot to automatically reply to messages. The settings are:

  • The regex you want to reply to
  • What you want to reply with
  • If the bot should delete the original message

Backend

There are also a few backend UX improvements. The 5 minute voice cache duration can now be changed, and when missing a config option, the full path is now shown.

Attachment
Attachment
0
Trey

Call me

Pretty simple update. Somehow, discord has not added the ability for voice channels to call people in servers yet. This is the closest I could get. The bot can ping for the first person to start a call, and can be configured to also:

  • Send a message on any join
  • Send a message on any leave
  • Only send a leave message when the last person leaves the call
Attachment
0
Trey

Shush

This took somehow way more and way less time then i thought it would. Anyway, when you are server muted/deafened or channel permissions prevent you from talking, the bot takes note of what you can do, and saves/restores it when switching channels. This fixes being able to make your own voice channel, and unmute yourself, then rejoin wherever you were muted. Right now, they are saved for a minimum 5 minutes, but can be extended when you update your voice status. This might not seem like much, but this is really useful to me.

0
Trey

Getting a promotion!

You can now promote guests to plus members by a vote. This one was faster then the votekick because most of the code is copied from votekick, so it works basically the same. Some of the code that I think will be reused in future votes is now in functions.

Attachment
0
Trey

Smaller changes

This devlog contains pretty small changes to some wording, but I still wanted to make it because I forgot some demo images in my last one. Some notable (but still small) changes are:

  • Wording changes on some logs
  • /vc create now allows disabling people from using activities
  • Fixed a bug where people may have been able to double trigger the votekick message
Attachment
Attachment
Attachment
0
Trey

Kick them out!

This update includes a few features, including votekicks. People can now start votekicks to kick members out of the server.
As always, there is a lot of config, and you can change:

  • Who can start a vote
  • Who can vote
  • Who is exempt from being votekicked
  • How many times one person can start a votekick in a specified duration
  • How many votes are required for a decision
    The vote happens in an individual channel, so permissions are customized by the bot, and the channel gets deleted after the vote.

backend

Permission checks can now be completed by a decorator

Attachment
0
Trey

Sorting hat

People who join now automatically get given the guest role if they are not a bot, and are given the VIP role if they are on the VIP list. It also gets logged to the configures log channel

Attachment
Attachment
0
Trey

Go to timeout

People can now time each other out! It’s mostly for fun, not for actual moderation. It has a configurable timeout duration and cooldown. You can also make the duration different when the leader times someone out!

Bugfixes

Rooms that are created now actually get deleted when you leave
People can no longer change the channel status when in a room
Permissions are actually enforced now

Attachment
Attachment
0
Trey

More room functionality

The text boxes work correctly now! The support team in pycords discord server got back really fast, and was really helpful. The fix was to use a pre-release that contained the bugfix. Anyway, you can now limit what others can do in vc, and change how many people can be in it at once. The channel owner can also bypass their own restrictions.

Attachment
Attachment
0
Trey

Voice rooms

After messing with modals for an hour, I got something mostly working. The channels do not auto delete yet, but most code is there. There is a weird bug right now where the text inputs should be optional, but are not. This looks like a library issue, so I will wait for a fix. Voice channels can be made, and the privacy level can be set up to whatever you can join, but the features and max people boxes do not work yet. Auto delete when nobody joins is working though!

Attachment
Attachment
Attachment
0
Trey

Restricting permissions

I have now planned out how the permission system will work. This is still a work in progress and new things will be added, but this is a good start. Sadly, discord does not let bot owners restrict commands to roles, so it is not possible to have the buttons hidden in UI.

Attachment
0
Trey

A fresh start

The bot and example config have all been planned out. The rest of this project should be implementing features from this config file to make everything work. I have a lot planned. I’m also giving myself the challenge of not using a DB, or any data storage, if possible, everything should be stored inside the discord server. The config file has also been documented, so anyone who wants to use my app, should have little trouble, even though it asks for a lot.

Attachment
0