 ## Discord Raffle Bot [0.3] [Repository](https://github.com/Jestemkioskiem/discord-raffle-bot/) 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](https://busy.org/exit?url=https%3A%2F%2Fgithub.com%2FRapptz%2Fdiscord.py) Python library. The bot is heavily dependent on the [asyncio](https://busy.org/exit?url=https%3A%2F%2Fasyncio.readthedocs.io%2Fen%2Flatest%2F) 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](https://github.com/Jestemkioskiem/discord-raffle-bot/commit/9e3ad350bae9fb65471ece4cec6273b99dee4bb8) and [fc8d092](https://github.com/Jestemkioskiem/discord-raffle-bot/commit/fc8d092228598964955e0ec8e1144b344ff182c9). ##### 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 *<id>* 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 ###### 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()`  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()`  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()`  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`  Changes to the old dm message & a new message for the reroll win. - `database`  Self explainatory. ### I hate new functionalities added to my good old software!! Worry not, just use [this branch](https://github.com/Jestemkioskiem/discord-raffle-bot/tree/no_db) 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](https://busy.org/exit?url=https%3A%2F%2Fgithub.com%2FJestemkioskiem%2Fdiscord-raffle-bot%2Fissues) or create Pull Requests directly. You can also contact me via comments under this post. [My Github Account](github.com/jestemkioskiem)
