diff --git a/src/joann-pupper-bot.cr b/src/joann-pupper-bot.cr index 6f03b16..88ea8c5 100644 --- a/src/joann-pupper-bot.cr +++ b/src/joann-pupper-bot.cr @@ -9,7 +9,7 @@ chatid_daniel = 220888832 # Configuration subreddit = "rarepuppers" -chatid = chatid_joann +chatid = chatid_daniel delay = 1.hours active_hours = 7..24 bot_token = "599474797:AAEmjQNO32uqurI16blS9FT4OoO7GdUZ6h0" @@ -25,11 +25,12 @@ bot.command "ping" do |update, args| end bot.command "pupper" do |update, args| - url = get_reddit_post(subreddit, completed) - if url + url_tuple = get_reddit_post(subreddit, completed) + if url_tuple + url, title = url_tuple command_chatid = update.message.as(Telepathy::Message).chat.id logger.info "Using URL #{url} for request from #{command_chatid}" - bot.send_photo(command_chatid, url) + bot.send_photo(command_chatid, url, title) else logger.error "Unable to find a post to send." end @@ -38,10 +39,11 @@ end spawn do loop do time = Time.now - url = get_reddit_post(subreddit, completed) if (active_hours.includes? time.hour) - if url + url_tuple = get_reddit_post(subreddit, completed) if (active_hours.includes? time.hour) + if url_tuple + url, title = url_tuple logger.info "Sending regular picture to #{chatid}." - bot.send_photo(chatid.to_i64, url) + bot.send_photo(chatid.to_i64, url, title) else logger.error "Unable to find a post to send. (Or it's quiet hours)" end diff --git a/src/joann-pupper-bot/reddit.cr b/src/joann-pupper-bot/reddit.cr index b66e933..78e58bb 100644 --- a/src/joann-pupper-bot/reddit.cr +++ b/src/joann-pupper-bot/reddit.cr @@ -11,6 +11,7 @@ end def filter_reddit_json(json, completed) json["data"]["children"] + .as_a .map(&.["data"]) .select do |it| url = it["url"].as_s @@ -22,5 +23,5 @@ end def get_reddit_post(subreddit, completed) json = get_reddit_json(subreddit) post = json.try { |json| filter_reddit_json(json, completed).first? } - post.try { |post| completed.push(post["name"].as_s); post["url"].as_s } + post.try { |post| completed.push(post["name"].as_s); { post["url"].as_s, post["title"].as_s } } end