nadoka 0.8.1 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -420,7 +420,7 @@ module Nadoka
420
420
  # use 4 gsub() because of the compatibility of RFC2813(3.2)
421
421
  ch = ch.toeuc.downcase.tr('[]\\~', '{}|^').tojis
422
422
  if ch.respond_to?(:force_encoding)
423
- ch.force_encoding('ASCII-8BIT')
423
+ ch.force_encoding(Encoding::ASCII_8BIT)
424
424
  end
425
425
  ch
426
426
  end
@@ -478,11 +478,18 @@ module Nadoka
478
478
  if format.kind_of? Proc
479
479
  text = format.call(params)
480
480
  elsif format
481
+ if format.respond_to?(:force_encoding)
482
+ format.force_encoding(Encoding::ASCII_8BIT)
483
+ end
481
484
  text = format.gsub(/\{([a-z]+)\}|\{prefix\:([a-z]+)\}/){|key|
482
485
  if $2
483
486
  method = $2.intern
484
487
  if msgobj[:orig].respond_to?(:prefix)
485
- (msgobj[:orig].prefix || '') =~ /^(.+?)\!(.+?)@(.+)/
488
+ prefix = msgobj[:orig].prefix || ''
489
+ if prefix.respond_to?(:force_encoding)
490
+ prefix.force_encoding(Encoding::ASCII_8BIT)
491
+ end
492
+ /^(.+?)\!(.+?)@(.+)/ =~ prefix
486
493
  case method
487
494
  when :nick
488
495
  $1
@@ -496,6 +503,9 @@ module Nadoka
496
503
  end
497
504
  else
498
505
  if m = msgobj[$1.intern]
506
+ if m.respond_to?(:force_encoding)
507
+ m.force_encoding(Encoding::ASCII_8BIT)
508
+ end
499
509
  m
500
510
  else
501
511
  "!!unknown attribute: #{$1}!!"
@@ -93,7 +93,7 @@ module Nadoka
93
93
  @logger.slog "Connection closed by server. Trying to reconnect."
94
94
 
95
95
  sleep @config.reconnect_delay
96
- retry
96
+ retry unless @exitting
97
97
 
98
98
  rescue NDK_ReconnectToServer
99
99
  @connected = false
@@ -107,7 +107,7 @@ module Nadoka
107
107
  @logger.slog "Reconnect request (no server response, or client request)."
108
108
 
109
109
  sleep @config.reconnect_delay
110
- retry
110
+ retry unless @exitting
111
111
 
112
112
  rescue Exception => e
113
113
  ndk_error e
@@ -173,6 +173,8 @@ module Nadoka
173
173
  when 'ERROR'
174
174
  msg = "Server login fail!(#{q})"
175
175
  @server_thread.raise NDK_ReconnectToServer
176
+ when '020'
177
+ # ignore
176
178
  else
177
179
  msg = "Server login fail!(#{q})"
178
180
  @logger.slog msg
@@ -419,9 +421,12 @@ module Nadoka
419
421
  }
420
422
 
421
423
  begin
422
- @server_thread.join
424
+ sleep
423
425
  rescue Interrupt
424
426
  @exitting = true
427
+ rescue Nadoka::NDK_Error
428
+ @exitting = true
429
+ raise
425
430
  ensure
426
431
  @server_thread.kill if @server_thread && @server_thread.alive?
427
432
  @clients_thread.kill if @clients_thread && @clients_thread.alive?
@@ -11,7 +11,7 @@
11
11
  #
12
12
 
13
13
  module Nadoka
14
- VERSION = '0.8.1'
14
+ VERSION = '0.8.2'
15
15
  NDK_Version = VERSION.dup
16
16
  NDK_Created = Time.now
17
17
 
@@ -1,3 +1,4 @@
1
+ # -*- ruby; coding: utf-8 -*- vim:set ft=ruby:
1
2
  =begin
2
3
 
3
4
  This plugin is test version.
@@ -11,15 +12,16 @@ require 'kconv'
11
12
  class DictBot < Nadoka::NDK_Bot
12
13
  def bot_initialize
13
14
  @available_channel = @bot_config[:ch] || /.*/
