Last Updated: February 25, 2016
·
430
· buddhamagnet

adn funding broadcaster

require 'cinch'
require 'nokogiri'
require 'open-uri'

class AppnetCrier
  attr_reader :doc

  def initialize
    @doc = Nokogiri::HTML(open('https://join.app.net')) 
  end

  def get_data(type = 'pledged')
    doc.at_css("div.#{type} div.stat-number").text
  end

  def funds
    "app.net has raised #{get_data}"
  end

  def backers
    "app.net now has #{get_data('backers')} backers"
  end

  def funds_and_backers
    "app.net has now raised #{get_data} from #{get_data('backers')}     backers"
  end
end

bot = Cinch::Bot.new do
  configure do |c|
    c.name = "appnet bot"
    c.server = "irc.freenode.org"
    c.channels = ["#appnet"]
  end

  on :message, "funds" do |m|
    a = AppnetCrier.new
    m.reply "Hello, #{m.user.nick} - #{a.funds}"
  end

  on :message, "backers" do |m|
    a = AppnetCrier.new
    m.reply "Hello, #{m.user.nick} - #{a.backers}"
  end

  on :message, "funds and backers" do |m|
    a = AppnetCrier.new
    m.reply "Hello, #{m.user.nick} - #{a.funds_and_backers}"
  end
end

bot.start