Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.