Skip to content
Browse files

Add bot commands for all Trac methods.

  • Loading branch information...
1 parent eb87e96 commit aa1933297a3ce4d5f430b225322659861733d8c6 @alloy alloy committed
Showing with 61 additions and 11 deletions.
  1. +41 −1 lib/macruby_bugmash_bot.rb
  2. +20 −10 lib/macruby_bugmash_bot/trac.rb
View
42 lib/macruby_bugmash_bot.rb
@@ -1,15 +1,55 @@
$:.unshift File.expand_path("../../vendor/cinch/lib", __FILE__)
require "cinch"
+require "macruby_bugmash_bot/trac"
bot = Cinch::Bot.new do
configure do |c|
- c.server = "irc.freenode.org"
+ c.server = "irc.freenode.org"
+ c.nick = "MacRuby-BugMash-bot"
c.channels = ["#cinch-bots"]
+
+ @trac = Trac.new
end
on :channel, "hello" do |m|
m.reply "Hello, #{m.user.nick}"
end
+
+ on :channel, "!gimme" do |m|
+ m.reply @trac.open_ticket
+ end
+
+ on :channel, /^!work (\d+)/ do |m, id|
+ m.reply @trac.assign_ticket(id, m.user.nick)
+ end
+
+ on :channel, /^!stop (\d+)/ do |m, id|
+ m.reply @trac.resign_from_ticket(id, m.user.nick)
+ end
+
+ on :channel, /^!status (\d+)/ do |m, id|
+ m.reply @trac.ticket_status(id, m.user.nick)
+ end
+
+ on :channel, /^!review (\d+)/ do |m, id|
+ m.reply @trac.mark_for_review(id, m.user.nick)
+ end
+
+ on :channel, /^!unreview (\d+)/ do |m, id|
+ m.reply @trac.unmark_for_review(id, m.user.nick)
+ end
+
+ on :message, "!me" do |m|
+ @trac.user(m.user.nick).each do |msg|
+ m.user.send(msg)
+ end
+ end
+
+ on :message, "!marked_for_review" do |m|
+ @trac.marked_for_review.each do |msg|
+ m.user.send(msg)
+ end
+ end
end
bot.start
View
30 lib/macruby_bugmash_bot/trac.rb
@@ -1,11 +1,12 @@
$:.unshift File.expand_path("../../../vendor/simple-rss/lib", __FILE__)
require "simple-rss"
+require "net/http"
require "cgi"
class Trac
- # RSS feed: http://www.macruby.org/trac/query?status=new&status=reopened&format=rss&col=id&col=summary&col=status&col=time&order=priority&max=1000
+ ACTIVE_TICKETS_RSS_FEED = URI.parse("http://www.macruby.org/trac/query?status=new&status=reopened&format=rss&col=id&col=summary&col=status&col=time&order=priority&max=1000")
def self.raw_active_tickets_feed
- # TODO
+ Net::HTTP.get(ACTIVE_TICKETS_RSS_FEED)
end
# Defines an instance method that takes: ID, ticket, user
@@ -27,20 +28,29 @@ def self.define_ticket_method(name, &block)
attr_reader :active_tickets, :users
def initialize
+ @active_tickets = {}
@users = {}
load_tickets!
end
def load_tickets!
- rss = SimpleRSS.parse(self.class.raw_active_tickets_feed)
- @active_tickets = rss.entries.inject({}) do |h, entry|
- id = File.basename(entry[:link]).to_i
- h[id] = { :id => id, :link => entry[:link], :summary => CGI.unescapeHTML(entry[:title]) }
- h
+ rss = nil
+ begin
+ rss = SimpleRSS.parse(self.class.raw_active_tickets_feed)
+ # obviously this is a bad thing to do, but I really don't want the bot to break this weekend due to HTTP problems...
+ rescue Exception => e
+ puts "[!] FETCHING THE MACRUBY TICKET FEED FAILED DUE TO: #{e.message}\n\t#{e.backtrace.join("\n\t")}"
end
- # clean assigned/marked tickets
- @users.each do |name, tickets|
- tickets.reject! { |t| @active_tickets[t[:id]].nil? }
+ if rss
+ @active_tickets = rss.entries.inject({}) do |h, entry|
+ id = File.basename(entry[:link]).to_i
+ h[id] = { :id => id, :link => entry[:link], :summary => CGI.unescapeHTML(entry[:title]) }
+ h
+ end
+ # clean assigned/marked tickets
+ @users.each do |name, tickets|
+ tickets.reject! { |t| @active_tickets[t[:id]].nil? }
+ end
end
end

0 comments on commit aa19332

Please sign in to comment.
Something went wrong with that request. Please try again.