Adding SQLite support & reroll functionality to the Discord Raffle Bot

in #utopian-io6 years ago (edited)

image.png

Discord Raffle Bot [0.3]

Repository
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.

Technology Stack

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

The commits for this update can be found between 9e3ad35 and fc8d092.

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.
image.png
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!
image.png

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

Following PEP8

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.

Implementation

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 on_message() event.

app.py
  • Raffle.usedb()
    image.png

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.

utils.py
  • check_last_id()
    image.png

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.

  • reroll()
    image.png

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.

config.py
  • r.messages
    image.png

Changes to the old dm message & a new message for the reroll win.

  • database
    image.png

Self explainatory.

I hate new functionalities added to my good old software!!

Worry not, just use this branch to get the old version of the bot.

Roadmap

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.

My Github Account

Sort:  
Loading...

Thanks for building this wonderful bot @jestemkioskiem. @jedigeiss, @techslut and I really appreciate the work you have put into it. It adds a great deal to our weekly show.

You're the best!!

Nice project. Wish you all the best.

Congratulations! Your post has been selected as a daily Steemit truffle! It is listed on rank 9 of all contributions awarded today. You can find the TOP DAILY TRUFFLE PICKS HERE.

I upvoted your contribution because to my mind your post is at least 17 SBD worth and should receive 101 votes. It's now up to the lovely Steemit community to make this come true.

I am TrufflePig, an Artificial Intelligence Bot that helps minnows and content curators using Machine Learning. If you are curious how I select content, you can find an explanation here!

Have a nice day and sincerely yours,
trufflepig
TrufflePig

Hey @jestemkioskiem
Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!