Author: mdiep
Date: Mon Jan 8 14:36:35 2007
New Revision: 16503
Added:
trunk/languages/tcl/examples/ircbot.tcl
Modified:
trunk/MANIFEST
Log:
[tcl]: Check in the source for jane
Modified: trunk/MANIFEST
==============================================================================
--- trunk/MANIFEST (original)
+++ trunk/MANIFEST Mon Jan 8 14:36:35 2007
@@ -1822,6 +1822,7 @@
languages/tcl/examples/bench.tcl [tcl]
languages/tcl/examples/fact.tcl [tcl]
languages/tcl/examples/hello.tcl [tcl]
+languages/tcl/examples/ircbot.tcl [tcl]
languages/tcl/examples/koohii.tcl [tcl]
languages/tcl/examples/power.tcl [tcl]
languages/tcl/lib/Parrot/Test/Tcl.pm [tcl]
Added: trunk/languages/tcl/examples/ircbot.tcl
==============================================================================
--- (empty file)
+++ trunk/languages/tcl/examples/ircbot.tcl Mon Jan 8 14:36:35 2007
@@ -0,0 +1,38 @@
+
+set nick jane
+set server irc.perl.org
+set channels [list #parrot]
+
+source irc.tcl
+
+proc privmsg {who target msg} {
+ set first [string wordstart $msg 0]
+ set last [string wordend $msg 0]
+
+ if {[string range $msg $first [expr {$last-1}]] ne "expr"} return
+
+ set expr [string range $msg $last end-1]
+ if {[string first \[ $expr] != -1} return
+
+ puts "expr: '$expr'"
+ if {$target eq $::nick} {set target $who}
+ if { [catch {$::cxn privmsg $target "$who: [expr $expr]"} err] } {
+ $::cxn privmsg $target "$who: $err"
+ }
+}
+
+set cxn [irc::connection]
+
+# event handlers
+$cxn registerevent PRIVMSG {::privmsg [who] [target] [msg]}
+$cxn registerevent defaultevent {puts "(event) [header]: [msg]"}
+
+$cxn connect $server
+$cxn user $nick localhost domain www.tcl.tk
+$cxn nick $nick
+foreach channel $channels {
+ $cxn join $channel
+}
+
+# event loop
+vwait ::exit