-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add README, setup, and update scripts :D (#3)
* Add setup.sh, update-ttl.sh, and README
- Loading branch information
Showing
16 changed files
with
1,154 additions
and
814 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,37 @@ | ||
#### | ||
## .ENV INFO | ||
## | ||
# The .env file is an easily-accessible configuration file that allows you to specify certain | ||
# default behaviors for the bot. Any modifications to this file will require a restart to take | ||
# effect. You can restart Discord TTL with the following command: | ||
## | ||
# docker-compose restart | ||
## | ||
#### | ||
|
||
#### | ||
## Variable: DISCORD_BOT_TOKEN | ||
## | ||
# This is an access token that will allow Discord TTL to run on a Discord bot of your choice. | ||
# See https://ayu.dev/r/discord-bot-token-guide to learn how to generate a Discord bot token. | ||
## | ||
#### | ||
DISCORD_BOT_TOKEN= | ||
# Number of seconds for Discord messages to live until. | ||
# Keep in mind that TTL may not be upheld if Discord is ratelimiting the bot. | ||
# 604800 seconds = 7 days | ||
MESSAGE_TTL=604800 | ||
|
||
#### | ||
## Variable: DEFAULT_MESSAGE_TTL | ||
## | ||
# This field specifies the default number of seconds for Discord messages to live until. Keep | ||
# in mind that TTL may not be upheld if Discord is ratelimiting the bot. Note: TTL can be | ||
# customized server-by-server with commands; This default simply declares what the configuration | ||
# will initially be set as before any commands are used. | ||
## | ||
# Uncomment DEFAULT_MESSAGE_TTL (by removing the # in front of DEFAULT_MESSAGE_TTL below) if | ||
# you would like for a default TTL to be applied to all servers that add this TTL instance. | ||
## | ||
# Comment DEFAULT_MESSAGE_TTL out (by adding a # in front of DEFAULT_MESSAGE_TTL) if you want | ||
# the default TTL to be unset, which will prevent TTL from deleting any messages until a TTL is | ||
# set via server commands. | ||
## | ||
#### | ||
DEFAULT_MESSAGE_TTL=604800 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
name: Tests | ||
on: [push, pull_request] | ||
on: [push] | ||
jobs: | ||
tests: | ||
name: Tests | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ | |
/node_modules/ | ||
.env | ||
yarn-error.log | ||
*.db | ||
/data/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Overview | ||
|
||
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 | ||
find a live version of this bot running at https://discord.gg/ayu | ||
|
||
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 | ||
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! | ||
|
||
|
||
# Steps to self-host | ||
|
||
## If you are new to self-hosting | ||
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. | ||
If you already have one, that's great! For my own sanity, this tutorial will only cover the steps to setting up an Ubuntu | ||
server, but it is possible to get Discord TTL running on any OS, so long as you can install | ||
[Docker](https://docs.docker.com/engine/install/ubuntu/) & [Docker Compose](https://docs.docker.com/compose/install/). | ||
|
||
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 | ||
perfectly-capable $3/month option that might be within budget for most: https://galaxygate.net/hosting/vps/ | ||
|
||
## Once you have a suitable location to host the bot | ||
Clone the repository to a desired location (such as your home directory): | ||
```bash | ||
cd ~ && git clone https://github.com/ayubun/discord-ttl | ||
``` | ||
Then, navigate to the newly-created `discord-ttl` directory: | ||
```bash | ||
cd discord-ttl | ||
``` | ||
Lastly, run the `setup.sh` script. Follow any instructions provided by the script: | ||
```bash | ||
./setup.sh | ||
``` | ||
And you're done! :) | ||
|
||
**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 | ||
helpful guide on how to get one here: https://ayu.dev/r/discord-bot-token-guide | ||
|
||
Once you get a bot token, paste it into the `.env` file where it says `DISCORD_BOT_TOKEN=` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/bash | ||
|
||
# # ================ | ||
# # TERMINAL COLORS~ | ||
# # ================ | ||
# MOVE_UP=`tput cuu 1` | ||
# CLEAR_LINE=`tput el 1` | ||
# BOLD=`tput bold` | ||
# UNDERLINE=`tput smul` | ||
# RED_TEXT=`tput setaf 1` | ||
# GREEN_TEXT=`tput setaf 2` | ||
# YELLOW_TEXT=`tput setaf 3` | ||
# BLUE_TEXT=`tput setaf 4` | ||
# MAGENTA_TEXT=`tput setaf 5` | ||
# CYAN_TEXT=`tput setaf 6` | ||
# WHITE_TEXT=`tput setaf 7` | ||
# RESET=`tput sgr0` | ||
|
||
# echo "${RESET}${RED_TEXT}[${BOLD}ERROR${RESET}${RED_TEXT}]${RESET}${BOLD}${YELLOW_TEXT}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#!/bin/bash | ||
|
||
# ================ | ||
# TERMINAL COLORS~ | ||
# ================ | ||
BOLD=`tput bold` | ||
UNDERLINE=`tput smul` | ||
RED_TEXT=`tput setaf 1` | ||
GREEN_TEXT=`tput setaf 2` | ||
YELLOW_TEXT=`tput setaf 3` | ||
BLUE_TEXT=`tput setaf 4` | ||
RESET=`tput sgr0` | ||
|
||
CURRENT_DIR=$(pwd) | ||
# source: https://stackoverflow.com/questions/59895/how-do-i-get-the-directory-where-a-bash-script-is-located-from-within-the-script | ||
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) | ||
cd ../$SCRIPT_DIR | ||
|
||
# ======================== | ||
# UPSTREAM VERSION CHECKER | ||
# ======================== | ||
|
||
# Reads the version number in package.json | ||
# src: https://gist.github.com/DarrenN/8c6a5b969481725a4413 | ||
# + https://stackoverflow.com/questions/428109/extract-substring-in-bash to remove space in front | ||
CURRENT_VERSION=${$(cat package.json \ | ||
| grep version \ | ||
| head -1 \ | ||
| awk -F: '{ print $2 }' \ | ||
| sed 's/[",]//g')#* } | ||
|
||
# Remove anything past the .'s in CURRENT_VERSION | ||
# src: https://stackoverflow.com/questions/428109/extract-substring-in-bash to remove space in front | ||
CURRENT_MAJOR_VERSION=${CURRENT_VERSION%\.*\.*} | ||
RAW_CONTENT_URL=https://raw.githubusercontent.com/ayubun/discord-ttl/v${CURRENT_MAJOR_VERSION} | ||
|
||
# Using the major version, grab the latest package.json version number on the ttl repo | ||
UPSTREAM_VERSION=${$(curl -s ${RAW_CONTENT_URL}/package.json \ | ||
| grep version \ | ||
| head -1 \ | ||
| awk -F: '{ print $2 }' \ | ||
| sed 's/[",]//g')#* } | ||
|
||
# We will check this JUST in case the major versions are mismatched (this shouldn't happen but /shrug ppl make mistakes) | ||
UPSTREAM_MAJOR_VERSION=${UPSTREAM_VERSION%\.*\.*} | ||
|
||
if [[ $CURRENT_MAJOR_VERSION != $UPSTREAM_MAJOR_VERSION ]]; then | ||
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}" | ||
echo "${RESET}${YELLOW_TEXT}[${BOLD}TTL Updater${RESET}${YELLOW_TEXT}]${RESET}${BOLD}${BLUE_TEXT} Pulling any new docker image(s)...${RESET}" | ||
docker-compose pull | ||
echo "${RESET}${YELLOW_TEXT}[${BOLD}TTL Updater${RESET}${YELLOW_TEXT}]${RESET}${BOLD}${BLUE_TEXT} Upping container(s)...${RESET}" | ||
docker-compose up -d | ||
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}" | ||
return 1 | ||
fi | ||
|
||
if [[ $CURRENT_VERSION < $UPSTREAM_VERSION ]]; then | ||
# PULL UPDATED SCRIPTS | ||
echo "${RESET}${YELLOW_TEXT}[${BOLD}TTL Updater${RESET}${YELLOW_TEXT}]${RESET}${BOLD}${BLUE_TEXT} Pulling updated scripts...${RESET}" | ||
SETUP_UPDATED=false | ||
if [[ $(curl -s ${RAW_CONTENT_URL}/setup.sh) != $(cat ./setup.sh) ]]; then | ||
SETUP_UPDATED=true | ||
fi | ||
# Currently unneeded \/ | ||
# UPDATER_UPDATED=false | ||
# if [[ $(curl -s ${RAW_CONTENT_URL}/bin/update-ttl.sh) != $(cat ./bin/update-ttl.sh) ]]; then | ||
# UPDATER_UPDATED=true | ||
# fi | ||
# BASH_CMD_UPDATED=false | ||
# if [[ $(curl -s ${RAW_CONTENT_URL}/bin/discord-ttl) != $(cat ./bin/discord-ttl) ]]; then | ||
# BASH_CMD_UPDATED=true | ||
# fi | ||
curl -s ${RAW_CONTENT_URL}/setup.sh > ./setup.sh | ||
curl -s ${RAW_CONTENT_URL}/bin/update-ttl.sh > ./bin/update-ttl.sh | ||
curl -s ${RAW_CONTENT_URL}/bin/discord-ttl > ./bin/discord-ttl | ||
# PULL UPDATED DOCKER COMPOSE | ||
echo "${RESET}${YELLOW_TEXT}[${BOLD}TTL Updater${RESET}${YELLOW_TEXT}]${RESET}${BOLD}${BLUE_TEXT} Pulling updated docker compose...${RESET}" | ||
curl -s ${RAW_CONTENT_URL}/docker-compose.yaml > ./docker-compose.yaml | ||
# PULL UPDATED README & .ENV EXAMPLE (I mean, why not, right?) | ||
echo "${RESET}${YELLOW_TEXT}[${BOLD}TTL Updater${RESET}${YELLOW_TEXT}]${RESET}${BOLD}${BLUE_TEXT} Pulling updated README & .env example...${RESET}" | ||
curl -s ${RAW_CONTENT_URL}/README.md > ./README.md | ||
curl -s ${RAW_CONTENT_URL}/.env.example > ./.env.example | ||
# PULL UPDATED PACKAGE.JSON (purely so the new version is reflected) | ||
echo "${RESET}${YELLOW_TEXT}[${BOLD}TTL Updater${RESET}${YELLOW_TEXT}]${RESET}${BOLD}${BLUE_TEXT} Pulling updated package.json (to reflect the updated version)...${RESET}" | ||
curl -s ${RAW_CONTENT_URL}/package.json > ./package.json | ||
if [[ $SETUP_UPDATED == true ]]; then | ||
echo "${RESET}${YELLOW_TEXT}[${BOLD}TTL Updater${RESET}${YELLOW_TEXT}]${RESET}${BOLD}${BLUE_TEXT} Running updated setup.sh...${RESET}" | ||
source ./setup.sh | ||
fi | ||
fi | ||
|
||
echo "${RESET}${YELLOW_TEXT}[${BOLD}TTL Updater${RESET}${YELLOW_TEXT}]${RESET}${BOLD}${BLUE_TEXT} Pulling any new docker image(s)...${RESET}" | ||
docker-compose pull | ||
echo "${RESET}${YELLOW_TEXT}[${BOLD}TTL Updater${RESET}${YELLOW_TEXT}]${RESET}${BOLD}${BLUE_TEXT} Upping container(s)...${RESET}" | ||
docker-compose up -d | ||
echo "${RESET}${YELLOW_TEXT}[${BOLD}TTL Updater${RESET}${YELLOW_TEXT}]${RESET}${BOLD}${GREEN_TEXT} Done! Discord TTL should now be up-to-date :)${RESET}" | ||
|
||
# Return to whatever location this script was intitally run from for UX purposes | ||
cd $CURRENT_DIR |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,9 @@ | |
"name": "discord-ttl", | ||
"version": "1.0.0", | ||
"main": "dist/app.js", | ||
"repository": "[email protected]:AyuAi/discord-ttl.git", | ||
"repository": "[email protected]:ayubun/discord-ttl.git", | ||
"author": "Ayu <[email protected]>", | ||
"license": "MIT", | ||
"precommit": [ | ||
"yarn run lint", | ||
"yarn run pretty" | ||
|
@@ -12,10 +13,12 @@ | |
"plugin:you-dont-need-momentjs/recommended" | ||
], | ||
"dependencies": { | ||
"@types/sqlite3": "^3.1.8", | ||
"discord.js": "^13.8.1", | ||
"dotenv": "^16.0.0", | ||
"eslint": "^8.2.0", | ||
"pg": "^8.7.1", | ||
"sqlite3": "^5.1.6", | ||
"ts-node": "^10.4.0", | ||
"typescript": "^4.4.4" | ||
}, | ||
|
@@ -41,5 +44,6 @@ | |
"precommit": "^1.2.2", | ||
"prettier": "^2.6.1", | ||
"ts-node-dev": "^1.1.8" | ||
} | ||
}, | ||
"description": "A simple Discord bot to delete server messages older than a specified TTL (time-to-live)" | ||
} |
Oops, something went wrong.