forked from slack-ruby/slack-ruby-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmarketbot.rb
27 lines (24 loc) · 846 Bytes
/
marketbot.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
require 'slack-ruby-bot'
require 'yahoo-finance'
SlackRubyBot::Client.logger.level = Logger::WARN
class MarketBot < SlackRubyBot::Bot
scan(/([A-Z]{2,5}+)/) do |client, data, stocks|
YahooFinance::Client.new.quotes(stocks, [:name, :symbol, :last_trade_price, :change, :change_in_percent]).each do |quote|
next if quote.symbol == 'N/A'
client.web_client.chat_postMessage(
channel: data.channel,
as_user: true,
text: "Hello",
attachments: [
{
fallback: "#{quote.name} (#{quote.symbol}): $#{quote.last_trade_price}",
title: "#{quote.name} (#{quote.symbol})",
text: "$#{quote.last_trade_price} (#{quote.change_in_percent})",
color: quote.change.to_f > 0 ? '#00FF00' : '#FF0000'
}
]
)
end
end
end
MarketBot.run