├── .gitignore ├── config.rb.sample └── hitozuma.rb /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | config.rb 3 | !config.rb.sample 4 | -------------------------------------------------------------------------------- /config.rb.sample: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | 3 | OPTIONS = { 4 | encode: Encoding::UTF_8, 5 | channels: ["#test", "#test2"], 6 | passes: [nil, "pass"], 7 | host: 'irc.example.com', 8 | port: 6667, 9 | nick: 'hitozuma', 10 | user: 'hitozuma', 11 | real: 'master@example.com' 12 | } 13 | -------------------------------------------------------------------------------- /hitozuma.rb: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | 3 | require 'net/irc' 4 | require 'config.rb' 5 | 6 | class NBot < Net::IRC::Client 7 | 8 | def on_rpl_welcome(m) 9 | enc = OPTIONS[:encode] 10 | OPTIONS[:channels].zip(OPTIONS[:channel_passes]) do |channel, pass| 11 | if pass 12 | #post(JOIN, channel.encode(enc), "+k", pass.encode(enc)) 13 | post(JOIN, channel.encode(enc), pass.encode(enc)) 14 | else 15 | post(JOIN, channel.encode(enc)) 16 | end 17 | end 18 | end 19 | 20 | def on_privmsg(m) 21 | super 22 | enc = OPTIONS[:encode] 23 | channel, message = *m 24 | m.prefix =~ /^(.+?)\!/ 25 | nick = $1 26 | now = Time.now 27 | ch = channel.sub(/^\#/, '') 28 | message.force_encoding(enc).encode(Encoding::UTF_8) 29 | if rand(100) == 0 30 | answer = (rand(10) != 0) ? "はい" : "いいえ" 31 | if nick 32 | message = "#{nick}: #{answer}" 33 | else 34 | message = answer 35 | end 36 | post(NOTICE, channel, message.encode(enc)) 37 | end 38 | end 39 | 40 | end 41 | 42 | Process.daemon(true) 43 | 44 | NBot.new(OPTIONS[:host], OPTIONS[:port], 45 | nick: OPTIONS[:nick], 46 | user: OPTIONS[:user], 47 | real: OPTIONS[:real]).start 48 | --------------------------------------------------------------------------------