Skip to content
This repository was archived by the owner on May 17, 2021. It is now read-only.
/ daily-bot Public archive

The bot that gives daily coding questions on CSCH.

License

Notifications You must be signed in to change notification settings

cscareerhub/daily-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

a9229ab · Nov 4, 2020
Jun 5, 2019
Sep 7, 2019
Mar 5, 2019
Jan 17, 2019
Jan 7, 2019
Dec 26, 2018
Oct 2, 2019
Jan 17, 2019
Nov 4, 2020
Jan 14, 2019
Sep 7, 2019
Nov 4, 2020
Nov 4, 2020
Nov 4, 2020

Repository files navigation

Build Status Discord Chat License Coverage Status

Daily-Bot

A bot that outputs coding questions on a daily basis.

Setup

Docker

Prerequisites:

  • docker (obviously)
  • docker-compose

Installation

  • Clone this repository into folder of choice.
  • Modify docker-compose.yml to change the default password and username under db.environment. I am not being held liable if stuff goes missing because you chose u:postgres p:postgres for login.
  • NOTE: If you have PostgreSQL installed on your host you will also have to do the following in docker-compose.yml:
db:
    image: postgres:latest
    restart: always
    ports:
      - '5432:5432'

Should have the port changed to read 5431:5432 (or whatever host port isn't taken as Postgres defaults to 5432) as can be seen below:

db:
    image: postgres:latest
    restart: always
    ports:
      - '5431:5432'
  • Create a .env file in current directory (look below for how the variables should appear, under Normal Script Installation).
  • Run docker-compose run -d --build from current directory

Normal Script

Prerequisites:

  • Python 3.4.2+
  • PostgreSQL
  • pip3 (or have pip reference Python 3 installation)

Installation

Note: this should be pretty generic among all Linux, MacOS, and Windows systems.

  • Run service postgresql start to enable the Postgres server. Note: this step may get removed in the future for dockerfile.
  • Move into the directory with main.py
  • Run pip3 install -r requirements.txt (or pip install -r requirements.txt depending on Python versions)
  • Create a .env file in the current directory. It should contain the following variables:
TOKEN=<Discord Developer Token>
USERNAME=<PostgreSQL account username for bot>
PASSWORD=<PostgreSQL account password for bot>

Note here that you will need to create an account for the postgres user manually, as well as the dailybot database.

  • Run python3 main.py (or again depending on install python main.py could suffice).
    If successful, this should be present on the terminal:
Logged in as
Daily-Bot
00000000000000 # This will vary as it is the Bot ID
------

Usage

Adding a Question

To add a question all you simply have to do is private message the bot the question you want to be added.
It should be inside triple backticks e.g)

```
Company that Asked
Key Data Structure Used
Actual Question
```

The bot will reply with what the person should see after minor editing. Reply YES to save the question to the database, NO (or anything else) to remove from cache and for you to reformat if needed.
NOTE: Body is unique so if you try add a question that is already in the database, you will be notified that it failed.

Showing a Question

In the given channel (daily-coding-challenge by default), enter >q or >show_question to get the corresponding question. This will automatically update on a daily basis.

If you provide a number index after command e.g >q 4 it will show the question with the xth index (in this case it will be the 4th). To find the index of the questions, list through them in >lq as is explained in Index found by [listing questions](README.md#Listing Questions)..

Listing Questions

>lq will list the first 10 questions that were input into the database. By providing an integer after command, e.g >lq 10 you will get 10 questions starting from provided index.
NOTE: indexing starts at 1, not 0.

Removing a Question

>del <index> e.g >del 10 deletes a question with given index. Index found by [listing questions](README.md#Listing Questions). If the question is the day's question, a new one will be found.

Editing Questions

>edit <index> e.g >edit 10 adds a person to an editor cache. PM the bot with just the new body of the question to update it. Index found by [listing questions](README.md#Listing Questions) or looking at the top left of a question when it is presented. Format for PMing bot:

```
New Body of question
```

Known Caveats

  • When using docker you will need to run docker-compose up twice. First time to initialize everything, then docker-compose down and up again to restart. Otherwise the Python script will not have access to the backing database.

About

The bot that gives daily coding questions on CSCH.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published