class Object

Public Instance Methods

on(regex, message) { || ... } click to toggle source
# File lib/bittrader-bot.rb, line 94
def on regex, message, &block
  regex =~ message.text

  if $~
    case block.arity
    when 0
      yield
    when 1
      yield $1
    when 2
      yield $1, $2
    end
  end
end
query_coin_price(coin) click to toggle source

Queries CoinMarketCap's API for a coin's current value in BTC and USD

# File lib/bittrader-bot.rb, line 86
def query_coin_price coin
  data = BittraderBot::CoinMarketCap.ticker_by_currency(coin)
  response = @bot.send_get_request(data[0], data[1])
  response_json = JSON.parse(response.body)
  coin_data = response_json[0].to_h
  "The price of #{coin} is currently #{coin_data['price_btc']} BTC (#{coin_data['price_usd']} USD)"
end
start_bot(config) click to toggle source

Launches bot with values read from config file

# File lib/bittrader-bot.rb, line 76
def start_bot config
  puts 'Loading configuration file...'
  file = File.read(config)
  config = JSON.parse file
  @bot = BittraderBot::BotLogic.new(config.to_h)
  puts 'Bittrader-Bot initialized.'
end