This repository has been archived on 2021-09-08. You can view files and clone it, but cannot push or open issues or pull requests.
Files
TakeMedicineLaBot/bot.sh

43 lines
1.4 KiB
Bash
Executable File

#!/bin/bash
token=$1
user=$2
# 傳送訊息
function sendMessage {
curl "https://api.telegram.org/bot$token/sendMessage?chat_id=$user&text=$1$2"
}
# 傳送照片
function sendPhoto {
curl "https://api.telegram.org/bot$token/sendPhoto" \
--header 'content-type: application/json' \
--data '{"chat_id": "'"$user"'", "photo": "'"$1"'", "caption": "'"$2"'"'"$3"'}'
}
function getRandomPhoto {
declare -a PHOTO_URLS=(
"https://imgur.com/p3Y0XU8.png"
"https://imgur.com/dprdJWv.png"
"https://imgur.com/MPdSnBe.png"
)
echo ${PHOTO_URLS[RANDOM % ${#PHOTO_URLS[@]}]}
}
sendMessage "你好,我會在你需要吃藥的時候提醒你哦~"
while true; do
# 早上 10 點
if [ "$(date "+%H:%M")" == "10:00" ]; then
sendPhoto $(getRandomPhoto) "該吃藥囉~" ', "reply_markup": {"resize_keyboard": true, "keyboard": [[{"text": "😊吃了"}, {"text": "😢等等"}]]}'
fi
# 晚上 7 點半
if [ "$(date "+%H:%M")" == "19:30" ]; then
sendPhoto $(getRandomPhoto) "該吃藥囉~" ', "reply_markup": {"resize_keyboard": true, "keyboard": [[{"text": "😊吃了"}, {"text": "😢等等"}]]}'
fi
# 晚上 11 點半
if [ "$(date "+%H:%M")" == "23:30" ]; then
sendPhoto $(getRandomPhoto) "該吃藥囉~" ', "reply_markup": {"resize_keyboard": true, "keyboard": [[{"text": "😊吃了"}, {"text": "😢等等"}]]}'
fi
sleep 60
done