Skip to content

Instantly share code, notes, and snippets.

@karmi
Created May 15, 2010 10:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save karmi/402123 to your computer and use it in GitHub Desktop.
Save karmi/402123 to your computer and use it in GitHub Desktop.
Bishop -- IRC bot for channel irc://chat.freenode.net/rubyonrails.cz
# Bishop -- IRC bot for channel irc://chat.freenode.net/rubyonrails.cz
#
# Source: http://gist.github.com/402123.txt
require 'rubygems'
require 'cinch'
require 'open-uri'
require 'nokogiri'
require 'rack/utils'
bot = Cinch.setup do
nick "BishopBot"
username "bishop-bot"
realname "http://gist.github.com/gists/402123"
server "irc.gts.cz"
channels %w( #sxjkliu )
end
BANNER=<<-END
I am here to help you. SRC: http://gist.github.com/402123.txt TODO: List of commands
END
WHY=<<-END
Proč jsme přešli na server Freenode? Protože je známější v komunitě, má funkční webové stránky, náš kanál najde více lidí, nebude se plést s oficiálním kanálem a bude hned jasné, že je to kanál pro Čechy a Slováky, protože Freenode má webové rozhraní, ...
END
def railsapi(query)
server = "http://apidock.com"
url = "#{server}/rails/search?query=#{Rack::Utils.escape(query)}"
doc = Nokogiri::HTML(open(url))
title = doc.at(".result h3 a").text
info = doc.at(".result .info").text.to_s.tr('()', '')
link = doc.at(".result h3 a")[:href]
url = "#{server}#{link}"
rescue Exception => e
p e
p e.backtrace
"No results found"
else
"#{title} (#{info}) --> #{url}"
end
def forum_last
url = "http://forum.rubyonrails.cz/posts.rss"
doc = Nokogiri::XML(open(url))
title = doc.at('item').at('title').text
link = doc.at('item').at('link').text
rescue Exception
"Something weird has happened..."
else
"#{title} (#{link})"
end
bot.on :join do |m|
m.reply "#{m.nick}: Vítej z webu! Nestyď se ptát, ale nejdřív se představ (/nick <TVOJE JMENO>), ať víme kdo jsi :)" if m.nick.to_s =~ /qwebirc/
end
bot.plugin "help", :prefix => :bot do |m|
m.irc.privmsg m.nick, BANNER
end
bot.plugin "railsapi-for :nickname :query", :prefix => :bot do |m|
m.reply "#{m.args[:nickname]}: " + railsapi(m.args[:query])
end
bot.plugin "railsapi :query", :prefix => :bot do |m|
m.answer railsapi(m.args[:query])
end
bot.plugin "forum last", :prefix => :bot do |m|
m.answer forum_last
end
bot.plugin "why :nickname", :prefix => :bot do |m|
m.reply "#{m.args[:nickname]}: " + WHY
end
bot.plugin "diky", :prefix => :bot do |m|
m.answer "Vzdy k sluzbam!"
end
bot.run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment