example.rb in botfly-0.1.1 vs example.rb in botfly-0.2.1
- old
+ new
@@ -1,24 +1,39 @@
require 'rubygems'
require 'botfly'
-
+require 'fileutils'
require 'yaml'
config = YAML::load(ARGF.read) if ARGF
-puts config.inspect
-Jabber::debug = false
-
bot = Botfly.login(config["jid"],config["pass"]) do
- on(:message).body(/^exit$/) { reply "Goodbye!"; quit }
- on(:message).nick(/rkneufeld/) do
- Botfly.logger.info("Callback called")
- @count ||= 0
- @count += 1
- reply("That's the #{@count}th message I've received.")
- end
+ blame_responder = on.message.body(/^blame/) do |a|
+ match = @body.match(/^blame (.*):(.*)$/)
+ file = match[1]
+ line = match[2].to_i
- on(:presence) { puts self }
- connect
+ project = "/Users/burke/src/jsgithistory"
+
+ result=nil
+ FileUtils.cd(project) do
+ result = `git blame -p -L#{line},#{line} #{file}`
+ end
+
+ author = result.scan(/author (.*)\n/).first
+ time = Time.at(result.scan(/author-time (.*)\n/).first.to_i)
+ commit = result.lines.first.split(' ').first.strip
+
+ reply "#{author}, #{time}, #{commit}"
+ end
+ join('bots') do
+ on.message do
+ reply "Hi"
+ end
+ end
+ on.message.from(/^rkneufeld/).body(/^kb$/) do
+ reply "Sure thing! You ARE the boss!"
+ remove blame_responder
+ reply "There, all done"
+ end
end
-Thread.stop
-loop{}
+
+Thread.stop;loop