chiark / gitweb /
topicedit: add a timeout; better error handling
[ircbot.git] / topicedit.tcl
index 43ec29f9aa78674147d927fad085baca80061202..88998782d35edefc0de1c666a6262a8391f6c8b7 100755 (executable)
@@ -9,9 +9,11 @@ manyset $argv host port nick ident ownfullname channel topicinfo
 
 set done 0
 
+after 30000 { set errorInfo {}; bgerror timeout }
+
 proc bgerror {msg} {
     global errorInfo errorCode
-    puts stderr "$msg\n$errorCode\n$errorInfo\n"
+    puts stderr "$msg\n$errorCode\n$errorInfo\n\nERROR: $msg\n"
     exit 16
 }
 
@@ -43,7 +45,8 @@ proc msg_333 {server code us channel setter when} {
 }
 proc msg_366 {args} {
     global oldtopic topicinfo channel done
-    set newtopic "$oldtopic | $topicinfo"
+    if {![info exists oldtopic]} return
+    set newtopic "$topicinfo | $oldtopic"
     sendout TOPIC $channel $newtopic
     sendout TOPIC $channel
     set done 1