├── .gitignore ├── YearProgressBot.service ├── LICENSE ├── README.md └── main.sh /.gitignore: -------------------------------------------------------------------------------- 1 | bar 2 | -------------------------------------------------------------------------------- /YearProgressBot.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Year Progress Bot 3 | After=network-online.target 4 | 5 | [Service] 6 | Type=simple 7 | Environment="LENGTH=20" 8 | Environment="API_TOKEN=123456789:ABCdEFGHIJKLMnop1QrSt2Uv3Wx_yzaBCdef" 9 | Environment="CHAT_ID=-1234567890" 10 | Environment="WORKDIR=/path/to/YearProgressBot" 11 | ExecStart=/bin/bash /path/to/YearProgressBot/main.sh 12 | Restart=always 13 | User=nobody 14 | 15 | [Install] 16 | WantedBy=multi-user.target 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | DO WHAT THE FUCK YOU WANT TO BUT IT'S NOT MY FAULT PUBLIC LICENSE 2 | Version 1, October 2013 3 | 4 | Copyright © 2013 Ben McGinnes 5 | 6 | Everyone is permitted to copy and distribute verbatim or modified 7 | copies of this license document, and changing it is allowed as long 8 | as the name is changed. 9 | 10 | DO WHAT THE FUCK YOU WANT TO BUT IT'S NOT MY FAULT PUBLIC LICENSE 11 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 12 | 13 | 0. You just DO WHAT THE FUCK YOU WANT TO. 14 | 15 | 1. Do not hold the author(s), creator(s), developer(s) or 16 | distributor(s) liable for anything that happens or goes wrong 17 | with your use of the work. 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | YearProgressBot 2 | =============== 3 | 4 | \\\ YearProgressBot /// written in Bash, for Telegram. 5 | 6 | Deployment 7 | ---------- 8 | 9 | 1. Clone the reposistory: 10 | ``` 11 | $ git clone https://github.com/RedL0tus/YearProgressBot.git 12 | ``` 13 | 14 | 2. Copy and modify the systemd unit file: 15 | Use your favourite editor to replace the dummy environment variables with yours. Don't forget to change the path at `ExecStart` as well. 16 | ``` 17 | # cp YearProgressBot.service /etc/systemd/system/YearProgressBot.service 18 | # nano /etc/systemd/system/YearProgressBot.service 19 | ``` 20 | 21 | 3. Start the bot 22 | ``` 23 | # systemctl start YearProgressBot 24 | ``` 25 | 26 | License 27 | ------- 28 | 29 | WTFNMFPLv1 30 | 31 | ``` 32 | DO WHAT THE FUCK YOU WANT TO BUT IT'S NOT MY FAULT PUBLIC LICENSE 33 | Version 1, October 2013 34 | 35 | Copyright © 2013 Ben McGinnes 36 | 37 | Everyone is permitted to copy and distribute verbatim or modified 38 | copies of this license document, and changing it is allowed as long 39 | as the name is changed. 40 | 41 | DO WHAT THE FUCK YOU WANT TO BUT IT'S NOT MY FAULT PUBLIC LICENSE 42 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 43 | 44 | 0. You just DO WHAT THE FUCK YOU WANT TO. 45 | 46 | 1. Do not hold the author(s), creator(s), developer(s) or 47 | distributor(s) liable for anything that happens or goes wrong 48 | with your use of the work. 49 | ``` 50 | -------------------------------------------------------------------------------- /main.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright © 2018-2020 Kay 4 | # This work is free. You can redistribute it and/or modify it under the 5 | # terms of the Do What The Fuck You Want To Public License, Version 2, 6 | # as published by Sam Hocevar. See the LICENSE file for more details. 7 | 8 | set -euo pipefail; 9 | 10 | function GET_PERCENTAGE { 11 | local CURRENT_YEAR; 12 | CURRENT_YEAR=$(date +%Y); 13 | if [ $((CURRENT_YEAR % 400)) -eq 0 ]; then 14 | local TOTAL_DAYS=366; 15 | elif [ $((CURRENT_YEAR % 100)) -eq 0 ]; then 16 | local TOTAL_DAYS=365; 17 | elif [ $((CURRENT_YEAR % 4)) -eq 0 ]; then 18 | local TOTAL_DAYS=366; 19 | else 20 | local TOTAL_DAYS=365; 21 | fi 22 | CURRENT_DAY=$(echo "$(date +%j) + 0" | bc); 23 | echo $((CURRENT_DAY*100/TOTAL_DAYS)); 24 | } 25 | 26 | function DISPLAY { 27 | local PERCENTAGE; 28 | PERCENTAGE=$(GET_PERCENTAGE); 29 | local FILLED=$((LENGTH*PERCENTAGE/100)); 30 | local BLANK=$((LENGTH-FILLED)); 31 | local BAR=""; 32 | for ((i=0;i>> Bot started."; 49 | while true; do 50 | BAR_NOW=$(DISPLAY); 51 | if [ "$BAR" == "$BAR_NOW" ]; then 52 | sleep 100; 53 | continue; 54 | fi 55 | curl -X POST \ 56 | "https://api.telegram.org/bot${API_TOKEN}/sendMessage" \ 57 | -d "chat_id=${CHAT_ID}&text=${BAR_NOW}"; 58 | echo "$BAR_NOW" > "$WORKDIR"/bar; 59 | BAR="$BAR_NOW"; 60 | done 61 | } 62 | 63 | MAIN; 64 | --------------------------------------------------------------------------------