YearProgressNotifier: Initial Repo
This commit is contained in:
commit
7580977e46
|
|
@ -0,0 +1,41 @@
|
|||
name: YearProgressBot
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
- cron: '0 12 */3 * *'
|
||||
- cron: '54 23 31 12 *'
|
||||
- cron: '0 0 1 1 *'
|
||||
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
# check if github perms are working as expected
|
||||
|
||||
steps:
|
||||
- name: Checkouts
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Run Bot
|
||||
run: |
|
||||
source config.txt
|
||||
export GIT_EMAIL="${{ secrets.GIT_EMAIL }}"
|
||||
export TG_TOKEN="${{ secrets.TG_TOKEN }}"
|
||||
export GIT_TOKEN=${{secrets.GITHUB_TOKEN}}
|
||||
export GIT_USERNAME="${{ secrets.GIT_USERNAME }}"
|
||||
if [[ "${TG_TOKEN}" == "" ]]; then echo 'TG Token not set, Exiting...' && exit 1 ; fi
|
||||
if [[ "${GIT_TOKEN}" == "" ]]; then echo 'GIT Token not set, Exiting...' && exit 1 ; fi
|
||||
if [[ "${GIT_USERNAME}" == "" ]]; then echo 'GIT Username not set, Exiting...' && exit 1 ; fi
|
||||
if [[ "${GIT_EMAIL}" == "" ]]; then echo 'GIT Email not set, Exiting...' && exit 1 ; fi
|
||||
export GIT_NAME_AND_REPONAME=$(git config --get remote.origin.url | sed 's/.*\/\([^ ]*\/[^.]*\).*/\1/')
|
||||
export GITHUB_USERNAME=$(echo "${GIT_NAME_AND_REPONAME}" | sed 's/\/.*//')
|
||||
echo $GIT_NAME_AND_REPONAME
|
||||
git config --global user.email "${GIT_EMAIL}"
|
||||
git config --global user.name "${GIT_USERNAME}"
|
||||
bash bot.sh
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
This is free and unencumbered software released into the public domain.
|
||||
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||
distribute this software, either in source code form or as a compiled
|
||||
binary, for any purpose, commercial or non-commercial, and by any
|
||||
means.
|
||||
|
||||
In jurisdictions that recognize copyright laws, the author or authors
|
||||
of this software dedicate any and all copyright interest in the
|
||||
software to the public domain. We make this dedication for the benefit
|
||||
of the public at large and to the detriment of our heirs and
|
||||
successors. We intend this dedication to be an overt act of
|
||||
relinquishment in perpetuity of all present and future rights to this
|
||||
software under copyright law.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
For more information, please refer to <https://unlicense.org>
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
YearProgressNotifier
|
||||
===============
|
||||
|
||||
YearProgressNotifier, a simple script to update the percentage of year passed to give anxiety to all who look at it, written in Bash, for Telegram.
|
||||
|
||||
This Repo is highly inspired by [RedL0tus/YearProgressBot](https://github.com/RedL0tus/YearProgressBot), albeit it takes a completely different approach towards how the bot runs.
|
||||
|
||||
Deployment
|
||||
----------
|
||||
|
||||
1. Fork the reposistory:
|
||||
|
||||
2. Set the following GitHub Actions secrets:
|
||||
```
|
||||
GIT_TOKEN : Your GitHub Account Token, To Generate One Head Over To "Settings"-->"Developer-Settings"-->"Personal-Access-Tokens"
|
||||
TG_TOKEN : Your Telegram Bot Token, To Get This, Head Over To Telegram And Start A Chat With @BotFather, Then Follow On-Screen Steps
|
||||
GIT_EMAIL : Preferably Your Private GitHub Email, Get It From "Settings/Emails"-->Under The "Keep My Email Addresses Private". GIT_EMAIL Could also be your normal email.
|
||||
GIT_USERNAME : Preferably Your GitHub Username, Although It Could Be Anything
|
||||
```
|
||||
2. Fill the values in config.txt:
|
||||
- Example of CHAT_IDS: `CHAT_IDS="-1001642062053 -1001199512844 -1001387925474"`
|
||||
- Example of LENGTH: `LENGTH=20`
|
||||
|
||||
3. Make sure Actions are enabled in GitHub:
|
||||
- To do this, visit the "Actions" tab of GitHub.
|
||||
- If done right, your Notifier should begin sending Year Percentage messages every 3 days!
|
||||
|
||||
-------
|
||||
|
||||
Common Issues
|
||||
----------
|
||||
|
||||
- You haven't added the Telegram Bot in your channel.
|
||||
- config.txt isn't populated with correct syntax.
|
||||
- Your GitHub Token expired. Make a token with no expiry.
|
||||
|
||||
-------
|
||||
|
||||
Features Nobody Asked For
|
||||
----------
|
||||
|
||||
- Multiple Telegram Bots. For some unknown reason, you can add multiple Telegram Bot Tokens in the GitHub secret of `TG_TOKEN` and the message would be sent by all the Telegram Bots (as long as they're in the group(s)/channel(s)).
|
||||
- The syntax follows: "$TOKEN1 $TOKEN2 $TOKEN3 ..."
|
||||
Example: `TG_TOKEN` : `5070501422:AAFqmHTVuWQnEO7bhbvghubbbiufPIRX2-cY 7666262877:AaqILoveMisakaMikoto7ygsgbbsyyAhsysvs-zY 5072701422:AAVuWQnILoveAnimeNiufPIRX2-cz`
|
||||
|
||||
-------
|
||||
|
||||
Why does this Notifier exist?
|
||||
----------
|
||||
|
||||
- This script exists with the sole purpose of reminding people (and inducing anxiety) of the passing year. In a futile attempt of hoping that another year doesn't fly by unnoticed.
|
||||
|
||||
-------
|
||||
|
||||
## **Warnings :**
|
||||
- This Script uses GitHub Actions. Proceed with caution.
|
||||
## **Credits :**
|
||||
* **RedL0tus** : [Github](https://github.com/RedL0tus/YearProgressBot)
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
#!/bin/bash
|
||||
|
||||
git_push() {
|
||||
git add -f percentage.txt
|
||||
git commit -m "YearProgressBot: logfile: Current Percentage: ${PERCENTAGE}%"
|
||||
echo ${GIT_NAME_AND_REPONAME}
|
||||
git remote -v
|
||||
git push --quiet -f https://${GITHUB_USERNAME}:${GIT_TOKEN}@github.com/${GIT_NAME_AND_REPONAME}
|
||||
}
|
||||
|
||||
get_percentage() {
|
||||
source config.txt
|
||||
CURRENT_YEAR=$(date +%Y)
|
||||
if [ $((CURRENT_YEAR % 400)) -eq 0 ]; then
|
||||
TOTAL_DAYS=366
|
||||
elif [ $((CURRENT_YEAR % 100)) -eq 0 ]; then
|
||||
TOTAL_DAYS=365
|
||||
elif [ $((CURRENT_YEAR % 4)) -eq 0 ]; then
|
||||
TOTAL_DAYS=366
|
||||
else
|
||||
TOTAL_DAYS=365
|
||||
fi
|
||||
CURRENT_DAY=$(echo "$(date +%j) + 0" | bc)
|
||||
echo $((CURRENT_DAY*100/TOTAL_DAYS))
|
||||
}
|
||||
|
||||
display() {
|
||||
PERCENTAGE=$(get_percentage)
|
||||
if [ -f "percentage.txt" ]; then echo "percentage.txt present!" ; else echo "percentage.txt not found, generating it!" && touch percentage.txt ; fi
|
||||
if [ "${LENGTH}" = "" ]; then LENGTH=20 ; fi
|
||||
FILLED=$((LENGTH*PERCENTAGE/100));
|
||||
BLANK=$((LENGTH-FILLED))
|
||||
for ((i=0;i<FILLED;i++)) {
|
||||
BAR="${BAR}▓"
|
||||
}
|
||||
for ((i=0;i<BLANK;i++)) {
|
||||
BAR="${BAR}░"
|
||||
}
|
||||
BAR_TEXT_PERCENTAGE="Year Progress: ${BAR} ${PERCENTAGE}%"
|
||||
}
|
||||
|
||||
telegram_message() {
|
||||
source config.txt
|
||||
echo ${CHAT_IDS}
|
||||
echo "Sending Telegram Message"
|
||||
echo "Current Percentage Is: ${BAR_TEXT_PERCENTAGE}"
|
||||
for CHAT_ID in ${CHAT_IDS}
|
||||
do
|
||||
for TG_TOKEN_INDIVIDUAL in ${TG_TOKEN}
|
||||
echo "Chat ID is: ${CHAT_ID}"
|
||||
curl -X POST "https://api.telegram.org/bot${TG_TOKEN_INDIVIDUAL}/sendMessage" -d "chat_id=${CHAT_ID}&text=${BAR_TEXT_PERCENTAGE}"
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
main() {
|
||||
#BAR_NOW=$(display)
|
||||
echo "Bot started."
|
||||
#echo $BAR_NOW
|
||||
echo $PERCENTAGE
|
||||
if [[ "$(tail -1 percentage.txt)" = "" ]] || [[ "$(tail -1 percentage.txt)" -lt "${PERCENTAGE}" ]]; then
|
||||
echo ${PERCENTAGE} >> percentage.txt
|
||||
git_push && telegram_message
|
||||
elif [[ "$(tail -1 percentage.txt)" -ge "99" ]] && [[ "${PERCENTAGE}" -le "1" ]]; then
|
||||
echo ${PERCENTAGE} >> percentage.txt
|
||||
git_push && telegram_message
|
||||
elif [[ "$(tail -1 percentage.txt)" = "${PERCENTAGE}" ]]; then
|
||||
echo "Percentage Same, Exiting...."
|
||||
exit 0
|
||||
else echo bruh
|
||||
fi
|
||||
telegram_message
|
||||
}
|
||||
display
|
||||
main
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
CHAT_IDS="-1001642062053 -1001387925474"
|
||||
LENGTH=20
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
90
|
||||
90
|
||||
98
|
||||
90
|
||||
98
|
||||
90
|
||||
98
|
||||
90
|
||||
98
|
||||
90
|
||||
98
|
||||
Loading…
Reference in New Issue