Sha256: fe4fc514ef3a5db1d2d8c817d4cbbdd2e7cba437cde09ece844d8692af9e4f0d

Contents?: true

Size: 816 Bytes

Versions: 4

Compression:

Stored size: 816 Bytes

Contents

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, %i[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,
        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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
slack-ruby-bot-0.12.0 examples/market/marketbot.rb
slack-ruby-bot-0.11.2 examples/market/marketbot.rb
slack-ruby-bot-0.11.1 examples/market/marketbot.rb
slack-ruby-bot-0.11.0 examples/market/marketbot.rb