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
Written by Dave Goodchild
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#