nadoka 0.8.4 → 0.8.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a0027c38e7562857343bf5e48f87e1916ec53cde
4
+ data.tar.gz: 86d15edf115119b3f5bcd9f54804195684c3bfa9
5
+ SHA512:
6
+ metadata.gz: 9a5a016d5cf5855d582ff360ab65022d4c53e2edab751d8349154b379dd1913091b6522b4b5ae56567433723d3801e9d3836edc3fd9df5f2918c15511004d5ea
7
+ data.tar.gz: 1548049a15809f1f5a54bf9521d14d426bd0ad0bb0182114b7ea79c7aa36f94ef117ff26fc83073c70e8981a221f715d0d1e0fc81edef91b729a679aa1450698
@@ -0,0 +1,24 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
5
+ - jruby-18mode # JRuby in 1.8 mode
6
+ - jruby-19mode # JRuby in 1.9 mode
7
+ - rbx-18mode
8
+ - rbx-19mode
9
+ - ruby-head
10
+ - jruby-head
11
+ - 1.8.7
12
+ - ree
13
+ matrix:
14
+ allow_failures:
15
+ - rvm: jruby-18mode
16
+ - rvm: jruby-19mode
17
+ - rvm: rbx-18mode
18
+ - rvm: rbx-19mode
19
+ - rvm: ruby-head
20
+ - rvm: jruby-head
21
+ - rvm: ree
22
+ script: ruby check-syntax.rb
23
+ notifications:
24
+ irc: "irc.freenode.org#nadoka_jp"
data/README.md CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  Written by SASADA Koichi <ko1 at atdot.net>
4
4
 
