nadoka 0.9.1 → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.travis.yml +2 -0
- data/lib/rss_check.rb +3 -5
- data/nadokarc +2 -2
- data/ndk/config.rb +1 -1
- data/ndk/server.rb +4 -0
- data/ndk/version.rb +1 -1
- data/plugins/autoop.nb +1 -1
- data/plugins/googlebot.nb +40 -4
- data/plugins/rss_checkbot.nb +1 -3
- data/plugins/titlebot.nb +22 -3
- data/rice/irc.rb +6 -5
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 499bbabcf8dd4f2b5c8850550daee031996821c3106f63795972f843b22fc45b
|
4
|
+
data.tar.gz: 1b151a20ec41485b4a0e368d62746591be4710c82b089e82314b9a969f499d3a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2cc2ed86d0496fdc7bbad02524df8c50efb784e559d15b3590c3dbdb8f1125f74738a5ccb574e682efd211e47b979a111e1dea3b7a341b58e8bef6715de99ed5
|
7
|
+
data.tar.gz: 71b721ff820b48fbdc39601e578cdbc795088fa6df223027a4c6e801d1eb8089de6dbb3024d3c6c2f467c5922afe0d796485b8fb50b1eb3eba58cf75ddd1763b
|
data/.travis.yml
CHANGED
data/lib/rss_check.rb
CHANGED
@@ -79,7 +79,7 @@ class RSS_Check
|
|
79
79
|
|
80
80
|
def read_content
|
81
81
|
case @uri.scheme
|
82
|
-
when 'http'
|
82
|
+
when 'http', 'https'
|
83
83
|
open(@uri){|f|
|
84
84
|
if f.content_encoding.any?{|e| /gzip/ =~ e}
|
85
85
|
Zlib::GzipReader.new(StringIO.new(f.read)).read || ''
|
@@ -96,7 +96,7 @@ class RSS_Check
|
|
96
96
|
|
97
97
|
def mtime
|
98
98
|
case @uri.scheme
|
99
|
-
when 'http'
|
99
|
+
when 'http', 'https'
|
100
100
|
open(@uri){|f|
|
101
101
|
f.last_modified || Time.now
|
102
102
|
}
|
@@ -204,13 +204,11 @@ if $0 == __FILE__
|
|
204
204
|
ARGV.shift || './rss_cache',
|
205
205
|
false # false
|
206
206
|
)
|
207
|
-
require 'iconv'
|
208
207
|
require 'kconv'
|
209
|
-
ic = Iconv.open("EUC-JP", "UTF-8")
|
210
208
|
|
211
209
|
rssc.check.each{|e|
|
212
210
|
puts e[:about]
|
213
|
-
title = (e[:ccode] == 'UTF-8') ?
|
211
|
+
title = (e[:ccode] == 'UTF-8') ? e[:title].toeuc : e[:title]
|
214
212
|
puts title
|
215
213
|
}
|
216
214
|
rssc.dump
|
data/nadokarc
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
#
|
8
8
|
# This program is free software with ABSOLUTELY NO WARRANTY.
|
9
9
|
# You can re-distribute and/or modify this program under
|
10
|
-
# the same terms of the Ruby's
|
10
|
+
# the same terms of the Ruby's license.
|
11
11
|
#
|
12
12
|
#
|
13
13
|
|
@@ -80,7 +80,7 @@ class NADOKA_Config < Nadoka::NDK_ConfigBase
|
|
80
80
|
# :port => 6667,
|
81
81
|
# },
|
82
82
|
# {
|
83
|
-
# :host => '
|
83
|
+
# :host => 'dh6.ircnet.ne.jp',
|
84
84
|
# :port => (6660 .. 6669),
|
85
85
|
# },
|
86
86
|
]
|
data/ndk/config.rb
CHANGED
@@ -387,7 +387,7 @@ module Nadoka
|
|
387
387
|
@config = {}
|
388
388
|
klass = ConfigClass.last
|
389
389
|
|
390
|
-
klass.ancestors[0
|
390
|
+
klass.ancestors[0..klass.ancestors.index(NDK_ConfigBase)].reverse_each{|kl|
|
391
391
|
kl.constants.each{|e|
|
392
392
|
@config[e.downcase.intern] = klass.const_get(e)
|
393
393
|
}
|
data/ndk/server.rb
CHANGED
data/ndk/version.rb
CHANGED
data/plugins/autoop.nb
CHANGED
data/plugins/googlebot.nb
CHANGED
@@ -41,9 +41,10 @@ BotConfig = [
|
|
41
41
|
#"User-Agent" => "Ruby/#{RUBY_VERSION}",
|
42
42
|
'Referer' => 'https://github.com/nadoka/nadoka',
|
43
43
|
},
|
44
|
-
#
|
45
|
-
|
46
|
-
|
44
|
+
# API key
|
45
|
+
:api_key => 'INSERT_YOUR_API_KEY',
|
46
|
+
# Custom search engine ID
|
47
|
+
:cx => '017576662512468239146:omuauf_lfve',
|
47
48
|
:googlec_maxwords => 5,
|
48
49
|
:search_default_lang => 'ja',
|
49
50
|
:count_default_lang => '',
|
@@ -94,6 +95,7 @@ class GoogleBot < Nadoka::NDK_Bot
|
|
94
95
|
@count_default_lang = (@bot_config[:count_default_lang] || '').sub(/^lang_/, '')
|
95
96
|
@headers = @bot_config.fetch(:headers, {})
|
96
97
|
@api_key = @bot_config[:api_key]
|
98
|
+
@cx = @bot_config[:cx]
|
97
99
|
@uri_slog = @bot_config.fetch(:uri_slog, false)
|
98
100
|
@ch_kcode = @bot_config.fetch(:ch_kcode, :tojis)
|
99
101
|
end
|
@@ -121,6 +123,8 @@ class GoogleBot < Nadoka::NDK_Bot
|
|
121
123
|
def dispatch_command msg
|
122
124
|
begin
|
123
125
|
case msg
|
126
|
+
when /^g>\s*(.+)/
|
127
|
+
custom_search $1
|
124
128
|
when /^goo(o*)gle( #{SEARCHER_RE})?(:.*?)?>\s*(.+)/o, /^gu(u*)guru(#{SEARCHER_RE})?(:.+)?>\s*(.+)/o
|
125
129
|
"goo#{$1}gle#{$2} bot#{$3}: #{search($1.length, $3, $4, $2)}"
|
126
130
|
when /^googlec( #{SEARCHER_RE})?(:.*?)?>\s*(.+)/o
|
@@ -135,6 +139,33 @@ class GoogleBot < Nadoka::NDK_Bot
|
|
135
139
|
end
|
136
140
|
end
|
137
141
|
|
142
|
+
def custom_search word
|
143
|
+
uri = "https://www.googleapis.com/customsearch/v1"
|
144
|
+
uri << "?key=#{@api_key}&cx=#{@cx}&q="
|
145
|
+
uri << CGI.escape(word)
|
146
|
+
@logger.slog "GoogleBot: #{uri}" if @uri_slog
|
147
|
+
result = open(uri, @headers) do |f|
|
148
|
+
JSON.parse(f.read)
|
149
|
+
end
|
150
|
+
@logger.slog "GoogleBot: #{result}" if @uri_slog
|
151
|
+
count = result["searchInformation"]["totalResults"].to_i
|
152
|
+
if count == 0
|
153
|
+
return "no match"
|
154
|
+
end
|
155
|
+
count = count.to_s.gsub(/(\d)(?=\d{3}+$)/, '\\1,')
|
156
|
+
item, = result["items"]
|
157
|
+
title = item["title"]
|
158
|
+
url = item["link"]
|
159
|
+
"#{title} - #{url} (and #{count} hit#{(count.to_i > 1) ? 's' : ''})".delete("\r\n")
|
160
|
+
rescue OpenURI::HTTPError => e
|
161
|
+
@logger.slog "GoogleBot: #{e.inspect}" if @uri_slog
|
162
|
+
result = JSON.parse(e.io.read)
|
163
|
+
if @uri_slog
|
164
|
+
@logger.slog "GoogleBot: #{result.inspect}"
|
165
|
+
end
|
166
|
+
result["error"]["errors"][0]["reason"].delete("\r\n")
|
167
|
+
end
|
168
|
+
|
138
169
|
def do_search word, cnt, lang, searcher='web'
|
139
170
|
i = 0
|
140
171
|
begin
|
@@ -173,6 +204,11 @@ class GoogleBot < Nadoka::NDK_Bot
|
|
173
204
|
def api_search word, cnt, lang, searcher
|
174
205
|
result = do_search word, cnt, lang, searcher
|
175
206
|
|
207
|
+
if result["responseData"].nil?
|
208
|
+
# {"responseData": null, "responseDetails": "qps rate exceeded", "responseStatus": 503}
|
209
|
+
return "error #{result['responseStatus']}: #{result['responseDetails']}"
|
210
|
+
end
|
211
|
+
|
176
212
|
count = result.estimatedTotalResultsCount.to_i
|
177
213
|
|
178
214
|
if count > 0
|
@@ -300,7 +336,7 @@ class GoogleBot < Nadoka::NDK_Bot
|
|
300
336
|
else
|
301
337
|
api_search word, cnt, lang, searcher
|
302
338
|
end
|
303
|
-
|
339
|
+
end
|
304
340
|
|
305
341
|
def googlec lang, word, searcher=nil
|
306
342
|
lang = lang_check(lang, @count_default_lang)
|
data/plugins/rss_checkbot.nb
CHANGED
@@ -29,7 +29,6 @@ BotConfig = [
|
|
29
29
|
=end
|
30
30
|
|
31
31
|
require 'lib/rss_check'
|
32
|
-
require 'iconv'
|
33
32
|
require 'kconv'
|
34
33
|
|
35
34
|
class RSS_CheckBot < Nadoka::NDK_Bot
|
@@ -40,7 +39,6 @@ class RSS_CheckBot < Nadoka::NDK_Bot
|
|
40
39
|
@tm = @bot_config.fetch(:tm,30) # min
|
41
40
|
@over = @bot_config.fetch(:over_message, nil)
|
42
41
|
@rssc = RSS_Check.new(@paths, @cache, true)
|
43
|
-
@ic = Iconv.open("EUC-JP", "UTF-8")
|
44
42
|
@prevtm= Time.now
|
45
43
|
end
|
46
44
|
|
@@ -99,7 +97,7 @@ class RSS_CheckBot < Nadoka::NDK_Bot
|
|
99
97
|
begin
|
100
98
|
# convert from U+FF5E FULLWIDTH TILDE to U+301C WAVE DASH
|
101
99
|
title = e[:title].gsub(/\357\275\236/u, "\343\200\234")
|
102
|
-
title =
|
100
|
+
title = title.toeuc
|
103
101
|
rescue Exception
|
104
102
|
# maybe, char code translation error
|
105
103
|
next
|
data/plugins/titlebot.nb
CHANGED
@@ -59,14 +59,28 @@ end
|
|
59
59
|
module URL2Title
|
60
60
|
module_function
|
61
61
|
|
62
|
+
BLACKLIST_HOST = [
|
63
|
+
/\blocalhost\b/,
|
64
|
+
/\A127\./,
|
65
|
+
/\A192\.168\./,
|
66
|
+
/\A10\./,
|
67
|
+
/\A169\.254\./,
|
68
|
+
]
|
69
|
+
|
62
70
|
def get_title(url, headers)
|
63
71
|
uri = URI(url)
|
64
72
|
info = { :uri => uri }
|
65
73
|
info[:errors] = []
|
66
74
|
case uri.host
|
67
|
-
when
|
75
|
+
when *BLACKLIST_HOST
|
68
76
|
info[:title] = "(ignored)"
|
69
77
|
return info
|
78
|
+
when /\A(?:www\.nicovideo\.jp)\z/
|
79
|
+
if /\A\/watch\/(sm\d+)\z/ =~ uri.path
|
80
|
+
uri = URI("http://d.hatena.ne.jp/video/niconico/#{$1}")
|
81
|
+
end
|
82
|
+
when /\A(?:mobile\.twitter\.com)\z/
|
83
|
+
uri = URI(url.sub(/mobile\.twitter\.com/, 'twitter.com'))
|
70
84
|
end
|
71
85
|
headers = {
|
72
86
|
:content_length_proc => proc{|x| raise Errno::EFBIG if x && x > 1048576},
|
@@ -104,7 +118,7 @@ module URL2Title
|
|
104
118
|
charset = $1
|
105
119
|
end
|
106
120
|
case charset
|
107
|
-
when /
|
121
|
+
when /shift[_-]jis/i
|
108
122
|
charset = "cp932"
|
109
123
|
when /euc-jp/i # euc-jp, x-euc-jp
|
110
124
|
charset = "eucjp-ms"
|
@@ -151,6 +165,10 @@ module URL2Title
|
|
151
165
|
end
|
152
166
|
when /\A(?:github\.com)\z/
|
153
167
|
# ignore og:title
|
168
|
+
when /\A(?:www\.youtube\.com)\z/
|
169
|
+
if %r'"title":"(.+?)"' =~ body
|
170
|
+
title = $1
|
171
|
+
end
|
154
172
|
else
|
155
173
|
if defined?(::Nokogiri)
|
156
174
|
doc ||= Nokogiri::HTML(body, uri.to_s, 'utf-8')
|
@@ -255,7 +273,7 @@ end
|
|
255
273
|
if __FILE__ == $0
|
256
274
|
require File.expand_path('../../ndk/version', __FILE__)
|
257
275
|
def u2t(url)
|
258
|
-
firefox = "Mozilla/5.0 (
|
276
|
+
firefox = "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:57.0) Gecko/20100101 Firefox/57.0"
|
259
277
|
ua = "NadokaTitleBot/#{Nadoka::VERSION}"
|
260
278
|
headers = {
|
261
279
|
"User-Agent" => "#{firefox} Ruby/#{RUBY_VERSION} #{ua}",
|
@@ -264,6 +282,7 @@ if __FILE__ == $0
|
|
264
282
|
rescue
|
265
283
|
$!.inspect
|
266
284
|
end
|
285
|
+
URL2Title::BLACKLIST_HOST << /\.test\z/
|
267
286
|
if ARGV.empty?
|
268
287
|
# TODO: test
|
269
288
|
else
|
data/rice/irc.rb
CHANGED
@@ -58,8 +58,8 @@ module RICE
|
|
58
58
|
|
59
59
|
@read_q = Queue.new
|
60
60
|
|
61
|
-
@read_th = Thread.new(@read_q, @eol) do |read_q,
|
62
|
-
read_thread(read_q,
|
61
|
+
@read_th = Thread.new(@read_q, @eol) do |read_q, eol_|
|
62
|
+
read_thread(read_q, eol_)
|
63
63
|
end
|
64
64
|
|
65
65
|
@threads = {}
|
@@ -86,7 +86,7 @@ module RICE
|
|
86
86
|
@delay = 0.3
|
87
87
|
@prev_send_time = Time.now
|
88
88
|
end
|
89
|
-
|
89
|
+
attr_accessor :delay
|
90
90
|
attr_reader :server, :port, :ssl_params
|
91
91
|
|
92
92
|
=begin
|
@@ -217,6 +217,7 @@ module RICE
|
|
217
217
|
context.set_params(ssl_params)
|
218
218
|
conn = OpenSSL::SSL::SSLSocket.new(conn, context)
|
219
219
|
conn.sync_close = true
|
220
|
+
conn.hostname = @server if conn.respond_to? :hostname=
|
220
221
|
conn.connect
|
221
222
|
if context.verify_mode != OpenSSL::SSL::VERIFY_NONE
|
222
223
|
conn.post_connection_check(@server)
|
@@ -246,8 +247,8 @@ module RICE
|
|
246
247
|
USER_THREAD = Struct.new('User_Thread', :q, :raise_on_close)
|
247
248
|
def regist(raise_on_close = false, *args)
|
248
249
|
read_q = Queue.new
|
249
|
-
th = Thread.new(read_q, self, *args) do |
|
250
|
-
yield(
|
250
|
+
th = Thread.new(read_q, self, *args) do |read_q_, conn, *args_|
|
251
|
+
yield(read_q_, conn, *args_)
|
251
252
|
end
|
252
253
|
@threads.synchronize do
|
253
254
|
@threads[th] = USER_THREAD.new(read_q, raise_on_close)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nadoka
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kazuhiro NISHIYAMA
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2018-09-29 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Nadoka is a tool for monitoring and logging IRC conversations and responding
|
15
15
|
to specially formatted requests. You define and customize these responses in Ruby.
|
@@ -97,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
97
|
version: '0'
|
98
98
|
requirements: []
|
99
99
|
rubyforge_project:
|
100
|
-
rubygems_version: 2.
|
100
|
+
rubygems_version: 2.7.6
|
101
101
|
signing_key:
|
102
102
|
specification_version: 4
|
103
103
|
summary: IRC logger, monitor and proxy program ("bot")
|