Skip to content
This repository has been archived by the owner on Sep 12, 2018. It is now read-only.

Commit

Permalink
Initial commit. All appears to be well.
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott Olson committed Feb 7, 2011
0 parents commit 604b141
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
19 changes: 19 additions & 0 deletions LICENSE
@@ -0,0 +1,19 @@
Copyright (c) 2011 Scott Olson <scott@scott-olson.org>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
7 changes: 7 additions & 0 deletions README
@@ -0,0 +1,7 @@
Yurbnurb is a little Ruby IRC bot using the Cinch gem. It provides an interface to the YubNub "command line for the web" using the Patron gem.

Requirements
------------

Yurbnurb requires the 'cinch' and 'patron' gems.

46 changes: 46 additions & 0 deletions yurbnurb.rb
@@ -0,0 +1,46 @@
require 'cinch'
require 'patron'
require 'uri'
require 'cgi'

bot = Cinch::Bot.new do
configure do |c|
c.server = "localhost"
c.nick = "yurbnurb"
c.channels = ["#programming", "#offtopic", "#bots"]
end

helpers do
def get_title(body)
title = body[/<title>(.*?)<\/title>/m, 1]
CGI.unescapeHTML(title).gsub("\n", " ").strip if title
end

def yubnub(query)
sess = Patron::Session.new
sess.timeout = 10
sess.base_url = "http://yubnub.org"
sess.headers['User-Agent'] = 'yurbnurb/1.0'

r = sess.get("/parser/parse?command=" + URI.escape(query))

return "HTTP error code #{r.status} while executing command (#{r.url})" if r.status >= 400

if r.body[0..1000].include?("<html") || r.body[0..1000].include?("<!doctype")
title = get_title(r.body)
return title ? "#{r.url} \"#{title}\"" : r.url
end

return r.url if r.body.chomp.include?("\n")

r.body.chomp
end
end

on :message, /^#{Regexp.escape nick}[:,]\s*(.+)$/ do |m, query|
m.reply("#{m.user.nick}: #{yubnub(query)}")
end
end

bot.start

0 comments on commit 604b141

Please sign in to comment.