Skip to content

Commit

Permalink
First pass at adding the Discord bot
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterJCLaw committed Oct 4, 2023
1 parent 68a11b1 commit 9f03aed
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 0 deletions.
5 changes: 5 additions & 0 deletions roles/discord-gated-entry/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Discord Gated Entry

A Bot for gating entry to a Discord server.

This is a deployment of <https://github.com/srobo/discord-gated-entry>.
4 changes: 4 additions & 0 deletions roles/discord-gated-entry/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- name: Restart discord-gated-entry
service:
name: discord-gated-entry
state: restarted
61 changes: 61 additions & 0 deletions roles/discord-gated-entry/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
- name: Install virtualenv system dependencies
apt:
pkg:
- python3-virtualenv
- python3-wheel

- name: Create user
user:
name: discord
shell: /bin/nologin
state: present

- name: Create install directory
file:
path: "{{ install_dir }}"
state: directory
owner: discord
mode: "755"

- name: Download
git:
repo: https://github.com/srobo/discord-gated-entry
dest: "{{ install_dir }}"
force: true
version: 476a9c942f580e2950048c2b95e15429cb0ae33d
notify:
Restart discord-gated-entry
register: discord_gated_entry_repo
become_user: discord

- name: Bootstrap environment file
file:
state: touch
dest: "{{ install_dir }}/.env"
mode: "0600"
owner: discord
notify:
Restart discord-gated-entry

- name: Install virtual environment
pip:
virtualenv: "{{ venv_dir }}"
requirements: "{{ install_dir }}/requirements.txt"
notify:
Restart discord-gated-entry
become_user: discord
when: discord_gated_entry_repo.changed # noqa: no-handler - Use a handler to ensure execution order

- name: Install systemd service
template:
src: discord-gated-entry.service
dest: /etc/systemd/system/discord-gated-entry.service
mode: "0644"
notify:
Restart discord-gated-entry

- name: Enable service
service:
name: discord-gated-entry
state: started
enabled: true
16 changes: 16 additions & 0 deletions roles/discord-gated-entry/templates/discord-gated-entry.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[Unit]
Description=Discord bot for gated entry
After=network.target

[Service]
User=discord

Type=simple

WorkingDirectory={{ install_dir }}
RuntimeDirectory=discord-gated-entry

ExecStart=/srv/discord-gated-entry/venv/bin/python main.py

[Install]
WantedBy=multi-user.target
2 changes: 2 additions & 0 deletions roles/discord-gated-entry/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
install_dir: /srv/discord-gated-entry
venv_dir: "{{ install_dir }}/venv"

0 comments on commit 9f03aed

Please sign in to comment.