5
+ [![Build Status](https://travis-ci.org/nadoka/nadoka.png?branch=master)](https://travis-ci.org/nadoka/nadoka)
6
+ [![Code Climate](https://codeclimate.com/github/nadoka/nadoka.png)](https://codeclimate.com/github/nadoka/nadoka)
7
+
5
8
  ## What's this?
6
9
 
7
10
  Nadoka is IRC Client Server program.
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ STDERR.puts RUBY_DESCRIPTION
3
+ result = true
4
+ Dir.glob("{bin/nadoka,nadokarc,**/*.[nr]b}") do |filename|
5
+ STDERR.print "#{filename}: "
6
+ result &&= system("ruby", "-cw", filename)
7
+ end
8
+ exit(result)
@@ -11,7 +11,7 @@
11
11
  #
12
12
 
13
13
  module Nadoka
14
- VERSION = '0.8.4'
14
+ VERSION = '0.8.5'
15
15
  NDK_Version = VERSION.dup
16
16
  NDK_Created = Time.now
17
17
 
@@ -33,13 +33,34 @@ end
33
33
  module GithubIssues
34
34
  module_function
35
35
 
36
- def issues(owner, repo, since=nil, state='open')
36
+ DEFAULT_HEADER = {
37
+ 'User-Agent' => "Nadoka-GithubIssuesBot/0.1",
38
+ }
39
+
40
+ def uri_read(uri, header)
41
+ debug = $GITHUB_ISSUES_DEBUG
42
+ p uri if debug
43
+ uri.open("r", header) do |f|
44
+ p f.meta if debug
45
+ return f.read
46
+ end
47
+ rescue OpenURI::HTTPError => e
48
+ p e.io.meta if debug
49
+ if e.io.meta["x-ratelimit-remaining"] == "0"
50
+ raise "#{e}: because x-ratelimit-remaining=0"
51
+ end
52
+ raise "#{e}: #{uri}"
53
+ end
54
+
55
+ def issues(owner, repo, since, state='open', header=DEFAULT_HEADER)
37
56
  since = since.utc.strftime("%Y-%m-%dT%H:%M:%SZ")
38
57
  uri = URI("https://api.github.com/repos/#{owner}/#{repo}/issues?since=#{since}&state=#{state}")
39
- issues = JSON.parse(uri.read)
58
+ json = uri_read(uri, header)
59
+ issues = JSON.parse(json)
40
60
  issues.each do |issue|
41
61
  comments_uri = URI("#{issue['comments_url']}?since=#{since}")
42
- comments = JSON.parse(comments_uri.read)
62
+ json = uri_read(comments_uri, header)
63
+ comments = JSON.parse(json)
43
64
  if comments.empty?
44
65
  yield [:issue, issue, issue_to_s(issue)]
45
66
  else
@@ -77,9 +98,10 @@ module GithubIssues
77
98
  end
78
99
 
79
100
  if __FILE__ == $0
101
+ $GITHUB_ISSUES_DEBUG = $DEBUG
80
102
  owner = "rubima"
81
103
  repo = "rubima"
82
- since = Time.now - 60*60*3
104
+ since = Time.now - 60*60*3*7
83
105
  GithubIssues.issues(owner, repo, since) do |_, _, s|
84
106
  puts s.gsub(/\s+/, ' ')
85
107
  end
@@ -135,7 +157,7 @@ class GithubIssuesBot < Nadoka::NDK_Bot
135
157
  send_notice @ch, s
136
158
  end
137
159
  rescue Exception => e
138
- send_notice(@ch, "rss bot error: #{e}")
160
+ send_notice(@ch, "github issues bot error for #{@owner}/#{@repo}: #{e}")
139
161
  @manager.ndk_error e
140
162
  end
141
163
  end
@@ -54,7 +54,9 @@ BotConfig = [
54
54
  =end
55
55
 
56
56
 
57
- require 'iconv'
57
+ unless "".respond_to?(:encode)
58
+ require 'iconv'
59
+ end
58
60
  require 'kconv'
59
61
  require 'shellwords'
60
62
  require 'cgi'
@@ -192,6 +194,10 @@ class GoogleBot < Nadoka::NDK_Bot
192
194
  result.gsub!(/&nbsp;/u, " ")
193
195
  result.gsub!(/\s+/, " ")
194
196
  return result
197
+ elsif /<div class="leg_calc [^<>]*><div[^<>]*>([^<>]*)<\/div><div[^<>]*>([^<>]*)</u =~ html
198
+ result = "#{$1} #{$2}"
199
+ #@logger.slog("google_calc>#{result.dump}")
200
+ return result
195
201
  else
196
202
  "response error"
197
203
  end
@@ -1,4 +1,4 @@
1
- #-*-ruby-*-
1
+ #-*-ruby; coding: euc-jp -*-
2
2
  #
3
3
  # Copyright (c) 2004-2005 SASADA Koichi <ko1 at atdot.net>
4
4
  #
@@ -27,7 +27,10 @@ Reply title of URL.
27
27
 
28
28
  =end
29
29
 
30
- require 'iconv'
30
+ begin
31
+ require 'iconv'
32
+ rescue LoadError
33
+ end
31
34
  require 'nkf'
32
35
  require 'open-uri'
33
36
  require 'timeout'
@@ -45,6 +48,13 @@ begin
45
48
  rescue LoadError
46
49
  end
47
50
 
51
+ unless OpenURI.redirectable?(URI("http://example.com"), URI("https://example.com"))
52
+ def OpenURI.redirectable?(uri1, uri2) # :nodoc:
53
+ uri1.scheme.downcase == uri2.scheme.downcase ||
54
+ (/\A(?:http|ftp)\z/i =~ uri1.scheme && /\A(?:https?|ftp)\z/i =~ uri2.scheme)
55
+ end
56
+ end
57
+
48
58
  module URL2Title
49
59
  module_function
50
60
 
@@ -104,39 +114,46 @@ module URL2Title
104
114
  body = NKF.nkf("-wm0x --ic=#{charset}", body)
105
115
  elsif charset
106
116
  charset.sub!(/\Ax-?/i, '')
107
- begin
108
- body = Iconv.conv("utf-8", charset, body)
109
- rescue Iconv::IllegalSequence => e
110
- info[:errors] << e
111
- body = NKF.nkf("-wm0x", body)
112
- rescue Iconv::InvalidEncoding => e
113
- info[:errors] << e
114
- body = NKF.nkf("-wm0x", body)
117
+ if defined?(Iconv)
118
+ begin
119
+ body = Iconv.conv("utf-8", charset, body)
120
+ rescue Iconv::IllegalSequence => e
121
+ info[:errors] << e
122
+ body = NKF.nkf("-wm0x", body)
123
+ rescue Iconv::InvalidEncoding => e
124
+ info[:errors] << e
125
+ body = NKF.nkf("-wm0x", body)
126
+ end
127
+ else
128
+ body = body.encode("utf-8", charset, :invalid => :replace, :undef => :replace)
115
129
  end
116
130
  else
117
131
  body = NKF.nkf("-wm0x", body)
118
132
  end
119
133
 
120
134
  title = nil
121
- case uri.host
135
+ if %r"<title\b(?>[^<>]*)>(.*?)</title(?>[^<>]*)>"miu =~ body
136
+ title = $1
137
+ end
138
+
139
+ case f.base_uri.host
122
140
  when /\A(?:twitter\.com)\z/
123
- if %r"<title\b(?>[^<>]*)>(.*?)</title(?>[^<>]*)>"miu =~ body
124
- title = $1
125
- end
126
141
  if defined?(::Nokogiri)
127
142
  doc = Nokogiri::HTML(body, uri.to_s, 'utf-8')
128
- tweet = doc.css('.tweet-text')
129
- unless tweet.empty?
143
+ tweet, = doc.css('.tweet-text')
144
+ if tweet
130
145
  tweet = tweet.inner_html
131
146
  tweet.gsub!(/<.*?>/, '')
132
147
  tweet.strip!
133
148
  title = tweet unless tweet.empty?
134
149
  end
135
150
  end
136
- else
137
- if %r"<title\b(?>[^<>]*)>(.*?)</title(?>[^<>]*)>"miu =~ body
138
- title = $1
151
+ when /\A(?:github\.com)\z/
152
+ # ignore og:title
153
+ if title
154
+ title = title.gsub(/\xC2\xB8/u, "-")
139
155
  end
156
+ else
140
157
  if defined?(::Nokogiri)
141
158
  doc ||= Nokogiri::HTML(body, uri.to_s, 'utf-8')
142
159
  og_title = doc.xpath("//meta[@property='og:title'][1]/@content")
@@ -176,10 +193,10 @@ module URL2Title
176
193
  doc ||= Nokogiri::HTML(body, uri.to_s, 'utf-8')
177
194
  canonical_uri = doc.xpath("//link[@rel='canonical'][1]/@href")
178
195
  unless canonical_uri.empty?
179
- info[:uri] = URI(canonical_uri.text)
196
+ info[:uri] = URI(shorten_url(canonical_uri.text))
180
197
  end
181
198
  elsif /<link rel="canonical" href="(.+?)"/i =~ body
182
- info[:uri] = URI(CGI.unescapeHTML($1))
199
+ info[:uri] = URI(shorten_url(CGI.unescapeHTML($1)))
183
200
  end
184
201
  if title
185
202
  title = CGI.unescapeHTML(title)
@@ -217,6 +234,18 @@ module URL2Title
217
234
  url.sub(/\/\#!\//, '/')
218
235
  end
219
236
 
237
+ def shorten_url(url)
238
+ case url
239
+ when %r!\Ahttp://www\.amazon\.co\.jp/.*(/dp/.+)\z!
240
+ "http://amazon.jp#{$1}"
241
+ when %r!\A(http://(?:[a-z]+\.)?slashdot\.jp/story/\d+/\d+/\d+/\d+)(?:/.*)?\z!
242
+ $1
243
+ else
244
+ # default: do nothing
245
+ url
246
+ end
247
+ end
248
+
220
249
  def url2title(url, headers)
221
250
  url = prepare_url(url)
222
251
  info = get_title(url, headers)
@@ -1,3 +1,4 @@
1
+ # coding: UTF-8
1
2
  #
2
3
  # Xi Bot
3
4
  #
@@ -717,7 +717,8 @@ E
717
717
  369,RPL_ENDOFWHOWAS 321,RPL_LISTSTART
718
718
  322,RPL_LIST 323,RPL_LISTEND 325,RPL_UNIQOPIS
719
719
  324,RPL_CHANNELMODEIS 331,RPL_NOTOPIC
720
- 332,RPL_TOPIC 341,RPL_INVITING 342,RPL_SUMMONING
720
+ 332,RPL_TOPIC 333,RPL_TOPICWHOTIME
721
+ 341,RPL_INVITING 342,RPL_SUMMONING
721
722
  344,RPL_REOPLIST 345,RPL_ENDOFREOPLIST
722
723
  346,RPL_INVITELIST 347,RPL_ENDOFINVITELIST
723
724
  348,RPL_EXCEPTLIST 349,RPL_ENDOFEXCEPTLIST
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nadoka
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.4
5
- prerelease:
4
+ version: 0.8.5
6
5
  platform: ruby
7
6
  authors:
8
7
  - Kazuhiro NISHIYAMA
@@ -10,7 +9,7 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2013-04-29 00:00:00.000000000 Z
12
+ date: 2013-07-29 00:00:00.000000000 Z
14
13
  dependencies: []
15
14
  description: Nadoka is a tool for monitoring and logging IRC conversations and responding
16
15
  to specially formatted requests. You define and customize these responses in Ruby.
@@ -23,10 +22,12 @@ extensions: []
23
22
  extra_rdoc_files: []
24
23
  files:
25
24
  - .gitignore
25
+ - .travis.yml
26
26
  - Gemfile
27
27
  - README.md
28
28
  - Rakefile
29
29
  - bin/nadoka
30
+ - check-syntax.rb
30
31
  - doc/ChangeLog.old
31
32
  - lib/rss_check.rb
32
33
  - lib/tagparts.rb
@@ -79,26 +80,25 @@ files:
79
80
  - rice/irc.rb
80
81
  homepage: https://github.com/nadoka/nadoka
81
82
  licenses: []
83
+ metadata: {}
82
84
  post_install_message:
83
85
  rdoc_options: []
84
86
  require_paths:
85
87
  - lib
86
88
  required_ruby_version: !ruby/object:Gem::Requirement
87
- none: false
88
89
  requirements:
89
- - - ! '>='
90
+ - - '>='
90
91
  - !ruby/object:Gem::Version
91
92
  version: '0'
92
93
  required_rubygems_version: !ruby/object:Gem::Requirement
93
- none: false
94
94
  requirements:
95
- - - ! '>='
95
+ - - '>='
96
96
  - !ruby/object:Gem::Version
97
97
  version: '0'
98
98
  requirements: []
99
99
  rubyforge_project: nadoka
100
- rubygems_version: 1.8.23
100
+ rubygems_version: 2.0.3
101
101
  signing_key:
102
- specification_version: 3
102
+ specification_version: 4
103
103
  summary: IRC logger, monitor and proxy program ("bot")
104
104
  test_files: []