14
-
15
+ @nkf = @bot_config[:nkf] || "-Wj"
15
16
  end
16
17
 
17
18
 
18
19
  def on_privmsg prefix, ch, msg
19
20
  if @available_channel === ch
21
+ msg = msg.toutf8
20
22
  if /\Adic(.)>\s*(.+)\s*/ =~ msg
21
- res = yahoo_dict $1, $2.toeuc
22
- send_notice(ch, res)
23
+ res = yahoo_dict $1, $2
24
+ send_notice(ch, NKF.nkf(@nkf, res))
23
25
  end
24
26
  end
25
27
  end
@@ -36,10 +38,10 @@ class DictBot < Nadoka::NDK_Bot
36
38
  "dict bot> " +
37
39
  if type = YAHOO_DICT_TYPE[type]
38
40
  word = URI.encode(word)
39
- uri = "http://dic.yahoo.co.jp/dsearch?p=#{word}&stype=0&dtype=#{type}"
41
+ uri = "http://dic.yahoo.co.jp/dsearch?ei=UTF-8&p=#{word}&stype=0&dtype=#{type}"
40
42
  open(uri){|f|
41
43
  if /<meta name="description" content=\"(.+?)\">/ =~ f.read
42
- "#{$1.tosjis.tojis} - #{uri}"
44
+ "#{$1} - #{uri}"
43
45
  else
44
46
  uri
45
47
  end
@@ -49,5 +51,3 @@ class DictBot < Nadoka::NDK_Bot
49
51
  end
50
52
  end
51
53
  end
52
-
53
-
@@ -1,4 +1,4 @@
1
- # -*-ruby-*-
1
+ # -*-ruby; coding: utf-8 -*- vim:set ft=ruby:
2
2
  #
3
3
  # Copyright (c) 2004-2005 SASADA Koichi <ko1 at atdot.net>
4
4
  # Copyright (c) 2009, 2010 Kazuhiro NISHIYAMA
@@ -82,8 +82,9 @@ class GoogleBot < Nadoka::NDK_Bot
82
82
  def on_privmsg prefix, ch, msg
83
83
  return unless @available_channel === ch
84
84
  return if same_bot?(ch)
85
+ msg = NKF.nkf('-w', msg)
85
86
  if response = dispatch_command(msg)
86
- send_notice(ch, response)
87
+ send_notice(ch, response.send(@ch_kcode))
87
88
  end
88
89
  end
89
90
 
@@ -181,7 +182,7 @@ class GoogleBot < Nadoka::NDK_Bot
181
182
  result.gsub!(/<sup>(.+?)<\/sup>/u) { "^(#{$1})" }
182
183
  result.gsub!(/<.+?>/u, '')
183
184
  result.gsub!(/&\#215;/u, "\303\227")
184
- result.send(@ch_kcode) # NKF.nkf('-j', result)
185
+ result
185
186
  else
186
187
  "response error"
187
188
  end
@@ -201,7 +202,7 @@ class GoogleBot < Nadoka::NDK_Bot
201
202
  result = open(uri, @headers) do |f|
202
203
  JSON.parse(f.read)
203
204
  end
204
- result[1].join(", ").send(@ch_kcode)
205
+ result[1].join(", ")
205
206
  end
206
207
 
207
208
  def google_code key
@@ -310,15 +311,18 @@ class GoogleBot < Nadoka::NDK_Bot
310
311
  end
311
312
 
312
313
  def show_char_code_and_erase_tag str
313
- return CGI.unescapeHTML(erase_tag(str.toeuc)).send(@ch_kcode)
314
+ if str.respond_to?(:encode)
315
+ return CGI.unescapeHTML(erase_tag(str.toutf8))
316
+ end
317
+ return CGI.unescapeHTML(erase_tag(str.toeuc))
314
318
 
315
319
  case $KCODE
316
320
  when 'EUC', 'SJIS'
317
- CGI.unescapeHTML(str.gsub(/\<.+?\>/, '')).send(@ch_kcode)
321
+ CGI.unescapeHTML(str.gsub(/\<.+?\>/, ''))
318
322
  when 'NONE', 'UTF-8'
319
323
  begin
320
324
  str = Iconv.conv("EUC-JP", "UTF-8", str)
321
- CGI.unescapeHTML(str.gsub(/\<.+?\>/, '')).send(@ch_kcode)
325
+ CGI.unescapeHTML(str.gsub(/\<.+?\>/, ''))
322
326
  rescue => e
323
327
  "(char code problem: #{e.class}[#{e.message.dump}])"
324
328
  end
@@ -328,6 +332,9 @@ class GoogleBot < Nadoka::NDK_Bot
328
332
  end
329
333
 
330
334
  def search_char_code str
335
+ if str.respond_to?(:encode)
336
+ return str.toutf8
337
+ end
331
338
  case $KCODE
332
339
  when 'EUC', 'SJIS'
333
340
  str.toeuc
@@ -1,4 +1,4 @@
1
- # -*-ruby-*-
1
+ # -*-ruby; coding: utf-8 -*- vim:set ft=ruby:
2
2
  #
3
3
  # Copyright (C) 2004 Kazuhiro NISHIYAMA
4
4
  # All rights reserved.
@@ -14,6 +14,7 @@ BotConfig = [
14
14
  :message_file => 'message.yaml',
15
15
  :root_key => Setting_name,
16
16
  :channels => %w[#nadoka #Ruby:*.jp],
17
+ :nkf => "-Ww",
17
18
  },
18
19
  ]
19
20
  =end
@@ -29,6 +30,7 @@ class MessageBot < Nadoka::NDK_Bot
29
30
  @store = YAML::Store.new(@bot_config[:message_file])
30
31
  @root_key = @bot_config[:root_key]
31
32
  @channels = @bot_config[:channels].collect{|ch| ch.downcase }
33
+ @nkf = @bot_config[:nkf] || "-WjXm0"
32
34
  load_message
33
35
  end
34
36
 
@@ -56,7 +58,7 @@ class MessageBot < Nadoka::NDK_Bot
56
58
 
57
59
  def on_privmsg prefix, ch, msg
58
60
  user = prefix.nick
59
- c = NKF.nkf('-e', ch.to_s).downcase
61
+ c = NKF.nkf('-w', ch.to_s).downcase
60
62
  return unless @channels.include?(c)
61
63
  u = user.downcase
62
64
  now = Time.now
@@ -67,14 +69,14 @@ class MessageBot < Nadoka::NDK_Bot
67
69
  message_id_list.each do |message_id|
68
70
  h = @message[message_id]
69
71
  next if h.key?('delivered')
70
- message = "#{h['from']}���󤫤�#{h['to']}�����������#{h['body']}��"
71
- send_notice(ch, NKF.nkf('-Ej -m0', message))
72
+ message = "#{h['from']}さんから#{h['to']}さんへ伝言「#{h['body']}"
73
+ send_notice(ch, NKF.nkf(@nkf, message))
72
74
  @message[message_id]['delivered'] = now
73
75
  end
74
76
  @list.delete(key)
75
77
  save_message
76
78
  end
77
- if /^���� (\S+) (.+)$/e =~ NKF.nkf('-e -m0', msg.to_s)
79
+ if /^伝言 (\S+) (.+)$/ =~ NKF.nkf('-w', msg.to_s)
78
80
  to_nick, body = $1, $2
79
81
  @message[message_id] = {
80
82
  'from' => user,
@@ -87,10 +89,8 @@ class MessageBot < Nadoka::NDK_Bot
87
89
  @list[key] ||= []
88
90
  @list[key].push(message_id)
89
91
  save_message
90
- send_notice(ch, NKF.nkf('-Ej -m0', "#{$1}����ؤ������򾵤�ޤ��� > #{u}����"))
92
+ send_notice(ch, NKF.nkf(@nkf, "#{$1}さんへの伝言を承りました > #{u}さん"))
91
93
  end
92
94
  end
93
95
 
94
96
  end
95
-
96
-
@@ -1,4 +1,4 @@
1
- # -*-ruby-*-
1
+ # -*-ruby; coding: utf-8 -*- vim:set ft=ruby:
2
2
  #
3
3
  # Copyright (c) 2004-2005 SASADA Koichi <ko1 at atdot.net>
4
4
  #
@@ -58,11 +58,11 @@ class RSS_CheckBot < Nadoka::NDK_Bot
58
58
  def send_notice(ch, msg)
59
59
  if ch.respond_to? :each
60
60
  ch.each{|c|
61
- super(c, msg)
61
+ super(c, msg.tojis)
62
62
  sleep 5 # Flood Protection
63
63
  }
64
64
  else
65
- super(ch, msg)
65
+ super(ch, msg.tojis)
66
66
  sleep 5 # Flood Protection
67
67
  end
68
68
  end
@@ -97,14 +97,15 @@ class RSS_CheckBot < Nadoka::NDK_Bot
97
97
  items.each{|e|
98
98
  if e[:ccode] == 'UTF-8'
99
99
  begin
100
+ # convert from U+FF5E FULLWIDTH TILDE to U+301C WAVE DASH
100
101
  title = e[:title].gsub(/\357\275\236/u, "\343\200\234")
101
- title = @ic.iconv(title).tojis
102
+ title = @ic.iconv(title)
102
103
  rescue Exception
103
104
  # maybe, char code translation error
104
105
  next
105
106
  end
106
107
  else
107
- title = e[:title].tojis
108
+ title = e[:title]
108
109
  end
109
110
 
110
111
  send_notice(@ch, "rss bot: #{title} - #{e[:about]}")
@@ -118,4 +119,3 @@ class RSS_CheckBot < Nadoka::NDK_Bot
118
119
  end
119
120
 
120
121
  end
121
-
@@ -1,4 +1,4 @@
1
- # -*-ruby-*-
1
+ # -*-ruby; coding: utf-8 -*- vim:set ft=ruby:
2
2
  #
3
3
  # Copyright (c) 2004-2006 SASADA Koichi <ko1 at atdot.net>
4
4
  #
@@ -45,18 +45,14 @@ require 'kconv'
45
45
  require 'rexml/document'
46
46
  require 'date'
47
47
 
48
-
49
- class TenkiBot < Nadoka::NDK_Bot
50
-
48
+ module Tenki
51
49
  CityIDs = {}
52
50
 
53
- def bot_initialize
54
- bot_init_utils
55
-
51
+ def init_tenki
56
52
  open('http://weather.livedoor.com/forecast/rss/forecastmap.xml'){|f|
57
53
  f.each{|line|
58
54
  if /city title="(.+?)" id="(\d+)"/ =~ line
59
- CityIDs[$1.toeuc] = $2.to_i
55
+ CityIDs[$1.toutf8] = $2.to_i
60
56
  end
61
57
  }
62
58
  }
@@ -69,10 +65,10 @@ class TenkiBot < Nadoka::NDK_Bot
69
65
  REXML::Document.new f.read
70
66
  }
71
67
 
72
- title = doc.elements['/lwws/title/'].text.toeuc
73
- telop = doc.elements['/lwws/telop/'].text.toeuc
74
- link = doc.elements['/lwws/link/'].text.toeuc
75
- desc = doc.elements['/lwws/description/'].text.toeuc
68
+ title = doc.elements['/lwws/title/'].text.toutf8
69
+ telop = doc.elements['/lwws/telop/'].text.toutf8
70
+ link = doc.elements['/lwws/link/'].text.toutf8
71
+ desc = doc.elements['/lwws/description/'].text.toutf8
76
72
  max = doc.elements['/lwws/temperature/max/celsius/'].text
77
73
  min = doc.elements['/lwws/temperature/min/celsius/'].text
78
74
  date = Date.parse(doc.elements['/lwws/forecastdate/'].text)
@@ -86,15 +82,42 @@ class TenkiBot < Nadoka::NDK_Bot
86
82
  unless celsius.empty?
87
83
  celsius = "(#{celsius.join(', ')}) "
88
84
  end
89
- "#{title} (#{datestr}): #{telop} - #{celsius}#{desc} - #{link}".tojis
85
+ "#{title} (#{datestr}): #{telop} - #{celsius}#{desc} - #{link}"
86
+ end
87
+ end
88
+
89
+ if __FILE__ == $0
90
+ include Tenki
91
+ city = ARGV.shift
92
+ timing = ARGV.shift || 'today'
93
+ if city.nil?
94
+ puts "#$0 city [today|tomorrow|dayaftertomorrow]"
95
+ else
96
+ init_tenki
97
+ begin
98
+ puts tenki(city, timing)
99
+ rescue IndexError
100
+ puts "Unknown city. Check city title on http://weather.livedoor.com/forecast/rss/forecastmap.xml"
101
+ end
102
+ end
103
+ exit
104
+ end
105
+
106
+ class TenkiBot < Nadoka::NDK_Bot
107
+ include Tenki
108
+
109
+ def bot_initialize
110
+ bot_init_utils
111
+ init_tenki
112
+ @nkf = @bot_config[:nkf] || "-Wj"
90
113
  end
91
114
 
92
115
  def on_privmsg prefix, ch, msg
93
116
  return unless @available_channel === ch
94
117
  return if same_bot?(ch)
95
-
118
+ msg = NKF.nkf('-w', msg)
96
119
  if /\Atenki(|:(today|tomorrow|dayaftertomorrow))>(.+)/ =~ msg
97
- city = $3.strip.toeuc
120
+ city = $3.strip.toutf8
98
121
  timing = ($2 || 'today').strip
99
122
  begin
100
123
  result = tenki(city, timing).gsub(/\n/, ' ')
@@ -103,9 +126,7 @@ class TenkiBot < Nadoka::NDK_Bot
103
126
  rescue => e
104
127
  result = "#{e}"
105
128
  end
106
- send_notice ch, "tenki bot: #{result}"
129
+ send_notice ch, NKF.nkf(@nkf, "tenki bot: #{result}")
107
130
  end
108
131
  end
109
132
  end
110
-
111
-
@@ -555,15 +555,17 @@ module RICE
555
555
  str << @command
556
556
 
557
557
  if @params
558
- f = false
559
558
  @params.each do |param|
560
559
  str << ' '
561
- if (param == @params[-1]) && (param.size == 0 || /(^:)|(\s)/ =~ param)
560
+ param_s = param.to_s
561
+ if param_s.respond_to?(:force_encoding)
562
+ param_s = param_s.dup.force_encoding(Encoding::ASCII_8BIT)
563
+ end
564
+ if (param == @params[-1]) && (param_s.size == 0 || /\A:|\s/ =~ param_s)
562
565
  str << ':'
563
- str << param.to_s
564
- f = true
566
+ str << param_s
565
567
  else
566
- str << param.to_s
568
+ str << param_s
567
569
  end
568
570
  end
569
571
  end
@@ -658,7 +660,13 @@ E
658
660
  str << @params[0]
659
661
 
660
662
  str << ' :'
661
- str << @params[1..-1].join(' ')
663
+ if "".respond_to?(:force_encoding)
664
+ str << @params[1..-1].map{|param|
665
+ param.force_encoding(Encoding::ASCII_8BIT)
666
+ }.join(' ')
667
+ else
668
+ str << @params[1..-1].join(' ')
669
+ end
662
670
 
663
671
  str << "\x0D\x0A"
664
672
  str
@@ -695,7 +703,11 @@ E
695
703
  003,RPL_CREATED
696
704
  004,RPL_MYINFO
697
705
  005,RPL_BOUNCE
706
+ 010,RPL_REDIR
707
+ 015,RPL_MAP 016,RPL_MAPMORE 017,RPL_MAPEND 018,RPL_MAPSTART
708
+ 020,RPL_HELLO 042,RPL_YOURID 043,RPL_SAVENICK
698
709
  302,RPL_USERHOST 303,RPL_ISON 301,RPL_AWAY
710
+ 304,RPL_TEXT
699
711
  305,RPL_UNAWAY 306,RPL_NOWAWAY 311,RPL_WHOISUSER
700
712
  312,RPL_WHOISSERVER 313,RPL_WHOISOPERATOR
701
713
  317,RPL_WHOISIDLE 318,RPL_ENDOFWHOIS
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.8.1
4
+ version: 0.8.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-05-29 00:00:00.000000000 Z
13
+ date: 2012-06-29 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description: Nadoka is a tool for monitoring and logging IRC conversations and responding
16
16
  to specially formatted requests. You define and customize these responses in Ruby.