Daily DSA Bot
An open source project developed by the mentees of Codess Cafe that involves a discord bot that posts data structures and algorithms questions everyday for daily coding practice.
Codess Cafe provides pro-bono mentorship for collegiate women in tech.
Ensure you have all the required libraries in requirements.txt.
$ pip3 install -r requirements.txtTo run the bot you need to be logged into Discord and have admin access (Manage Server Permissions) to the server where you intend to use the bot.
Clone this repo by following the instructions below:
$ git clone https://github.com/Codess-Cafe/Python-discord-bot.git
$ cd Python-discord-bot
$ python3 bot.py If you have followed the configuration steps, the code in the above repository should activate the discord bot.
- Create a discord account, log in, and navigate to the
application page. - Assign a name to the application and click on
Create. - Head to the
Bottab, click onAdd Bot, and confirm. - Keep the default settings (check
Public botand uncheckRequire OAuth2 Code Grant)
The bot now has an account on Discord!
Copy the token given because it will be needed to log into the bot and use it in your server. Ensure that no one else has access to this token because it gives the owner free access to the bot.
Add the token to bot.py at the head of the file in the following manner:
TOKEN = "YOUR_TOKEN_HERE"- After adding the bot to the server, we need to create an
invite linkfor the bot. - Go to the
OAuth2tab and selectscopes. - Choose
permissionsfor the bot according to your requirements (for this bot, selectingtext permissionsis sufficient). - Next, select the
copybutton above permissions and paste theURLin the browser. - Choose a server for which you have
Manage Server Permissionsand click onAuthorize.
Your bot has now been added to the server!
More information about creating and using Discord bots is available in the Discord Documentation here.
The discord bot is built primarily in Python, making use of the discord.py library.
- Clone the repository and follow the configuration steps. You can run the code either on your local machine or on an online platform such as
repl.it. - If running on your local machine, run the following code in your terminal:
$ python3 bot.py
- The bot should now respond to your messages and commands! The command prefix is specified in the
bot.pyfile as!, so add this prefix to every command sent in the server to get the correct response. For example, try entering the following command in the server:!description
The bot detects messages from all users that are not the bot itself and does the following:
- Scans greetings present in the
mssglist which contains various case insensitive greetings, and if they are present, it returns a random greeting from the greetings array. - Scans messages for the word
quoteand returns a random quote from theZenQuotes API. - Scans messages for the word
jokeand returns a random joke from theJoke API.
The bot detects commands that begin with the command prefix ! and does the following:
- Responds to the
faqcommand by searching for auser specified keywordin the user's message and returning a suitable response. - Responds to the
descriptioncommand by returning the description of what the bot does. This is stored as predefined variable. - Responds to the
countercommand by returning the number of problems solved by the user. This information is retrieved from the count function.
The bot uses external APIs to fetch data required by the user.
- The
ZenQuotes APIinvolves sending a request to this URL which returns aJSONvariable consisting of thequotewhich is stored in the identifierq, andauthorwhich is stored in the identifieraof the returned object. - The
Joke APIinvolves sending a request to this URL which returns aJSONvariable consisting ofsetupwhich is stored in thesetupidentifier, anddeliverywhich is stored in the identifierdeliveryof the returned object. Appendingsafe-modat the end of the request ensures clean, non-explicit jokes.
This website contains more information about the ZenQuotes API.
This website contains more information about the Joke API.
- The bot posts a random
Data Structures and Algorithmprogramming questions everyday. - The bot
takes inputto record whether the question that day was solved. - The bot responds to
greetingslike "Hi", "Hello", etc. and responds in kind. - The bot responds to the
!descriptioncommand and responds with a description of its functionalities. - If the user mentions
quotein their message, the bot returns a joke using theZenQuotes API. - If the user mentions
jokein their message, the bot returns a joke using theJoke API. - The bot responds to the
countcommand and returns the number of questions solved by that user. - The bot responds to the
!faqcommand by returning a response tofrequently asked questionsbased on akeywordentered by the user.
NOTE: This project is only for mentees of Codess Cafe under open source track.
- Head over to
issuestab and grab anygood-first-issue. - Comment on the issue and ask for it to be assigned to you.
- After the issue is assigned,
forkthe repository and create a local clone. - Get contributing and open a
pull requestto get your code added to themain branch!
Add any issues or features that you think will improve the application in the issues tab!
All contributions and features are welcome!
- Repository: https://github.com/Codess-Cafe/Python-discord-bot
- Issue tracker: https://github.com/Codess-Cafe/Python-discord-bot/issues
- Codess Cafe Website: https://codess.cafe/
The code in this project is licensed under MIT license as found in the
LICENSEfile, and below as well.
MIT License
Copyright (c) 2021 Codess.Cafe
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Discord bot for codes.cafe built using python
- head over to
issuestab and grab anygood-first-issue - comment on the issue and ask for it to be assigned
- after the issue is assigned, fork the repo and create a local clone
- get contributing !