author | jestemkioskiem |
---|---|
permlink | adding-sqlite-support-and-reroll-functionality-to-the-discord-raffle-bot |
category | utopian-io |
json_metadata | {"community":"busy","app":"busy/2.5.4","format":"markdown","tags":["utopian-io","development","discord","python","programming"],"users":[],"links":["https://github.com/Jestemkioskiem/discord-raffle-bot/","https://busy.org/exit?url=https%3A%2F%2Fgithub.com%2FRapptz%2Fdiscord.py","https://busy.org/exit?url=https%3A%2F%2Fasyncio.readthedocs.io%2Fen%2Flatest%2F","https://github.com/Jestemkioskiem/discord-raffle-bot/commit/9e3ad350bae9fb65471ece4cec6273b99dee4bb8","https://github.com/Jestemkioskiem/discord-raffle-bot/commit/fc8d092228598964955e0ec8e1144b344ff182c9","https://github.com/Jestemkioskiem/discord-raffle-bot/tree/no_db","https://busy.org/exit?url=https%3A%2F%2Fgithub.com%2FJestemkioskiem%2Fdiscord-raffle-bot%2Fissues","https://github.com/jestemkioskiem"],"image":["https://ipfs.busy.org/ipfs/QmePVjzm27W8c2RviQUE9p2tTqVaADVeFH1oQpW8BNtLps","https://ipfs.busy.org/ipfs/QmeRT3JYtPjB2o46PmTCSrMy8Kt2K9VWdYSWZojr1qAdkN","https://ipfs.busy.org/ipfs/QmNYJ4oR5pNAVhUvmmuDDKA4WYc7zHbMFGn5A3vYU9siXe","https://ipfs.busy.org/ipfs/QmZ5tRfARL3tu6oafbZQerP7yUWFLwKCC6VnM81czbe3GN","https://ipfs.busy.org/ipfs/QmZx12FrB8Atp593wPgNMxiFQhLLNar2QPcjjVVQBx7cqz","https://ipfs.busy.org/ipfs/QmTMBAMEQix4aamHBftx6AFGREKbRDHc2M2ZoJi3m4y8Mi","https://ipfs.busy.org/ipfs/QmebyweDdQm3hmZnwzUcvs8pCvmYmSqYTVK1MHAeXfgE9F","https://ipfs.busy.org/ipfs/Qmf5D5bw5AravBWX2Q6aZh2DdJ74CBnHSVgeiRMFtceJR2"]} |
created | 2018-08-02 00:06:30 |
last_update | 2018-08-02 00:32:00 |
depth | 0 |
children | 6 |
last_payout | 2018-08-09 00:06:30 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 52.833 HBD |
curator_payout_value | 16.725 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 5,228 |
author_reputation | 41,292,066,961,817 |
root_title | "Adding SQLite support & reroll functionality to the Discord Raffle Bot" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 66,815,761 |
net_rshares | 41,311,889,945,445 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
yuxi | 0 | 3,015,186,603 | 10% | ||
jamzed | 0 | 31,495,650,880 | 100% | ||
mys | 0 | 26,928,918,956 | 25% | ||
jakipatryk | 0 | 54,536,961,155 | 100% | ||
jga | 0 | 2,674,910,202 | 8.5% | ||
semasping | 0 | 3,748,921,919 | 100% | ||
doughtaker | 0 | 22,592,825,821 | 100% | ||
jacekw | 0 | 7,399,011,167 | 50% | ||
rafalski | 0 | 29,498,374,215 | 100% | ||
bachuslib | 0 | 19,608,396,321 | 100% | ||
andrejcibik | 0 | 89,834,280,365 | 100% | ||
leir | 0 | 728,383,855 | 20% | ||
buckydurddle | 0 | 25,684,303,474 | 100% | ||
podanrj | 0 | 10,869,512,242 | 100% | ||
fernandorivera | 0 | 191,894,967 | 100% | ||
jrawsthorne | 0 | 7,744,461,777 | 100% | ||
utopian-io | 0 | 40,441,024,990,402 | 26.36% | ||
jaff8 | 0 | 68,704,406,183 | 100% | ||
emrebeyler | 0 | 52,364,112,367 | 27% | ||
bocik | 0 | 9,961,244,266 | 100% | ||
astromaniak | 0 | 5,424,331,837 | 15% | ||
mvanyi | 0 | 1,646,873,452 | 100% | ||
piotr-galas | 0 | 4,456,663,835 | 100% | ||
amosbastian | 0 | 28,194,579,558 | 47.92% | ||
tdre | 0 | 3,628,556,677 | 100% | ||
jestemkioskiem | 0 | 50,825,901,414 | 100% | ||
grzesiekb | 0 | 138,187,584,785 | 100% | ||
didymos | 0 | 1,615,858,146 | 100% | ||
sargoon | 0 | 8,309,315,722 | 100% | ||
holger80 | 0 | 91,512,730,062 | 26% | ||
movement19 | 0 | 3,804,173,197 | 17% | ||
mirkosche | 0 | 429,071,469 | 100% | ||
chetoblackmetal | 0 | 609,616,895 | 100% | ||
sereze | 0 | 107,650,067 | 13.5% | ||
zcool | 0 | 236,257,869 | 10% | ||
statsexpert | 0 | 1,843,105,922 | 40% | ||
zakaria14 | 0 | 213,533,052 | 50% | ||
trufflepig | 0 | 17,985,687,949 | 34% | ||
merry1990 | 0 | 564,633,078 | 100% | ||
maknah | 0 | 565,935,847 | 100% | ||
sergbog | 0 | 573,210,265 | 100% | ||
jemissongordon | 0 | 563,542,288 | 100% | ||
annetlitvin | 0 | 563,518,970 | 100% | ||
dima.nurgaliev | 0 | 573,030,496 | 100% | ||
manegasparyan | 0 | 575,134,121 | 100% | ||
polsikio | 0 | 563,629,777 | 100% | ||
miki21657 | 0 | 563,635,855 | 100% | ||
viktorpetro | 0 | 572,775,896 | 100% | ||
yallod | 0 | 563,746,921 | 100% | ||
shoemakerintegra | 0 | 563,635,855 | 100% | ||
floorsopera | 0 | 575,819,307 | 100% | ||
molly.smith | 0 | 575,819,307 | 100% | ||
artyr.stepnenkov | 0 | 563,632,655 | 100% | ||
thememeguy | 0 | 171,410,640 | 27% | ||
dearshy | 0 | 563,632,655 | 100% | ||
payslipsitaly | 0 | 575,816,367 | 100% | ||
halftimehydrated | 0 | 575,819,307 | 100% | ||
thusmow | 0 | 563,635,855 | 100% | ||
awesomebinding | 0 | 563,635,855 | 100% | ||
whimperrubbery | 0 | 575,822,576 | 100% | ||
kiraluchkova | 0 | 575,822,576 | 100% | ||
maslov11 | 0 | 563,632,655 | 100% | ||
vasiliytol | 0 | 572,775,896 | 100% | ||
artyr.kalmetov | 0 | 563,632,655 | 100% | ||
bandageweeds | 0 | 563,632,655 | 100% | ||
olgafalatova | 0 | 563,629,777 | 100% | ||
tamarakanakova | 0 | 563,629,777 | 100% | ||
kitgoody | 0 | 563,629,777 | 100% | ||
cubesroom | 0 | 563,629,777 | 100% | ||
seevalhrona | 0 | 563,629,777 | 100% | ||
theythundery | 0 | 563,629,777 | 100% | ||
mereflag | 0 | 563,629,777 | 100% | ||
cliveponie | 0 | 563,629,777 | 100% | ||
snoozesalsa | 0 | 563,629,777 | 100% | ||
loathsomemaps | 0 | 563,626,632 | 100% | ||
infusedbatter | 0 | 563,626,632 | 100% | ||
marcatounique | 0 | 563,626,632 | 100% | ||
anesterov | 0 | 575,813,153 | 100% | ||
vtemnotu | 0 | 575,813,153 | 100% | ||
iauns | 0 | 12,641,725,615 | 100% | ||
vsmirnov3 | 0 | 564,736,672 | 100% | ||
yollardannotlar | 0 | 228,342,679 | 13.5% | ||
criticizemars | 0 | 564,635,488 | 100% | ||
jacekw.dev | 0 | 798,523,338 | 100% | ||
terraceadze | 0 | 563,557,436 | 100% | ||
keepchild | 0 | 563,554,522 | 100% | ||
plankkellogs | 0 | 575,739,484 | 100% | ||
moistmidpoint | 0 | 575,733,647 | 100% | ||
secret.service | 0 | 4,309,012,994 | 10% |
Nice project. Wish you all the best.
author | aburashed |
---|---|
permlink | re-jestemkioskiem-adding-sqlite-support-and-reroll-functionality-to-the-discord-raffle-bot-20180802t000918201z |
category | utopian-io |
json_metadata | {"tags":["utopian-io"],"app":"steemit/0.1"} |
created | 2018-08-02 00:09:24 |
last_update | 2018-08-02 00:09:24 |
depth | 1 |
children | 0 |
last_payout | 2018-08-09 00:09:24 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 36 |
author_reputation | 1,343,255,939,027 |
root_title | "Adding SQLite support & reroll functionality to the Discord Raffle Bot" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 66,815,972 |
net_rshares | 0 |
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!!
author | buckydurddle |
---|---|
permlink | re-jestemkioskiem-adding-sqlite-support-and-reroll-functionality-to-the-discord-raffle-bot-20180804t112811050z |
category | utopian-io |
json_metadata | {"tags":["utopian-io"],"users":["jestemkioskiem","jedigeiss","techslut"],"app":"steemit/0.1"} |
created | 2018-08-04 11:28:09 |
last_update | 2018-08-04 11:28:09 |
depth | 1 |
children | 0 |
last_payout | 2018-08-11 11:28:09 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.018 HBD |
curator_payout_value | 0.005 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 193 |
author_reputation | 101,965,608,464,038 |
root_title | "Adding SQLite support & reroll functionality to the Discord Raffle Bot" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 67,083,507 |
net_rshares | 15,877,046,683 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
jestemkioskiem | 0 | 15,877,046,683 | 30% |
I am really proud of your progress on your Python journey. :) A couple of minor feedbacks: - Indentation levels  I have counted almost 4 indentation levels in the code. For the reader, that makes the program hard to understand. You go into a different state in each if/for/ block. It reminds me [this](https://www.reddit.com/r/ProgrammerHumor/comments/27yykv/indent_hadouken/) :) You can alternatively check the opposite condition and make less levels of indentations. Instead of this: ``` if utils.permission_check(self.author, config.permitted_roles): # ... do stuff # other if/else condifitions ``` This: ``` if not utils.permission_check(self.author, config.permitted_roles): # send permission error return # ... do stuff # other if/else condifitions ``` This will help the code readers a lot since we don't have interpret/remember the code in our heads in every indentation level. - Using a **blocking** SQLite library Asyncio is a non blocking library, thus if you use it you should use all your companian libraries async. [Here](https://github.com/jreese/aiosqlite) is a asyncio portable SQLite library you can find. Running blocking functions in an async environments hurts the application reactivity very [bad on certain cases](https://docs.python.org/3.6/library/asyncio-dev.html#handle-blocking-functions-correctly). Even though, you won't feel the impact in small scale, it's good to use non-blocking libraries with asyncio. *** Your contribution has been evaluated according to [Utopian policies and guidelines](https://join.utopian.io/guidelines), as well as a predefined set of questions pertaining to the category. To view those questions and the relevant answers related to your post, [click here](https://review.utopian.io/result/3/2322211). ---- Need help? Write a ticket on https://support.utopian.io/. Chat with us on [Discord](https://discord.gg/uTyJkNm). [[utopian-moderator]](https://join.utopian.io/)
author | emrebeyler |
---|---|
permlink | re-jestemkioskiem-adding-sqlite-support-and-reroll-functionality-to-the-discord-raffle-bot-20180802t065609592z |
category | utopian-io |
json_metadata | {"tags":["utopian-io"],"image":["https://cdn.steemitimages.com/DQmQTbV7xF5SFZQnVJSdx9VxiAY83fkghx3WSsNNsSgDsww/Screen%20Shot%202018-08-02%20at%209.42.55%20AM.png"],"links":["https://www.reddit.com/r/ProgrammerHumor/comments/27yykv/indent_hadouken/","https://github.com/jreese/aiosqlite","https://docs.python.org/3.6/library/asyncio-dev.html#handle-blocking-functions-correctly","https://join.utopian.io/guidelines","https://review.utopian.io/result/3/2322211","https://support.utopian.io/","https://discord.gg/uTyJkNm","https://join.utopian.io/"],"app":"steemit/0.1"} |
created | 2018-08-02 06:56:09 |
last_update | 2018-08-02 06:56:09 |
depth | 1 |
children | 1 |
last_payout | 2018-08-09 06:56:09 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 2.274 HBD |
curator_payout_value | 0.753 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 2,134 |
author_reputation | 448,535,049,068,622 |
root_title | "Adding SQLite support & reroll functionality to the Discord Raffle Bot" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 66,846,270 |
net_rshares | 1,792,292,955,569 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
espoem | 0 | 17,021,257,979 | 15% | ||
utopian-io | 0 | 1,525,460,758,973 | 1% | ||
emrebeyler | 0 | 198,970,017,942 | 100% | ||
jestemkioskiem | 0 | 50,504,218,494 | 100% | ||
mops2e | 0 | 336,702,181 | 10% |
Hey! Your feedback, as always, is incredible. As a self-learner this provides feedback to the exact issues I'm facing without reading through pages and pages of text that addresses issues I am already aware of. Comments like this are the best part of contributing to Utopian! This is knowledge that will stick with me for the rest of my career when I take it to an actual job. Thank you so much! Stay awesome! Edit: Looked into the indetation, you can find the commit [here](https://github.com/Jestemkioskiem/discord-raffle-bot/commit/524cf045f1dcbf793aa8bf0470f770b0f38ce74b), I'll look into the asyncio issue later today. So expect to be positively surprised the next time you see my contribution here!
author | jestemkioskiem |
---|---|
permlink | re-emrebeyler-re-jestemkioskiem-adding-sqlite-support-and-reroll-functionality-to-the-discord-raffle-bot-20180802t122219931z |
category | utopian-io |
json_metadata | {"tags":["utopian-io"],"app":"busy/2.5.4","community":"busy","format":"markdown","users":[],"links":["https://github.com/Jestemkioskiem/discord-raffle-bot/commit/524cf045f1dcbf793aa8bf0470f770b0f38ce74b"],"image":[]} |
created | 2018-08-02 12:22:21 |
last_update | 2018-08-02 12:49:42 |
depth | 2 |
children | 0 |
last_payout | 2018-08-09 12:22:21 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 708 |
author_reputation | 41,292,066,961,817 |
root_title | "Adding SQLite support & reroll functionality to the Discord Raffle Bot" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 66,871,759 |
net_rshares | 211,400,357 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
apocz | 0 | 211,400,357 | 100% |
**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.](https://steemit.com/@trufflepig/daily-truffle-picks-2018-08-02) 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!](https://steemit.com/steemit/@trufflepig/weekly-truffle-updates-2018-30) Have a nice day and sincerely yours,  *`TrufflePig`*
author | trufflepig |
---|---|
permlink | re-adding-sqlite-support-and-reroll-functionality-to-the-discord-raffle-bot-20180802t213350 |
category | utopian-io |
json_metadata | "" |
created | 2018-08-02 21:33:54 |
last_update | 2018-08-02 21:33:54 |
depth | 1 |
children | 0 |
last_payout | 2018-08-09 21:33:54 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 884 |
author_reputation | 21,266,577,867,113 |
root_title | "Adding SQLite support & reroll functionality to the Discord Raffle Bot" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 66,920,246 |
net_rshares | 0 |
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.** <a href='https://v2.steemconnect.com/sign/account-witness-vote?witness=utopian-io&approve=1'>Vote for Utopian Witness!</a>
author | utopian-io |
---|---|
permlink | re-adding-sqlite-support-and-reroll-functionality-to-the-discord-raffle-bot-20180806t145509z |
category | utopian-io |
json_metadata | "{"app": "beem/0.19.42"}" |
created | 2018-08-06 14:55:09 |
last_update | 2018-08-06 14:55:09 |
depth | 1 |
children | 0 |
last_payout | 2018-08-13 14:55:09 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 306 |
author_reputation | 152,955,367,999,756 |
root_title | "Adding SQLite support & reroll functionality to the Discord Raffle Bot" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 67,306,189 |
net_rshares | 0 |