Adding SQLite support & reroll functionality to the Discord Raffle Bot
Discord Raffle Bot [0.3]
The Discord Raffle Bot is, as the name suggests, a simple python bot for hosting real time raffles for talk shows, communities, livestreams and others. This simple bot allows for flexibility while utilizing just a single command to ensure simplicity for non-tech savvy users.
People experienced in the Python programming language will also be able to easily expand on the bot, add new functionalities and commands thanks to an easy and simple code design that welcomes even the beginners.
This bot utilizes just Python 3.6 (should work on 3.0 and newer, but was tested on 3.6) and the discord.py Python library.
The bot is heavily dependent on the asyncio library (installed by default) which allows Python to act as an asynchronous programming language. This ensures that the bot can be run on multiple discord servers and in multiple channels at once without stopping raffles already taking place and without hosting multiple instances of the bot.
Newly implemented features
Database Functionality (SQLite)
I chose SQLite for one, simple reason - it's lightweight and doesn't require any installing by whoever wishes to use this bot. It's plug and use, which is something that I value really highly in this project.
I implemented a feature that will save every performed raffle into a SQLite database table.
The id is self incremented, everything else is inputted at the end of each raffle.
Thanks to that, an another, really important feature, was added!
Reroll functionality (!reroll)
By typing in
!reroll <id>, where is the id of a given raffle, you can reroll the raffle with all the participants and get a new, different winner!
This is useful for when the winner wants to concede his prize, the winner does not respond or the winner is a part of the staff - generally someone who should not win the raffle. The winner will always be chosen at random, but it will never be the previous winner unless they're the only person to enter the raffle
While previously some small changes to the code were made to comply with the PEP8 guidelines, they were lazy, not very thought out and partially wrong. The code has been adjusted to these guidelines and will follow them ever since now.
3 New functions were added in total, as well as a new custom message and a new config setting. The
Raffle class has been altered slightly and some changes were made to the
This method of the Raffle class is utilized to create the table if needed, and then save the raffle in the DB. It also sets
self.raffle_id to the correct value.
This function allows for quick fetches of the last id in the database, then returns the ID of the current raffle. This is necessary to inform the raffle owner of his raffle's ID which in turn lets him reroll if needed.
This is the big boy of this update. Essentially runs the entire reroll - fetches necessary information and then picks a new winner at random. Returns the same winner if there was only 1 participant.
Changes to the old dm message & a new message for the reroll win.
I hate new functionalities added to my good old software!!
Worry not, just use this branch to get the old version of the bot.
The project is finished aside from final polish and addition of good suggestions. It will also remain maintained for bugs if any are found.
How to contribute?
If you wish to contribute to this project, please use the Github Issues or create Pull Requests directly. You can also contact me via comments under this post.