From 0e84279c66b74ad3c697775723e8bc6d5aef5d61 Mon Sep 17 00:00:00 2001 From: boonebytes Date: Sun, 6 Mar 2022 06:23:27 -0330 Subject: [PATCH 1/5] Updated PMs to send on all anonymous votes, and to PM when vote removed --- models/poll.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/models/poll.py b/models/poll.py index 7cb01a2..15561ac 100644 --- a/models/poll.py +++ b/models/poll.py @@ -1487,6 +1487,7 @@ async def vote(self, user, option, message): if vote: await vote.delete_from_db() await self.refresh(message) + await self.bot.loop.create_task(user.send(f'Your vote for **{self.options_reaction[choice]}** has been REMOVED.')) return # check if already voted for the same choice @@ -1524,7 +1525,7 @@ async def vote(self, user, option, message): if not answer or answer.lower() == "-": answer = "No Answer" - if self.anonymous and self.hide_count: + if self.anonymous or self.hide_count: self.bot.loop.create_task(user.send(f'Your vote for **{self.options_reaction[choice]}** has been counted.')) # commit From fafba22ffb9bf7de908d3848a38c686c72e8a5a7 Mon Sep 17 00:00:00 2001 From: boonebytes Date: Sun, 6 Mar 2022 09:11:44 -0330 Subject: [PATCH 2/5] Docker config and related files, ignores, etc. --- .dockerignore | 1 + .gitignore | 5 ++- Dockerfile | 15 ++++++++ docker-compose.yml | 26 ++++++++++++++ docker-requirements.txt | 38 ++++++++++++++++++++ docker.md | 78 +++++++++++++++++++++++++++++++++++++++++ mongo-init.js | 15 ++++++++ setup.md | 3 +- 8 files changed, 179 insertions(+), 2 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 docker-requirements.txt create mode 100644 docker.md create mode 100644 mongo-init.js diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..8fce603 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +data/ diff --git a/.gitignore b/.gitignore index 02c3087..8025234 100644 --- a/.gitignore +++ b/.gitignore @@ -16,4 +16,7 @@ export/ *.pyc #backup -backup/ \ No newline at end of file +backup/ + +# Docker development - data for mongodb +data/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0744b51 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM python:3.7 + +WORKDIR /usr/src/ + +RUN pip install --upgrade pip + +COPY docker-requirements.txt ./requirements.txt +RUN pip install --no-cache-dir -r requirements.txt + +VOLUME [ "/usr/src/app" ] +WORKDIR /usr/src/app/ + +#ENTRYPOINT [ "python", "/usr/src/app/pollmaster.py" ] +ENTRYPOINT [ "python", "/usr/src/app/launcher.py" ] + diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..1cccd34 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,26 @@ +version: "3.5" +services: + bot: + build: . + links: + - "mongodb:db" + volumes: + - type: bind + source: . + target: /usr/src/app + mongodb: + image: mongo:5.0.5 + environment: + - MONGO_INITDB_ROOT_USERNAME=pmroot + - MONGO_INITDB_ROOT_PASSWORD=changeme + volumes: + - type: bind + source: ./data + target: /data/db + - type: bind + source: ./mongo-init.js + target: /docker-entrypoint-initdb.d/mongo-init.js + read_only: true + ports: + - "27107:27107" + diff --git a/docker-requirements.txt b/docker-requirements.txt new file mode 100644 index 0000000..909c044 --- /dev/null +++ b/docker-requirements.txt @@ -0,0 +1,38 @@ +# This file adjusts some of the dependencies to a +# version that seems to function in Docker. If +# the main requirements.txt file is updated, those +# changes could also be made in here. If this file +# becomes an exact match to requirements.txt, update +# Dockerfile to reference requirements.txt, then +# delete this file. +aiohttp==3.7.4 +async-timeout==3.0.1 +asyncpg==0.21.0 +attrs==20.2.0 +certifi==2020.6.20 +chardet==3.0.4 +cycler==0.10.0 +dateparser==0.7.4 +dblpy==0.4.0 +discord.py==1.6.0 +idna==2.10 +idna-ssl==1.1.0 +kiwisolver==1.3.1 +matplotlib==3.2.1 +motor==2.3.0 +multidict==5.0.0 +numpy==1.19.2 +pymongo==3.11.0 +pyparsing==2.4.7 +python-dateutil==2.8.1 +pytz==2020.1 +ratelimiter==1.2.0.post0 +regex==2020.10.23 +requests==2.24.0 +six==1.15.0 +typing-extensions==3.7.4.3 +tzlocal==2.1 +Unidecode==1.1.1 +urllib3==1.25.11 +websockets==8.1 +yarl==1.4.2 diff --git a/docker.md b/docker.md new file mode 100644 index 0000000..439396a --- /dev/null +++ b/docker.md @@ -0,0 +1,78 @@ +# Setting up Pollmaster for Docker Development + +## Purpose + +These instructions are intended to help configure a development environment. They have not been designed or written with considerations for security, and are therefore not appropriate to run in a production environment. + +## Requirements + +These steps have been tested on Ubuntu 20.04 + +[Docker Engine: Community](https://docs.docker.com/install/linux/docker-ce/ubuntu/) + +## Installation + +Execute the following commands from a terminal window: +```sh +git clone https://github.com/matnad/pollmaster.git +cd pollmaster +``` +## Setup app and bot in Discord + +- Setup an app and a bot using [Creating a Bot Account](https://discordpy.readthedocs.io/en/latest/discord.html#creating-a-bot-account) + +## Running the application + +- Create a secrets.py in essentials folder in the project. You can use the following template + +```python +class Secrets: + def __init__(self): + self.dbl_token = '' # DBL token (only needed for public bot) + self.mongo_db = 'mongodb://username:password@db:27017/pollmaster' # Replace with credentials in mongo-init.js + self.bot_token = '' # official discord bot token + self.mode = 'development' # or production + +SECRETS = Secrets() +``` + +- Update essentials/settings.py ; set the owner\_id to the developer's User ID in Discord +- Run the following commands from a terminal window, within the pollmaster working directory: +```sh +docker-compose build +docker-compose up -d +``` +- When making changes to the Python code, run these commands to restart the bot: +```sh +docker stop pollmaster_bot_1 +docker start pollmaster_bot_1 +``` + +## Invite the bot in Discord + +- Generate url to invite the bot using [Inviting Your Bot](https://discordpy.readthedocs.io/en/latest/discord.html#inviting-your-bot) +- Specify permissions by using the following bit format of the bot permissions appended to the bot invitation url and paste the url in browser and follow the instructions as given in the above url + +> &permissions=1073867840 + +- Now you will see the bot in your Discord channel +- Try commands like pm!help and pm!new + +## Log files + +- You can view the log file pollmaster.log in the pollmaster directory +- These commands will also output anything from the two docker containers: +```sh +docker logs pollmaster_bot_1 +docker logs pollmaster_mongodb_1 +``` + +## Cleanup + +When finished development work, run this command from the pollmaster working copy to remove the docker containers: +```sh +docker-compose down +``` + +If you would like to clear the MongoDB database files, remove the data/ directory as well. + diff --git a/mongo-init.js b/mongo-init.js new file mode 100644 index 0000000..621f0e9 --- /dev/null +++ b/mongo-init.js @@ -0,0 +1,15 @@ +db = db.getSiblingDB('pollmaster'); + +db.createUser( + { + user: "pm", + pwd: "pwdhere", + roles: [ + { + role: "dbOwner", + db: "pollmaster" + } + ] + } +); + diff --git a/setup.md b/setup.md index 50c8217..31919b2 100644 --- a/setup.md +++ b/setup.md @@ -37,6 +37,7 @@ class Secrets: SECRETS = Secrets() ``` +- Update essentials/settings.py ; set the owner\_id to the developer's User ID in Discord - Run the application using python pollmaster.py - You can see the following : ``` @@ -55,4 +56,4 @@ Servers verified. Bot running. ## Log files -- You can view the log file pollmaster.log in the pollmaster directory \ No newline at end of file +- You can view the log file pollmaster.log in the pollmaster directory From 7e06476989f0a2d6f5da44bcbd0e39e51da74955 Mon Sep 17 00:00:00 2001 From: boonebytes Date: Sun, 6 Mar 2022 09:24:15 -0330 Subject: [PATCH 3/5] Updated docker readme, removed unrelated change --- docker.md | 1 + models/poll.py | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docker.md b/docker.md index 439396a..54709cb 100644 --- a/docker.md +++ b/docker.md @@ -16,6 +16,7 @@ Execute the following commands from a terminal window: ```sh git clone https://github.com/matnad/pollmaster.git cd pollmaster +mkdir data ``` ## Setup app and bot in Discord diff --git a/models/poll.py b/models/poll.py index 15561ac..7cb01a2 100644 --- a/models/poll.py +++ b/models/poll.py @@ -1487,7 +1487,6 @@ async def vote(self, user, option, message): if vote: await vote.delete_from_db() await self.refresh(message) - await self.bot.loop.create_task(user.send(f'Your vote for **{self.options_reaction[choice]}** has been REMOVED.')) return # check if already voted for the same choice @@ -1525,7 +1524,7 @@ async def vote(self, user, option, message): if not answer or answer.lower() == "-": answer = "No Answer" - if self.anonymous or self.hide_count: + if self.anonymous and self.hide_count: self.bot.loop.create_task(user.send(f'Your vote for **{self.options_reaction[choice]}** has been counted.')) # commit From 4d250e3bef30a47f04415917f570c0f08177780a Mon Sep 17 00:00:00 2001 From: boonebytes Date: Fri, 11 Mar 2022 06:06:40 -0330 Subject: [PATCH 4/5] Updated docker requirements based on feedback from Pollmaster Support Discord --- docker-requirements.txt | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/docker-requirements.txt b/docker-requirements.txt index 909c044..6d4ebb2 100644 --- a/docker-requirements.txt +++ b/docker-requirements.txt @@ -1,11 +1,4 @@ -# This file adjusts some of the dependencies to a -# version that seems to function in Docker. If -# the main requirements.txt file is updated, those -# changes could also be made in here. If this file -# becomes an exact match to requirements.txt, update -# Dockerfile to reference requirements.txt, then -# delete this file. -aiohttp==3.7.4 +aiohttp async-timeout==3.0.1 asyncpg==0.21.0 attrs==20.2.0 @@ -13,14 +6,14 @@ certifi==2020.6.20 chardet==3.0.4 cycler==0.10.0 dateparser==0.7.4 -dblpy==0.4.0 -discord.py==1.6.0 +dblpy==0.3.4 +discord.py==1.5.1 idna==2.10 idna-ssl==1.1.0 -kiwisolver==1.3.1 +kiwisolver==1.3.0 matplotlib==3.2.1 motor==2.3.0 -multidict==5.0.0 +multidict numpy==1.19.2 pymongo==3.11.0 pyparsing==2.4.7 From caf90eba89cd57c2c182011f6ec584a631bea216 Mon Sep 17 00:00:00 2001 From: Jeffrey Boone Date: Fri, 11 Mar 2022 06:11:28 -0330 Subject: [PATCH 5/5] Added comment to docker requirements --- docker-requirements.txt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docker-requirements.txt b/docker-requirements.txt index 6d4ebb2..3f9b744 100644 --- a/docker-requirements.txt +++ b/docker-requirements.txt @@ -1,3 +1,10 @@ +# This file adjusts some of the dependencies to a +# version that seems to function in Docker. If +# the main requirements.txt file is updated, those +# changes could also be made in here. If this file +# becomes an exact match to requirements.txt, update +# Dockerfile to reference requirements.txt, then +# delete this file. aiohttp async-timeout==3.0.1 asyncpg==0.21.0