Sha256: 23c7fa9409d834118d1743a964674b9d1890f6af16e874f908820b2763f7bb6c

Contents?: true

Size: 823 Bytes

Versions: 10

Compression:

Stored size: 823 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, [: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

10 entries across 10 versions & 1 rubygems

Version Path
slack-ruby-bot-0.10.5 examples/market/marketbot.rb
slack-ruby-bot-0.10.4 examples/market/marketbot.rb
slack-ruby-bot-0.10.3 examples/market/marketbot.rb
slack-ruby-bot-0.10.2 examples/market/marketbot.rb
slack-ruby-bot-0.10.1 examples/market/marketbot.rb
slack-ruby-bot-0.10.0 examples/market/marketbot.rb
slack-ruby-bot-0.9.0 examples/market/marketbot.rb
slack-ruby-bot-0.8.2 examples/market/marketbot.rb
slack-ruby-bot-0.8.1 examples/market/marketbot.rb
slack-ruby-bot-0.8.0 examples/market/marketbot.rb