Update to crystal 0.25.1 and send caption.
This commit is contained in:
parent
263db178a7
commit
1c6625400a
@ -9,7 +9,7 @@ chatid_daniel = 220888832
|
|||||||
|
|
||||||
# Configuration
|
# Configuration
|
||||||
subreddit = "rarepuppers"
|
subreddit = "rarepuppers"
|
||||||
chatid = chatid_joann
|
chatid = chatid_daniel
|
||||||
delay = 1.hours
|
delay = 1.hours
|
||||||
active_hours = 7..24
|
active_hours = 7..24
|
||||||
bot_token = "599474797:AAEmjQNO32uqurI16blS9FT4OoO7GdUZ6h0"
|
bot_token = "599474797:AAEmjQNO32uqurI16blS9FT4OoO7GdUZ6h0"
|
||||||
@ -25,11 +25,12 @@ bot.command "ping" do |update, args|
|
|||||||
end
|
end
|
||||||
|
|
||||||
bot.command "pupper" do |update, args|
|
bot.command "pupper" do |update, args|
|
||||||
url = get_reddit_post(subreddit, completed)
|
url_tuple = get_reddit_post(subreddit, completed)
|
||||||
if url
|
if url_tuple
|
||||||
|
url, title = url_tuple
|
||||||
command_chatid = update.message.as(Telepathy::Message).chat.id
|
command_chatid = update.message.as(Telepathy::Message).chat.id
|
||||||
logger.info "Using URL #{url} for request from #{command_chatid}"
|
logger.info "Using URL #{url} for request from #{command_chatid}"
|
||||||
bot.send_photo(command_chatid, url)
|
bot.send_photo(command_chatid, url, title)
|
||||||
else
|
else
|
||||||
logger.error "Unable to find a post to send."
|
logger.error "Unable to find a post to send."
|
||||||
end
|
end
|
||||||
@ -38,10 +39,11 @@ end
|
|||||||
spawn do
|
spawn do
|
||||||
loop do
|
loop do
|
||||||
time = Time.now
|
time = Time.now
|
||||||
url = get_reddit_post(subreddit, completed) if (active_hours.includes? time.hour)
|
url_tuple = get_reddit_post(subreddit, completed) if (active_hours.includes? time.hour)
|
||||||
if url
|
if url_tuple
|
||||||
|
url, title = url_tuple
|
||||||
logger.info "Sending regular picture to #{chatid}."
|
logger.info "Sending regular picture to #{chatid}."
|
||||||
bot.send_photo(chatid.to_i64, url)
|
bot.send_photo(chatid.to_i64, url, title)
|
||||||
else
|
else
|
||||||
logger.error "Unable to find a post to send. (Or it's quiet hours)"
|
logger.error "Unable to find a post to send. (Or it's quiet hours)"
|
||||||
end
|
end
|
||||||
|
@ -11,6 +11,7 @@ end
|
|||||||
|
|
||||||
def filter_reddit_json(json, completed)
|
def filter_reddit_json(json, completed)
|
||||||
json["data"]["children"]
|
json["data"]["children"]
|
||||||
|
.as_a
|
||||||
.map(&.["data"])
|
.map(&.["data"])
|
||||||
.select do |it|
|
.select do |it|
|
||||||
url = it["url"].as_s
|
url = it["url"].as_s
|
||||||
@ -22,5 +23,5 @@ end
|
|||||||
def get_reddit_post(subreddit, completed)
|
def get_reddit_post(subreddit, completed)
|
||||||
json = get_reddit_json(subreddit)
|
json = get_reddit_json(subreddit)
|
||||||
post = json.try { |json| filter_reddit_json(json, completed).first? }
|
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
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user