Skip to content

Instantly share code, notes, and snippets.

@mfojtik
Created May 9, 2011 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mfojtik/962549 to your computer and use it in GitHub Desktop.
Save mfojtik/962549 to your computer and use it in GitHub Desktop.
redmine_bot
require 'rubygems'
require 'cinch'
require 'nokogiri'
require 'pp'
require 'rest-client'
FEED_URL="https://www.aeolusproject.org/redmine/activity.atom?key=296155b7b55159144a341f198e5909d24cd003ea"
def feed
client = RestClient::Resource.new(FEED_URL, '<username>', '<password>')
Nokogiri::HTML(client.get)
end
class RedmineWatch
include Cinch::Plugin
attr_accessor :last_id
timer 20, method: :refresh
def refresh
entries = (feed/"feed entry")
activity = entries.first
if (activity/'id').text.strip != @last_id
data = {
:text => (activity/'title').text.strip,
:author => (activity/'author name').text.strip,
}
project = data[:text].split('-').first.strip
data[:text].gsub!(/^(.+) \-/, '').strip
Channel("#deltacloud-internal").send("[\u000307#{data[:author]}\u000f] [#{project}] #{data[:text]}")
@last_id = (activity/'id').text.strip
end
end
end
bot = Cinch::Bot.new do
configure do |c|
c.server = "irc.freenode.net"
c.channels = ["#aeolus"]
c.nick = "redmine"
c.verbose = true
c.plugins.plugins = [RedmineWatch]
end
on :channel, /^!halibut (.+)/ do |m, text|
begin
m.reply "#{text.strip}: \u000305<`)))><\u000f tail slapped your chest and face"
rescue Exception => e
pp e.backtrace
end
end
end
bot.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment