Posted to tcl by tockitj at Wed Jul 18 14:33:08 GMT 2007view pretty

#!/usr/bin/expect
spawn socat - TCP4:irc.freenode.org:6667
set NICK($spawn_id) [ string map "%RAND [expr int(10000000 + rand()*89999999)]" Guest_%RAND ]
lappend SPAWNS $spawn_id
set timeout -1

expect {
        -i $SPAWNS 
        "NOTICE AUTH :" {
          send -i $expect_out(spawn_id) "USER A B C D\n"
          send -i $expect_out(spawn_id) "NICK $NICK($expect_out(spawn_id))\n"
          exp_continue
        }
        "VERSION" {
          send "JOIN #test_bot\n"
          exp_continue
        }
        -nocase -re "\n:\[^ \n\]* PRIVMSG (\[^ \n\]*) :!spawns*\r\r" {
          send -i $expect_out(spawn_id) "PRIVMSG $expect_out(1,string) :spawns $SPAWNS\n"
          exp_continue
        }
 	-nocase -re "PING (\[^\n\r\]*)\r\r" { 
	  send -i $expect_out(spawn_id) "PONG $expect_out(1,string)\n"
	  exp_continue
 	}
        -nocase -re "\n:(\[^\n\r!\]*)!(\[^@\n\]*)@(\[^ \n\]*) NICK :(\[^\r\n \]*)" {
          if { [ string compare $expect_out(1,string) $NICK($expect_out(spawn_id)) ] == 0 } { 
            set NICK($expect_out(spawn_id)) $expect_out(4,string) 
          }
          exp_continue
        }
        -nocase -re "\n:tockitj!~?(\[^@\n\r\]*)@(\[^ \n\r\]*) PRIVMSG (\[^ \n\r\]*) :!bot *(\[^:\n\r\]*): *(\[^\r\n\]*)\r\r" {
          if { [ string first $NICK($expect_out(spawn_id)) $expect_out(4,string) ] != -1 } {
            set COMMAND [ string map "%BOT $NICK($expect_out(spawn_id))" $expect_out(5,string) ]
            send -i $expect_out(spawn_id) "$COMMAND\n" 
          }
          exp_continue
        }
        -nocase -re "\n:(\[^!\n\r\]*)!~?(\[^@\r\n\]*)@(\[^ \r\n\]*) PRIVMSG (\[^ \r\n\]*) \: *\!echo (\[^\r\n\]*)\r\r" {
          send -i $expect_out(spawn_id) "PRIVMSG $expect_out(4,string) :$expect_out(5,string)\n"
          exp_continue
        }
       -nocase -re "\n:tockitj!~?(\[^@\n\]*)@(\[^ \n\]*) PRIVMSG (\[^ \n\]*) :!clone\r\r" {
          spawn socat - TCP4:irc.freenode.org:6667
          lappend SPAWNS $spawn_id
          set NICK($spawn_id) [ string map "%RAND [expr int(10000000 + rand()*89999999)]" Guest_%RAND ]
          set timeout -1
          exp_continue
       }
}
puts "\n*** DONE *** "