Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
  • 11 commits
  • 11 files changed
  • 0 commit comments
  • 1 contributor
View
4 bot.rb
@@ -17,7 +17,7 @@ def check_acl(message)
require "cinch/plugins/channel_util"
require "cinch/plugins/converter"
require "cinch/plugins/dictionary"
-require "cinch/plugins/down_for_me"
+require "cinch/plugins/downforeveryone"
require "cinch/plugins/etymology"
require "cinch/plugins/github_hook"
require "cinch/plugins/google_fight"
@@ -127,6 +127,8 @@ def reset( load_conf = true )
configure do |c|
c.load YAML.load_file 'config.yaml'
+ Cinch::Plugins::Haiku.enable_acl
+
acl = Cinch::Extensions::ACL.new
# global defaults
acl.set_default(:channel, nil, :allow)
View
4 lib/cinch/plugins/channel_util.rb
@@ -5,8 +5,8 @@ class ChannelUtil
enable_acl
match("op", method: :op)
- match(/join (#[A-Z0-9_-]+)/i, method: :join)
- match(/part (#[A-Z0-9_-]+)/i, method: :part)
+ match(/join (\S+)/i, method: :join)
+ match(/part (\S+)/i, method: :part)
def op(m)
if m.channel
View
3  lib/cinch/plugins/converter.rb
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
# Uses Google to convert just about anything to anything else (units, currency, etc.)
# By Pistos - irc.freenode.net#geoshell
@@ -15,6 +16,8 @@ class Converter
include Cinch::Plugin
enable_acl
+ self.help = "conv|convert|calc <expression> – Use Google to do conversions and calculations"
+
match(/(?:conv(?:ert)|calc) +(.*)$/)
def execute(m, arg)
# FIXME currency conversions do not work
View
3  lib/cinch/plugins/dictionary.rb
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
require 'open-uri'
require 'nokogiri'
@@ -7,6 +8,8 @@ class Dictionary
include Cinch::Plugin
enable_acl
+ self.help = "d|dict <word> – Look up a word"
+
match(/d(?:ict)? (.+)/)
def execute(m, arg)
catch :done do
View
18 lib/cinch/plugins/down_for_me.rb
@@ -1,18 +0,0 @@
-require 'cgi'
-require 'open-uri'
-require 'nokogiri'
-
-module Cinch
- module Plugins
- class DownForMe
- include Cinch::Plugin
- enable_acl
-
- match(/(?:up|down)\?? +(.+)/)
- def execute(m, site)
- doc = Nokogiri::HTML( open( "http://www.downforeveryoneorjustme.com/#{site}" ) )
- m.reply "[#{site}] " + doc.at( 'div#container' ).children.select{ |e| e.text? }.join( ' ' ).gsub( /\s+/, ' ' ).strip, true
- end
- end
- end
-end
View
3  lib/cinch/plugins/etymology.rb
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
require 'cgi'
require 'open-uri'
require "nokogiri"
@@ -8,6 +9,8 @@ class Etymology
include Cinch::Plugin
enable_acl
+ self.help = "etym|etymology <term> – Check the etymology of a term"
+
match(/etym(?:ology)? (.+)/)
def execute(m, term)
arg = CGI.escape(term)
View
2  lib/cinch/plugins/github_hook.rb
@@ -115,7 +115,7 @@ def github_hook(m, payload)
# Announce each individual commit
commits.each do |cdata|
author = cdata['author']['name']
- message = cdata['message'].gsub(/\s+/, ' ')[0..384]
+ message = cdata['message'].split("\n").first.gsub(/\s+/, ' ')[0..300]
url = cdata['url']
# FIXME escape strings
text = "[#{Format(:bold, "github")}] [#{Format(:bold, repo)}] <#{Format(:orange, author)}> #{message} #{url}"
View
26 lib/cinch/plugins/google.rb
@@ -1,5 +1,5 @@
require 'cgi'
-require 'open-uri'
+require "json"
module Cinch
module Plugins
@@ -10,25 +10,23 @@ class Google
match(/g(?:oogle)? (?:(\d+) )?(.+)/)
def execute(m, num_results, search_term)
- num_results ||= 1
- if num_results > config[:max_results]
+ num_results = (num_results && num_results.to_i) || 1
+ if num_results.to_i > config[:max_results]
num_results = config[:max_results]
end
argument_string = CGI.escape(search_term)
- open( "http://www.google.com/search?q=#{argument_string}&safe=active" ) do |html|
- counter = 0
- html.read.scan /<a href="?([^"]+)" class=l.*?>(.+?)<\/a>/m do |match|
- url, title = match
- title.gsub!( /<.+?>/, "" )
- ua = search_term.gsub( /-?site:\S+/, '' ).strip
- m.reply "[#{ua}]: #{url} - #{title}"
- counter += 1
- break if counter >= num_results
- end
+ open("http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=#{argument_string}") do |http|
+ json = JSON.parse(http.read)
+ results = json["responseData"]["results"]
+ results = results.select {|result| result["GsearchResultClass"] == "GwebSearch"}[0, num_results]
- if counter == 0
+ if results.empty?
m.reply "(no results)"
+ else
+ results.each do |result|
+ m.safe_reply "[%s] %s - %s" % [search_term, result["url"], result["titleNoFormatting"]]
+ end
end
end
end
View
26 lib/cinch/plugins/haiku.rb
@@ -1,26 +0,0 @@
-require 'open-uri'
-require 'nokogiri'
-
-module Cinch
- module Plugins
- class Haiku
- include Cinch::Plugin
- enable_acl
-
- match "haiku"
- def execute(m)
- haikus = Nokogiri::HTML(
- open "http://www.dailyhaiku.org/haiku/?pg=#{rand(220) + 1}"
- ).search( 'p.haiku' ).to_a
- haiku_lines = haikus[ rand( haikus.size ) ].text.split( /[\r\n]+/ )
- width = haiku_lines.inject(0) { |max,line|
- line.length > max ? line.length : max
- }
- haiku_lines.each do |line|
- sleep config[:delay] if config[:delay]
- m.reply( ' ' + line.center( width ) )
- end
- end
- end
- end
-end
View
8 lib/cinch/plugins/twitter.rb
@@ -28,8 +28,12 @@ def initialize(*args)
@seen = Hash.new { |hash, key| hash[key] = [] }
Timer(config[:poll_interval]) do
- poll_timeline
- poll_searches
+ begin
+ poll_timeline
+ poll_searches
+ rescue Twitter::Error::ServiceUnavailable
+ info "Twitter is currently unavailable"
+ end
end
end
View
15 lib/cinch/plugins/url_summarizer.rb
@@ -122,7 +122,8 @@ def listen(m)
URI.extract(m.message, ["http", "https"]).each do |link|
uri = URI.parse(link)
head = @agent.head(link)
- if !["text/html", "application/xhtml+xml"].include?(head["content-type"]) || head["content-length"].to_i > 200000
+ content_type = head["content-type"].to_s.split(";").first
+ if !["text/html", "application/xhtml+xml"].include?(content_type) || head["content-length"].to_i > 200000
next
end
@@ -156,11 +157,11 @@ def listen(m)
if uri.fragment =~ /^!\/.+?\/status\/(\d+)$/
open("https://twitter.com/statuses/show/#{$1}.json",
:ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|
- json = http.read
- tweet = JSON.parse(json)
- escaped_text = CGI.unescapeHTML(tweet['text'])
- m.reply "[#{Format(:bold, "twitter")}] <#{tweet[ 'user' ][ 'screen_name' ]}> #{escaped_text}"
- end
+ json = http.read
+ tweet = JSON.parse(json)
+ escaped_text = CGI.unescapeHTML(tweet['text'])
+ m.reply "[#{Format(:bold, "twitter")}] <#{tweet[ 'user' ][ 'screen_name' ]}> #{escaped_text}"
+ end
end
when "github.com"
if uri.path =~ /\/(.+?)\/commit\//
@@ -182,7 +183,7 @@ def listen(m)
end
else
title = page.title.gsub(/[\x00-\x1f]*/, "").gsub(/[ ]{2,}/, " ").strip rescue nil
- m.reply title
+ m.reply "[URL] " + title
end
end
end

No commit comments for this range

Something went wrong with that request. Please try again.