Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dockerise bot #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
DISCORD_TOKEN=
COMMITTEE_CHANNEL_ID=
VOTING_CHANNEL_ID=
COMMITTEE_ROLE_ID=
UNION_URL=https://www.guildofstudents.com/organisation/memberlist/6531/?sort=groups
UNION_COOKIE=
SECRETARY_NAME=
SECRETARY_EMAIL=
JOIN_LINK=https://cssbham.com/join
ENABLE_EMAIL_USAGE=0
ENABLE_SHEET_USAGE=0
SHEET_ID=
SMTP_SERVER=localhost
SMTP_PORT=25
[email protected]
SENDER_PASSWORD=
VOTING_CODE=
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ env
.env
token.json
TODO
cogs/__pycache__
utils/__pycache__
data/
.python-version
**/__pycache__
*.bak
*.swp
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM python:3.9-slim-buster

WORKDIR /app

COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt

COPY ./src .

RUN groupadd -r votingbot && useradd --no-log-init -r -g votingbot votingbot
USER votingbot

CMD [ "python3", "main.py" ]

24 changes: 21 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# Society voting-bot
A Discord bot for doing society elections. The voting system used is Instant Runoff Voting.

## Dependencies
pip install -U Discord.py python-dotenv pyrankvote aiorwlock
## Getting started

## Setup
### Setup

You'll need to create a discord bot of your own in the [Discord Developer Portal](https://discord.com/developers/applications) with View Channels and Read Messages permissions. It's also handy if you have an empty server (or "guild") for you to test in. This section of [this guide](https://realpython.com/how-to-make-a-discord-bot-python/#how-to-make-a-discord-bot-in-the-developer-portal) may be helpful to set that up.

Expand Down Expand Up @@ -45,6 +44,25 @@ You can put these in a .env file in the repo directory as it uses dotenv (see [h
You will also need a token.json file to authorise access to the Google Sheets API and a Google account with access to the candidates spreadsheet. [This guide](https://developers.google.com/sheets/api/quickstart/python) will generate the correct token, as long as you set it up to use the "auth/spreadsheets" scope, in both the OAuth Credentials step, and the example code.

Bot requires send message and edit message permissions for full functionality


### Starting the bot

#### Using Docker

docker compose up --build

#### Manually

First install the dependencies:

pip install -r requirements.txt

Then run the main file:

python src/main.py


## Contributions

In short, patches welcome. If you raise a PR, I'll review it, test it, and (probably) merge it.
Expand Down
17 changes: 17 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
services:
votingbot:
build:
context: .
volumes:
- type: bind
source: ./data
target: /app/data
- type: bind
source: ./.env
target: /app/.env
environment:
VOTERS_FILE: data/voters
STANDING_FILE: data/standing
REFERENDA_FILE: data/referenda
NAMES_FILE: data/names

31 changes: 31 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
aiohttp==3.8.3
aiorwlock==1.3.0
aiosignal==1.3.1
async-timeout==4.0.2
attrs==22.1.0
cachetools==5.2.0
certifi==2022.9.24
charset-normalizer==2.1.1
discord.py==2.1.0
frozenlist==1.3.3
google-api-core==2.10.2
google-api-python-client==2.65.0
google-auth==2.14.1
google-auth-httplib2==0.1.0
googleapis-common-protos==1.56.4
httplib2==0.21.0
idna==3.4
multidict==6.0.2
protobuf==4.21.9
pyasn1==0.4.8
pyasn1-modules==0.2.8
pyparsing==3.0.9
pyrankvote==2.0.6
python-dotenv==0.21.0
requests==2.28.1
rsa==4.9
six==1.16.0
tabulate==0.9.0
uritemplate==4.1.1
urllib3==1.26.12
yarl==1.8.1
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.