Skip to content

Commit 90032cc

Browse files
authored
Add README, setup, and update scripts :D (#3)
* Add setup.sh, update-ttl.sh, and README
1 parent 49d3536 commit 90032cc

File tree

16 files changed

+1154
-814
lines changed

16 files changed

+1154
-814
lines changed

.env.example

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,37 @@
1+
####
2+
## .ENV INFO
3+
##
4+
# The .env file is an easily-accessible configuration file that allows you to specify certain
5+
# default behaviors for the bot. Any modifications to this file will require a restart to take
6+
# effect. You can restart Discord TTL with the following command:
7+
##
8+
# docker-compose restart
9+
##
10+
####
11+
12+
####
13+
## Variable: DISCORD_BOT_TOKEN
14+
##
15+
# This is an access token that will allow Discord TTL to run on a Discord bot of your choice.
16+
# See https://ayu.dev/r/discord-bot-token-guide to learn how to generate a Discord bot token.
17+
##
18+
####
119
DISCORD_BOT_TOKEN=
2-
# Number of seconds for Discord messages to live until.
3-
# Keep in mind that TTL may not be upheld if Discord is ratelimiting the bot.
4-
# 604800 seconds = 7 days
5-
MESSAGE_TTL=604800
20+
21+
####
22+
## Variable: DEFAULT_MESSAGE_TTL
23+
##
24+
# This field specifies the default number of seconds for Discord messages to live until. Keep
25+
# in mind that TTL may not be upheld if Discord is ratelimiting the bot. Note: TTL can be
26+
# customized server-by-server with commands; This default simply declares what the configuration
27+
# will initially be set as before any commands are used.
28+
##
29+
# Uncomment DEFAULT_MESSAGE_TTL (by removing the # in front of DEFAULT_MESSAGE_TTL below) if
30+
# you would like for a default TTL to be applied to all servers that add this TTL instance.
31+
##
32+
# Comment DEFAULT_MESSAGE_TTL out (by adding a # in front of DEFAULT_MESSAGE_TTL) if you want
33+
# the default TTL to be unset, which will prevent TTL from deleting any messages until a TTL is
34+
# set via server commands.
35+
##
36+
####
37+
DEFAULT_MESSAGE_TTL=604800

.github/workflows/docker-publish.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
# https://github.com/docker/metadata-action
5252
- name: Extract Docker metadata
5353
id: meta
54-
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
54+
uses: docker/metadata-action@v4
5555
with:
5656
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
5757
tags: |
@@ -70,7 +70,6 @@ jobs:
7070
tags: ${{ steps.meta.outputs.tags }}
7171
labels: ${{ steps.meta.outputs.labels }}
7272

73-
7473
# Sign the resulting Docker image digest except on PRs.
7574
# This will only write to the public Rekor transparency log when the Docker
7675
# repository is public to avoid leaking data. If you would like to publish

.github/workflows/tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: Tests
2-
on: [push, pull_request]
2+
on: [push]
33
jobs:
44
tests:
55
name: Tests

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
/node_modules/
33
.env
44
yarn-error.log
5+
*.db
6+
/data/

LICENSE

Lines changed: 21 additions & 674 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Overview
2+
3+
Discord TTL is a simple Discord bot that protects privacy by deleting all server messages older than a given TTL (time-to-live). You can
4+
find a live version of this bot running at https://discord.gg/ayu
5+
6+
Currently, Discord TTL is meant to be self-hosted; Self-hosting comes with a few benefits-- for one, you can guarantee that the bot won't do
7+
anything you wont expect. It also allows you to have ratelimits If you would like to set it up for your server, follow the steps below!
8+
9+
10+
# Steps to self-host
11+
12+
## If you are new to self-hosting
13+
Firsly, I am happy that you are looking to expand your knowledge into this domain! To get started, you'll want a server to host your bot on.
14+
If you already have one, that's great! For my own sanity, this tutorial will only cover the steps to setting up an Ubuntu
15+
server, but it is possible to get Discord TTL running on any OS, so long as you can install
16+
[Docker](https://docs.docker.com/engine/install/ubuntu/) & [Docker Compose](https://docs.docker.com/compose/install/).
17+
18+
If you don't have a VPS yet, you can find them all over the internet :D If you need a recommendation, GalaxyGate's Standard 1GB offers a
19+
perfectly-capable $3/month option that might be within budget for most: https://galaxygate.net/hosting/vps/
20+
21+
## Once you have a suitable location to host the bot
22+
Clone the repository to a desired location (such as your home directory):
23+
```bash
24+
cd ~ && git clone https://github.com/ayubun/discord-ttl
25+
```
26+
Then, navigate to the newly-created `discord-ttl` directory:
27+
```bash
28+
cd discord-ttl
29+
```
30+
Lastly, run the `setup.sh` script. Follow any instructions provided by the script:
31+
```bash
32+
./setup.sh
33+
```
34+
And you're done! :)
35+
36+
**Note**: You will need a Discord bot token from the Discord Developers portal to be able to run Discord TTL. Discord.js has a really
37+
helpful guide on how to get one here: https://ayu.dev/r/discord-bot-token-guide
38+
39+
Once you get a bot token, paste it into the `.env` file where it says `DISCORD_BOT_TOKEN=`

bin/discord-ttl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
# # ================
4+
# # TERMINAL COLORS~
5+
# # ================
6+
# MOVE_UP=`tput cuu 1`
7+
# CLEAR_LINE=`tput el 1`
8+
# BOLD=`tput bold`
9+
# UNDERLINE=`tput smul`
10+
# RED_TEXT=`tput setaf 1`
11+
# GREEN_TEXT=`tput setaf 2`
12+
# YELLOW_TEXT=`tput setaf 3`
13+
# BLUE_TEXT=`tput setaf 4`
14+
# MAGENTA_TEXT=`tput setaf 5`
15+
# CYAN_TEXT=`tput setaf 6`
16+
# WHITE_TEXT=`tput setaf 7`
17+
# RESET=`tput sgr0`
18+
19+
# echo "${RESET}${RED_TEXT}[${BOLD}ERROR${RESET}${RED_TEXT}]${RESET}${BOLD}${YELLOW_TEXT}"

bin/update-ttl.sh

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#!/bin/bash
2+
3+
# ================
4+
# TERMINAL COLORS~
5+
# ================
6+
BOLD=`tput bold`
7+
UNDERLINE=`tput smul`
8+
RED_TEXT=`tput setaf 1`
9+
GREEN_TEXT=`tput setaf 2`
10+
YELLOW_TEXT=`tput setaf 3`
11+
BLUE_TEXT=`tput setaf 4`
12+
RESET=`tput sgr0`
13+
14+
CURRENT_DIR=$(pwd)
15+
# source: https://stackoverflow.com/questions/59895/how-do-i-get-the-directory-where-a-bash-script-is-located-from-within-the-script
16+
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
17+
cd ../$SCRIPT_DIR
18+
19+
# ========================
20+
# UPSTREAM VERSION CHECKER
21+
# ========================
22+
23+
# Reads the version number in package.json
24+
# src: https://gist.github.com/DarrenN/8c6a5b969481725a4413
25+
# + https://stackoverflow.com/questions/428109/extract-substring-in-bash to remove space in front
26+
CURRENT_VERSION=${$(cat package.json \
27+
| grep version \
28+
| head -1 \
29+
| awk -F: '{ print $2 }' \
30+
| sed 's/[",]//g')#* }
31+
32+
# Remove anything past the .'s in CURRENT_VERSION
33+
# src: https://stackoverflow.com/questions/428109/extract-substring-in-bash to remove space in front
34+
CURRENT_MAJOR_VERSION=${CURRENT_VERSION%\.*\.*}
35+
RAW_CONTENT_URL=https://raw.githubusercontent.com/ayubun/discord-ttl/v${CURRENT_MAJOR_VERSION}
36+
37+
# Using the major version, grab the latest package.json version number on the ttl repo
38+
UPSTREAM_VERSION=${$(curl -s ${RAW_CONTENT_URL}/package.json \
39+
| grep version \
40+
| head -1 \
41+
| awk -F: '{ print $2 }' \
42+
| sed 's/[",]//g')#* }
43+
44+
# We will check this JUST in case the major versions are mismatched (this shouldn't happen but /shrug ppl make mistakes)
45+
UPSTREAM_MAJOR_VERSION=${UPSTREAM_VERSION%\.*\.*}
46+
47+
if [[ $CURRENT_MAJOR_VERSION != $UPSTREAM_MAJOR_VERSION ]]; then
48+
echo "${RESET}${RED_TEXT}[${BOLD}ERROR${RESET}${RED_TEXT}]${RESET}${BOLD}${YELLOW_TEXT} The upstream major version is unexpected! The updater will only update the container(s) now.${RESET}"
49+
echo "${RESET}${YELLOW_TEXT}[${BOLD}TTL Updater${RESET}${YELLOW_TEXT}]${RESET}${BOLD}${BLUE_TEXT} Pulling any new docker image(s)...${RESET}"
50+
docker-compose pull
51+
echo "${RESET}${YELLOW_TEXT}[${BOLD}TTL Updater${RESET}${YELLOW_TEXT}]${RESET}${BOLD}${BLUE_TEXT} Upping container(s)...${RESET}"
52+
docker-compose up -d
53+
echo "${RESET}${YELLOW_TEXT}[${BOLD}TTL Updater${RESET}${YELLOW_TEXT}]${RESET}${BOLD}${GREEN_TEXT} Done! Discord TTL container(s) should now be up-to-date :)${RESET}"
54+
return 1
55+
fi
56+
57+
if [[ $CURRENT_VERSION < $UPSTREAM_VERSION ]]; then
58+
# PULL UPDATED SCRIPTS
59+
echo "${RESET}${YELLOW_TEXT}[${BOLD}TTL Updater${RESET}${YELLOW_TEXT}]${RESET}${BOLD}${BLUE_TEXT} Pulling updated scripts...${RESET}"
60+
SETUP_UPDATED=false
61+
if [[ $(curl -s ${RAW_CONTENT_URL}/setup.sh) != $(cat ./setup.sh) ]]; then
62+
SETUP_UPDATED=true
63+
fi
64+
# Currently unneeded \/
65+
# UPDATER_UPDATED=false
66+
# if [[ $(curl -s ${RAW_CONTENT_URL}/bin/update-ttl.sh) != $(cat ./bin/update-ttl.sh) ]]; then
67+
# UPDATER_UPDATED=true
68+
# fi
69+
# BASH_CMD_UPDATED=false
70+
# if [[ $(curl -s ${RAW_CONTENT_URL}/bin/discord-ttl) != $(cat ./bin/discord-ttl) ]]; then
71+
# BASH_CMD_UPDATED=true
72+
# fi
73+
curl -s ${RAW_CONTENT_URL}/setup.sh > ./setup.sh
74+
curl -s ${RAW_CONTENT_URL}/bin/update-ttl.sh > ./bin/update-ttl.sh
75+
curl -s ${RAW_CONTENT_URL}/bin/discord-ttl > ./bin/discord-ttl
76+
# PULL UPDATED DOCKER COMPOSE
77+
echo "${RESET}${YELLOW_TEXT}[${BOLD}TTL Updater${RESET}${YELLOW_TEXT}]${RESET}${BOLD}${BLUE_TEXT} Pulling updated docker compose...${RESET}"
78+
curl -s ${RAW_CONTENT_URL}/docker-compose.yaml > ./docker-compose.yaml
79+
# PULL UPDATED README & .ENV EXAMPLE (I mean, why not, right?)
80+
echo "${RESET}${YELLOW_TEXT}[${BOLD}TTL Updater${RESET}${YELLOW_TEXT}]${RESET}${BOLD}${BLUE_TEXT} Pulling updated README & .env example...${RESET}"
81+
curl -s ${RAW_CONTENT_URL}/README.md > ./README.md
82+
curl -s ${RAW_CONTENT_URL}/.env.example > ./.env.example
83+
# PULL UPDATED PACKAGE.JSON (purely so the new version is reflected)
84+
echo "${RESET}${YELLOW_TEXT}[${BOLD}TTL Updater${RESET}${YELLOW_TEXT}]${RESET}${BOLD}${BLUE_TEXT} Pulling updated package.json (to reflect the updated version)...${RESET}"
85+
curl -s ${RAW_CONTENT_URL}/package.json > ./package.json
86+
if [[ $SETUP_UPDATED == true ]]; then
87+
echo "${RESET}${YELLOW_TEXT}[${BOLD}TTL Updater${RESET}${YELLOW_TEXT}]${RESET}${BOLD}${BLUE_TEXT} Running updated setup.sh...${RESET}"
88+
source ./setup.sh
89+
fi
90+
fi
91+
92+
echo "${RESET}${YELLOW_TEXT}[${BOLD}TTL Updater${RESET}${YELLOW_TEXT}]${RESET}${BOLD}${BLUE_TEXT} Pulling any new docker image(s)...${RESET}"
93+
docker-compose pull
94+
echo "${RESET}${YELLOW_TEXT}[${BOLD}TTL Updater${RESET}${YELLOW_TEXT}]${RESET}${BOLD}${BLUE_TEXT} Upping container(s)...${RESET}"
95+
docker-compose up -d
96+
echo "${RESET}${YELLOW_TEXT}[${BOLD}TTL Updater${RESET}${YELLOW_TEXT}]${RESET}${BOLD}${GREEN_TEXT} Done! Discord TTL should now be up-to-date :)${RESET}"
97+
98+
# Return to whatever location this script was intitally run from for UX purposes
99+
cd $CURRENT_DIR

docker-compose.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ version: '3.8'
22

33
services:
44
discord-ttl:
5-
image: ghcr.io/ayubun/discord-ttl:0
5+
image: ghcr.io/ayubun/discord-ttl:1
6+
restart: always
7+
volumes:
8+
- ${PWD}/data:/usr/src/app/data
69
env_file:
7-
- .env
10+
- .env

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
"name": "discord-ttl",
33
"version": "1.0.0",
44
"main": "dist/app.js",
5-
"repository": "git@github.com:AyuAi/discord-ttl.git",
5+
"repository": "git@github.com:ayubun/discord-ttl.git",
66
"author": "Ayu <ayu@ayu.dev>",
7+
"license": "MIT",
78
"precommit": [
89
"yarn run lint",
910
"yarn run pretty"
@@ -12,10 +13,12 @@
1213
"plugin:you-dont-need-momentjs/recommended"
1314
],
1415
"dependencies": {
16+
"@types/sqlite3": "^3.1.8",
1517
"discord.js": "^13.8.1",
1618
"dotenv": "^16.0.0",
1719
"eslint": "^8.2.0",
1820
"pg": "^8.7.1",
21+
"sqlite3": "^5.1.6",
1922
"ts-node": "^10.4.0",
2023
"typescript": "^4.4.4"
2124
},
@@ -41,5 +44,6 @@
4144
"precommit": "^1.2.2",
4245
"prettier": "^2.6.1",
4346
"ts-node-dev": "^1.1.8"
44-
}
47+
},
48+
"description": "A simple Discord bot to delete server messages older than a specified TTL (time-to-live)"
4549
}

0 commit comments

Comments
 (0)