Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
80 lines (73 sloc) 2.31 KB
require 'rubygems'
require 'net/toc'
require 'config.rb'
require 'github.rb'
commands = {
"repo" => ["NAME", "return information on repository NAME"],
"search" => [nil, "See 'help search users' and 'help search repos'"],
"search users" => ["NAME", "return information about user NAME"],
"search repos" => ["NAME", "return information about repository NAME"],
"about" => [nil, "information about gitonaim"],
"commands" => [nil, "list of commands"],
"help" => ["(COMMAND)", "if passed COMMAND, returns info on COMMAND.\notherwise is identical to 'commands'"]
}
print "Initializing bot..."
client = Net::TOC.new($bot["name"], $bot["pass"])
puts "Done"
print "Connecting..."
client.connect
puts "Done"
client.on_im do |msg, buddy|
puts "<#{buddy}> #{msg}"
case msg.strip
when /^repo ([^\/]+)\/([^$]+)$/
repos = GitHub::User::Repos.new($1)
r = repos.fetch($2)
if r.nil?
buddy.send_im("No such repository #{$1}/#{$2}")
else
text = "#{r['owner']}/#{r['name']}:\n" \
"#{r['description']}\n" \
"#{r['forks']} forks, #{r['watchers']} people watching, #{r['open_issues']} open issues\n"
if r['homepage'] != ""
text += "Homepage: #{r['homepage']}\n"
end
text += "Url: #{r['url']}"
buddy.send_im(text)
end
when /^search users (.*)$/
buddy.send_im("Sowee, user search not implemented D:")
when /^search repos (.*)$/
buddy.send_im("Searching github for: #{$1}")
results = GitHub::Search::Repos.new($1).list
if results.nil?
buddy.send_im("No results for #{$1}")
else
text = "Results:"
results.each { |r|
text += "\n#{r['username']}/#{r['name']}"
}
buddy.send_im("#{text}")
end
when /^about$/
buddy.send_im("Github repository: http://github.com/RockerMONO/gitonaim (Say \"repo gitonaim\" for more information)")
when /^(help|commands)$/
buddy.send_im("Commands: #{commands.keys.join(', ')}")
when /^help (.*)$/
if commands.has_key?($1)
text = "Description:\n" \
"#{commands[$1][1]}\n" \
"Usage: #{$1} #{commands[$1][0]}"
buddy.send_im("#{text}")
else
buddy.send_im("No such command #{$1}")
end
else
buddy.send_im("No such command #{msg}")
end
text = nil
end
client.on_error do |error|
handle_error(error)
end
client.wait