his.js

Telegram bot for /his/ threads.
git clone git://git.knutsen.co/his.js
Log | Files | Refs | LICENSE

commit dcb70728ab17ca947d5785b58302a8830c601bb3
parent 5b581554ddd130ce83fc2763090d4f1bb0431074
Author: Daniel <23189912+danyisill@users.noreply.github.com>
Date:   Thu, 30 Jul 2020 14:50:03 +0300

Merge pull request #2 from Demonstrandum/master

Added shell script.
Diffstat:
M.gitignore | 4++--
Ahis.sh | 33+++++++++++++++++++++++++++++++++
Mstart.sh | 2+-
3 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -1,2 +1,2 @@ -# JSON Store -posted.json +# Posted files +posted* diff --git a/his.sh b/his.sh @@ -0,0 +1,33 @@ +#!/usr/bin/bash + +[ -z "$HIS_BOT_TOKEN" ] && { echo "No API token in ENV!"; exit 1; } +[ ! -f ./posted ] && touch posted + +update () { + curl -s 'https://a.4cdn.org/his/threads.json' \ + | tr n '\n' \ + | tr -cd '1234567890:\n' \ + | sed 1d \ + | while read -r thread; do + if [[ "$(cut -d : -f 4 <<< "$thread")" -gt 50 ]]; then + echo "--- Checking if thread already exists... ---" + if grep -q "$(cut -d : -f 2 <<< "$thread")" posted; then + echo " -> Exists, not posting." + continue + else + echo " -> Posting new message!" + cut -d : -f 2 <<< "$thread" \ + | tee -a posted \ + | xargs -I {} curl -s "https://api.telegram.org/bot$HIS_BOT_TOKEN/sendMessage?chat_id=@his50replies&text=https://boards.4channel.org/his/thread/{}" >/dev/null + fi + sleep 0.25 + fi + done +} + +for (( ; ; )); do + echo "=== Checking. ===" + update + sleep 300 # 5 min. +done + diff --git a/start.sh b/start.sh @@ -1,6 +1,6 @@ #!/bin/sh -node his.js & +bash ./his.sh & echo "$!" > ./.pid echo "Bot started."