44 lines
1.2 KiB
Makefile

SHELL=/bin/bash
ALL_UPDATE_IDS_SRC=$(shell ls data/*.update_id.json)
ALL_UPDATE_IDS=$(subst .update_id,.processed_id,$(ALL_UPDATE_IDS_SRC))
all: fetch_updates process_updates
echo "Done"
process_updates: $(ALL_UPDATE_IDS)
%.processed_id.json: %.update_id.json router.php
cat $< | php router.php > $@
fetch_updates:
echo "Fetching new updates..."
curl -s "https://api.telegram.org/bot$(TELEGRAM_BOT_TOKEN)/getUpdates" \
| jq -c '.result[]' \
| while read -r update_msg; \
do \
file="data/$$(echo $$update_msg | jq -c '.update_id').update_id.json"; \
if [ -f "$$file" ]; then \
old_md5=$$(md5sum "$$file" | cut -d' ' -f1); \
new_md5=$$(echo "$$update_msg" | md5sum | cut -d' ' -f1); \
if [ "$$old_md5" != "$$new_md5" ]; then \
echo "$$update_msg" > "$$file"; \
fi; \
else \
echo "$$update_msg" > "$$file"; \
fi; \
done
upload-available-commands: data/available-commands.json
curl -s "https://api.telegram.org/bot$(TELEGRAM_BOT_TOKEN)/setMyCommands" -d 'commands=$(shell cat data/available-commands.json)'
echo "New commands uploaded"
data/available-commands.json: $(wildcard commands/*.inc.php)
php router.php --print-json-command-list > $@
clean:
rm data/*.json