diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..c9c5f96 --- /dev/null +++ b/.env.example @@ -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 +SENDER_EMAIL=hello@somewhere.local +SENDER_PASSWORD= +VOTING_CODE= diff --git a/.gitignore b/.gitignore index f27fd3d..48f5977 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,8 @@ env .env token.json TODO -cogs/__pycache__ -utils/__pycache__ +data/ +.python-version +**/__pycache__ *.bak *.swp diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..44318b0 --- /dev/null +++ b/Dockerfile @@ -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" ] + diff --git a/README.md b/README.md index 9d483fd..8e20031 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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. diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..a24fe79 --- /dev/null +++ b/docker-compose.yml @@ -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 + diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..5daef2b --- /dev/null +++ b/requirements.txt @@ -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 diff --git a/__init__.py b/src/__init__.py similarity index 100% rename from __init__.py rename to src/__init__.py diff --git a/cogs/admin.py b/src/cogs/admin.py similarity index 100% rename from cogs/admin.py rename to src/cogs/admin.py diff --git a/cogs/info.py b/src/cogs/info.py similarity index 100% rename from cogs/info.py rename to src/cogs/info.py diff --git a/cogs/running.py b/src/cogs/running.py similarity index 100% rename from cogs/running.py rename to src/cogs/running.py diff --git a/cogs/voting.py b/src/cogs/voting.py similarity index 100% rename from cogs/voting.py rename to src/cogs/voting.py diff --git a/main.py b/src/main.py similarity index 100% rename from main.py rename to src/main.py diff --git a/utils/checkers.py b/src/utils/checkers.py similarity index 100% rename from utils/checkers.py rename to src/utils/checkers.py diff --git a/utils/helpers.py b/src/utils/helpers.py similarity index 100% rename from utils/helpers.py rename to src/utils/helpers.py diff --git a/utils/society_members.py b/src/utils/society_members.py similarity index 100% rename from utils/society_members.py rename to src/utils/society_members.py