diff --git a/bot.sh b/bot.sh index f71fe0d..e17430d 100755 --- a/bot.sh +++ b/bot.sh @@ -5,47 +5,45 @@ user=$2 # 傳送訊息 function sendMessage { - curl "https://api.telegram.org/bot$token/sendMessage?chat_id=$user&text=$1$2" + 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"'}' + curl "https://api.telegram.org/bot$token/sendPhoto" \ + --header 'content-type: application/json' \ + --data '{"chat_id": "'"$user"'", "photo": "'"$1"'", "caption": "'"$2"'"'"$3"'}' } # 傳送貼圖 function sendSticker { - curl "https://api.telegram.org/bot$token/sendSticker?chat_id=$user&sticker=$1$2" + curl "https://api.telegram.org/bot$token/sendSticker?chat_id=$user&sticker=$1$2" } -# 主程式 -while true; do - # 早上 9 點ㄘ吃黃色藥 - if [ "$(date "+%H:%M")" == "09:00" ]; then - sendSticker "CAADAQADWAQAAvoPCRQhPbMdi-bNqQI" - sendPhoto "https://i.imgur.com/mfAL4SC.jpg" "吃這顆~" ', "reply_markup": {"inline_keyboard": [[{"text": "😊吃過了", "callback_data": "1"}, {"text": "😢等等吃", "callback_data": "2"}]]}' - sleep 1m - fi - # 下午 1 點ㄘ吃黃色藥 - if [ "$(date "+%H:%M")" == "13:00" ]; then - sendSticker "CAADAQADWAQAAvoPCRQhPbMdi-bNqQI" - sendPhoto "https://i.imgur.com/mfAL4SC.jpg" "吃這顆~" ', "reply_markup": {"inline_keyboard": [[{"text": "😊吃過了", "callback_data": "1"}, {"text": "😢等等吃", "callback_data": "2"}]]}' - sleep 1m - fi - # 晚上 6 點ㄘ吃黃色藥 - if [ "$(date "+%H:%M")" == "18:00" ]; then - sendSticker "CAADAQADWAQAAvoPCRQhPbMdi-bNqQI" - sendPhoto "https://i.imgur.com/mfAL4SC.jpg" "吃這顆~" ', "reply_markup": {"inline_keyboard": [[{"text": "😊吃過了", "callback_data": "1"}, {"text": "😢等等吃", "callback_data": "2"}]]}' - sleep 1m - fi - # 晚上 11 點ㄘ吃白色藥 - if [ "$(date "+%H:%M")" == "23:00" ]; then - sendSticker "CAADAQADWAQAAvoPCRQhPbMdi-bNqQI" - sendPhoto "https://i.imgur.com/8k7dXHM.jpg" "吃這顆~" ', "reply_markup": {"inline_keyboard": [[{"text": "😊吃過了", "callback_data": "1"}, {"text": "😢等等吃", "callback_data": "2"}]]}' - sleep 1m - fi +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[@]}]} +} - sleep 10s -done \ No newline at end of file +while true; do + # 早上 10 點 + if [ "$(date "+%H:%M")" == "10:00" ]; then + sendSticker "CAADAQADWAQAAvoPCRQhPbMdi-bNqQI" + sendPhoto $(getRandomPhoto) "吃了嗎~" ', "reply_markup": {"inline_keyboard": [[{"text": "😊吃了", "callback_data": "1"}, {"text": "😢等等", "callback_data": "2"}]]}' + fi + # 晚上 7 點半 + if [ "$(date "+%H:%M")" == "19:30" ]; then + sendSticker "CAADAQADWAQAAvoPCRQhPbMdi-bNqQI" + sendPhoto $(getRandomPhoto) "吃了嗎~" ', "reply_markup": {"inline_keyboard": [[{"text": "😊吃了", "callback_data": "1"}, {"text": "😢等等", "callback_data": "2"}]]}' + fi + # 晚上 11 點半 + if [ "$(date "+%H:%M")" == "23:30" ]; then + sendSticker "CAADAQADWAQAAvoPCRQhPbMdi-bNqQI" + sendPhoto $(getRandomPhoto) "吃了嗎" ', "reply_markup": {"inline_keyboard": [[{"text": "😊吃了", "callback_data": "1"}, {"text": "😢等等", "callback_data": "2"}]]}' + fi + sleep 60 +done