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.
- Python Discord Bot
- Python-discord-bot
- Note - This project is only for mentees of codess.cafe under open source track
- getting started for contributing
Ensure you have all the required libraries in requirements.txt
.
$ pip3 install -r requirements.txt
To 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
Bot
tab, click onAdd Bot
, and confirm. - Keep the default settings (check
Public bot
and 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 link
for the bot. - Go to the
OAuth2
tab and selectscopes
. - Choose
permissions
for the bot according to your requirements (for this bot, selectingtext permissions
is sufficient). - Next, select the
copy
button above permissions and paste theURL
in the browser. - Choose a server for which you have
Manage Server Permissions
and 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.py
file 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
mssg
list 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
quote
and returns a random quote from theZenQuotes API
. - Scans messages for the word
joke
and returns a random joke from theJoke API
.
The bot detects commands that begin with the command prefix !
and does the following:
- Responds to the
faq
command by searching for auser specified keyword
in the user's message and returning a suitable response. - Responds to the
description
command by returning the description of what the bot does. This is stored as predefined variable. - Responds to the
counter
command 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 API
involves sending a request to this URL which returns aJSON
variable consisting of thequote
which is stored in the identifierq
, andauthor
which is stored in the identifiera
of the returned object. - The
Joke API
involves sending a request to this URL which returns aJSON
variable consisting ofsetup
which is stored in thesetup
identifier, anddelivery
which is stored in the identifierdelivery
of the returned object. Appendingsafe-mod
at 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 Algorithm
programming questions everyday. - The bot
takes input
to record whether the question that day was solved. - The bot responds to
greetings
like "Hi", "Hello", etc. and responds in kind. - The bot responds to the
!description
command and responds with a description of its functionalities. - If the user mentions
quote
in their message, the bot returns a joke using theZenQuotes API
. - If the user mentions
joke
in their message, the bot returns a joke using theJoke API
. - The bot responds to the
count
command and returns the number of questions solved by that user. - The bot responds to the
!faq
command by returning a response tofrequently asked questions
based on akeyword
entered by the user.
NOTE: This project is only for mentees of Codess Cafe under open source track.
- Head over to
issues
tab and grab anygood-first-issue
. - Comment on the issue and ask for it to be assigned to you.
- After the issue is assigned,
fork
the repository and create a local clone. - Get contributing and open a
pull request
to 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!
Refer to CONTRIBUTING.md
for more information!
- 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
LICENSE
file, 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
issues
tab 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 !