-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
10da978
commit e571b65
Showing
14 changed files
with
156 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
**/__pycache__/ | ||
.dockerignore | ||
.git/ | ||
.github/ | ||
.gitignore | ||
data/ | ||
docker/ | ||
install.bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,5 +104,6 @@ venv.bak/ | |
|
||
# project specific | ||
client_token | ||
data/ | ||
twitter_api_tokens.json | ||
.vscode/ |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
FROM python:3.8.1-slim | ||
|
||
ARG CLIENT_TOKEN_FILE | ||
ARG TWITTER_API_TOKENS_FILE | ||
|
||
ARG DATABASE_URI | ||
ENV DBURI $DATABASE_URI | ||
|
||
# pull in required files | ||
WORKDIR /home/memebot/ | ||
COPY src src | ||
COPY requirements.txt requirements.txt | ||
COPY $CLIENT_TOKEN_FILE client_token | ||
COPY $TWITTER_API_TOKENS_FILE twitter_api_tokens.json | ||
|
||
# set up virtual environment | ||
ENV VIRTUAL_ENV "/venv" | ||
ENV PATH "$VIRTUAL_ENV/bin:$PATH" | ||
|
||
RUN \ | ||
apt update -y && \ | ||
# gcc is required to build package aiohttp (https://docs.aiohttp.org/en/stable/) required by discord.py | ||
apt install -y gcc && \ | ||
python -m venv $VIRTUAL_ENV && \ | ||
# install dependencies | ||
python -m pip install -r requirements.txt | ||
|
||
# run memebot | ||
CMD python3 src/main.py --database-uri ${DBURI} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
version: '3.1' | ||
|
||
services: | ||
bot: | ||
container_name: memebot-bot | ||
build: | ||
dockerfile: docker/Dockerfile | ||
context: .. | ||
args: | ||
CLIENT_TOKEN_FILE: client_token | ||
TWITTER_API_TOKENS_FILE: twitter_api_tokens.json | ||
DATABASE_URI: "mongodb://db:27017" | ||
restart: always | ||
depends_on: | ||
- db | ||
environment: | ||
PYTHONUNBUFFERED: 1 | ||
networks: | ||
default: | ||
db: | ||
container_name: memebot-db | ||
image: mongo:4.4.4-bionic | ||
restart: always | ||
volumes: | ||
- ../data/db:/data/db | ||
- ../src/config/mongod.yaml:/etc/mongo/mongod.yaml:ro | ||
networks: | ||
default: | ||
|
||
networks: | ||
default: | ||
driver: bridge | ||
ipam: | ||
config: | ||
- subnet: 172.19.0.0/24 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
discord.py | ||
pymongo | ||
python-twitter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import config | ||
from .internals import DatabaseInternals | ||
|
||
db_internals = DatabaseInternals() | ||
|
||
if config.database_enabled: | ||
db_internals.connect() | ||
|
||
|
||
def test() -> bool: | ||
""" | ||
Functions as a "ping" to the databse to ensure that there is an available connection | ||
:return: True if the test succeeds | ||
""" | ||
test_db = db_internals.get_db("test") | ||
test_db.list_collection_names() | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from typing import Optional | ||
|
||
import pymongo as mongo | ||
import pymongo.database | ||
|
||
import config | ||
|
||
|
||
class DatabaseInternals: | ||
""" | ||
Class for managing all database internals that do not need to be exposed to the command programmer. | ||
""" | ||
|
||
def __init__(self): | ||
self.client: Optional[mongo.MongoClient] = None | ||
|
||
def connect(self) -> None: | ||
""" | ||
Create a client connection to a MongoDB database | ||
""" | ||
if self.client is None: | ||
self.client = mongo.MongoClient(config.database_uri.geturl()) | ||
|
||
def get_db(self, db_name: str) -> mongo.database.Database: | ||
return self.client[db_name] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters