public
Last active

  • Download Gist
bot.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
require 'cinch'
require 'open-uri'
require 'simple-rss'
require 'twitter'
 
 
Twitter.configure do |config|
end
 
class WnyGroup
include Cinch::Plugin
plugin "wnygroup"
help "!wnyrug"
 
match /wnyrug/
 
def initialize(*args)
super
@latest = ""
end
 
timer 10, :method => :fetch_latest
def fetch_latest
rss = SimpleRSS.parse(open("http://www.meetup.com/Western-New-York-Ruby/events/rss/WNY+-+Buffalo+Ruby/"))
if latest = rss.entries.first
title, link = latest[:title], latest[:guid]
attending = latest[:description].scan(/Attending:\s+(\d+)/).flatten.first
string = "#{title} [#{attending || 0}] (#{link})"
if string != @latest
@latest = string
Channel("#nyruby-labs").send @latest
end
end
end
end
 
class NyRubyTwitter
include Cinch::Plugin
plugin "nyrubytwitter"
 
def initialize(*args)
super
@tweets = []
end
 
timer 500, :method => :check_tag
# match "nyruby"
def check_tag
results = Twitter::Search.new.containing("#nyruby").result_type("recent").per_page(10).fetch
messages = results.map {|tweet| "#{tweet.from_user}: #{tweet.text}"}
diff = messages - @tweets
if diff.any?
@tweets = messages
diff.each do |message|
Channel("#nyruby-labs").send message
end
else
# Channel("#nyruby-labs").send "no new tweets"
end
end
 
# def execute(m)
# check_tag
# end
end
 
bot = Cinch::Bot.new do
configure do |c|
c.nick = "WNYRuby"
c.server = "irc.freenode.net"
c.port = 6667
c.realname = 'WNY RUG'
c.verbose = true
c.version = 'WNYRUG 0.1'
c.channels = ["#nyruby-labs"]
c.plugins.plugins = [WnyGroup, NyRubyTwitter]
end
end
 
bot.start

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.