#coding:utf-8

require "watir"
require "kconv"
require "open-uri"


time = 6000

def peko_cc
	a   = "コナンバーペロッ".split(//)
	szz = (rand(a.size)+1)
	a.shuffle!.take(szz).permutation(szz).take(1).each do |m|
	  c = m.join
	  c << "「"
	  c <<
	  if a.drop(szz).size < 2
	    "ンー"    
	  else
	    a.drop(szz).shuffle.join
	  end
	  c << "ｗ"*(rand(4..35))
	  c << "」"
	  break c
	end
end


def rem_cc
  a = [
  ["ゴミ"]*5,
  "死ね",
  ].flatten

  case rand(70)
    when 0..4
     a.sample + "ｗ"*rand(2..65)
    when 4..20
      a.sample + "ゴミ"*(3..25).select(&:even?).sample + "ｗ"*rand(2..15)
    when 20..30
      a.sample + "ゴミ"*(2..6).select(&:even?).sample + "ｗ"*rand(2..55)
    when 30..40
      a.sample + a.sample + "ｗ"*rand(2..55)
    when 40..60
     	peko_cc
    else
      "ゴミ"
  end
end
# puts rem_cc
# -------------------

agent = Watir::Browser.new :ie
begin

	thread = open("http://t...content-available-to-author-only...h.net/tech/subject.txt" ).read.each_line.to_a
	thread = thread[6..14] + 
	thread.select do |m|
	  m.toutf8 =~ /C言語なら俺に
	  |py】
	  |Win32API
	  |自治スレッド
	  |何年待ってもruby以上の言語が出てこない
	  |プログラミング雑談/xi
	end
	thread.uniq!
	puts thread
	thread.sample =~ /(.*).dat/
	puts ad = "http://t...content-available-to-author-only...h.net/test/read.cgi/tech/#{$1}/l1"

#  agent.visible = true
  agent.goto ad
  sleep 1
  agent.text_field(:name, "MESSAGE").value = rem_cc  
  agent.button(:name, "submit").click
# agent.close


  sleep time + rand(1040)
rescue ; p $! ; sleep 60 ;
end while true
