[Tkabber-dev] r929 - in trunk/tkabber-plugins: . bc mute osd quiz

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Sun Feb 11 21:14:49 MSK 2007


Author: sergei
Date: 2007-02-11 21:14:45 +0300 (Sun, 11 Feb 2007)
New Revision: 929

Added:
   trunk/tkabber-plugins/quiz/quizdata.txt
Modified:
   trunk/tkabber-plugins/ChangeLog
   trunk/tkabber-plugins/bc/bc.tcl
   trunk/tkabber-plugins/mute/mute.tcl
   trunk/tkabber-plugins/osd/osd.tcl
   trunk/tkabber-plugins/quiz/quiz.tcl
Log:
	* bc/bc.tcl, quiz/quiz.tcl, osd/osd.tcl, mute/mute.tcl: Made working
	  with current Tkabber version.

	* quiz/quizdata.txt: Added short quiz data sample.


Modified: trunk/tkabber-plugins/ChangeLog
===================================================================
--- trunk/tkabber-plugins/ChangeLog	2007-02-11 14:39:45 UTC (rev 928)
+++ trunk/tkabber-plugins/ChangeLog	2007-02-11 18:14:45 UTC (rev 929)
@@ -17,6 +17,11 @@
 	* georoster/georoster.tcl, spy/spy.tcl, traffic/traffic.tcl: Save
 	  tabs on exit and restore on start.
 
+	* bc/bc.tcl, quiz/quiz.tcl, osd/osd.tcl, mute/mute.tcl: Made working
+	  with current Tkabber version.
+
+	* quiz/quizdata.txt: Added short quiz data sample.
+
 2006-02-10  Sergei Golovan <sgolovan at nes.ru>
 
 	* whiteboard/whiteboard.tcl, whiteboard/svgrender.tcl: Added

Modified: trunk/tkabber-plugins/bc/bc.tcl
===================================================================
--- trunk/tkabber-plugins/bc/bc.tcl	2007-02-11 14:39:45 UTC (rev 928)
+++ trunk/tkabber-plugins/bc/bc.tcl	2007-02-11 18:14:45 UTC (rev 929)
@@ -6,12 +6,10 @@
     set prefix {[B&C]: }
 }
 
-
-proc bc::load {filename {enc utf-8}} {
+proc bc::load_file {filename {enc utf-8}} {
     variable words
 
-    set f [file join [file dirname [info script]] $filename]
-    set fd [open $f]
+    set fd [open $filename]
     fconfigure $fd -encoding $enc
 
     set words {}
@@ -22,7 +20,18 @@
     close $fd
 }
 
-bc::load ru.dic koi8-r
+namespace eval bc {
+    # A hack (reload the script in koi8-r encoding)
+    if {![info exists words]} {
+	set file [file join [file dirname [info script]] ru.dic]
+	load_file $file koi8-r
+	set fd [open [info script]]
+	fconfigure $fd -encoding koi8-r
+	uplevel 1 [read $fd]
+	close $fd
+	return
+    }
+}
 
 proc bc::get_question {} {
     variable words
@@ -55,6 +64,7 @@
     if {$type != "groupchat"} return
     if {[string index $body 0] != "/"} return
 
+    set jid [chat::get_jid $chatid]
     lassign [textutil::splitx [string trim $body] {[\t \r\n]+}] command nick
 
     switch -- $command {
@@ -69,7 +79,7 @@
 	/bcnext {
 	    if {$nick != ""} {
 		# óÔÏÉÌÏ ÂÙ ÐÒÏ×ÅÒÉÔØ, ÞÔÏ ÀÚÅÒ × ÞÁÔÅ...
-		next $chatid "$chatid/$nick" $type
+		next $chatid "$jid/$nick" $type
 	    }
 	    return stop
 	}
@@ -100,6 +110,9 @@
     variable attempts
     variable prefix
 
+    set connid [chat::get_connid $chatid]
+    set jid [chat::get_jid $chatid]
+
     set s [string trim $body]
 
     switch -- $s {
@@ -131,10 +144,11 @@
 		incr attempts($chatid,$from)
 		set at $attempts($chatid,$from)
 
-		message::send_msg $chatid -type groupchat \
+		message::send_msg $jid -type groupchat \
 		    -body "$nick: ${prefix}íÏÌÏÄÅÃ! úÁÄÕÍÁÎÎÏÅ ÓÌÏ×Ï\
-\"$word($chatid,$from)\" ÂÙÌÏ ÏÔÇÁÄÁÎÏ ÚÁ $at\
-[lindex {. ÐÏÐÙÔËÕ ÐÏÐÙÔËÉ ÐÏÐÙÔÏË} [numgrp $at]]."
+			   \"$word($chatid,$from)\" ÂÙÌÏ ÏÔÇÁÄÁÎÏ ÚÁ $at\
+			   [lindex {. ÐÏÐÙÔËÕ ÐÏÐÙÔËÉ ÐÏÐÙÔÏË} [numgrp $at]]." \
+		    -connection $connid
 
 		add_score $chatid $nick $ww $at
 		unset word($chatid,$from)
@@ -142,8 +156,9 @@
 		return
 	    }
 	    if {[lsearch -exact $words $w] == -1} {
-		message::send_msg $chatid -type groupchat \
-		    -body "$nick: ${prefix}ñ ÎÅ ÚÎÁÀ ÓÌÏ×Á \"$w\"."
+		message::send_msg $jid -type groupchat \
+		    -body "$nick: ${prefix}ñ ÎÅ ÚÎÁÀ ÓÌÏ×Á \"$w\"." \
+		    -connection $connid
 		return
 	    }
 	    set l [string length $w]
@@ -156,8 +171,9 @@
 	    } else {
 		set attempts($chatid,$from) 1
 	    }
-	    message::send_msg $chatid -type groupchat \
-		-body "$nick: ${prefix} $w: $matches"
+	    message::send_msg $jid -type groupchat \
+		-body "$nick: ${prefix} $w: $matches" \
+		-connection $connid
 	}
     }
 }
@@ -168,14 +184,17 @@
     variable game
     variable prefix
 
+    set connid [chat::get_connid $chatid]
+    set jid [chat::get_jid $chatid]
+
     if {![info exists game($chatid)]} {
 	set game($chatid) ""
-	message::send_msg $chatid -type groupchat \
+	message::send_msg $jid -type groupchat \
 	    -body "${prefix}äÏÂÒÏ ÐÏÖÁÌÏ×ÁÔØ ÎÁ ÉÇÒÕ \"ïÔÇÁÄÁÊ ÓÌÏ×Ï\"!\
-  þÔÏÂÙ ÕÚÎÁÔØ ÐÒÁ×ÉÌÁ ÉÇÒÙ, ××ÅÄÉÔÅ !bcrules."
-	# next $chatid 
+		   þÔÏÂÙ ÕÚÎÁÔØ ÐÒÁ×ÉÌÁ ÉÇÒÙ, ××ÅÄÉÔÅ !bcrules." \
+	    -connection $connid
     } else {
-	chat::add_message $chatid $chatid error "éÇÒÁ ÕÖÅ ÚÁÐÕÝÅÎÁ" {}
+	chat::add_message $chatid $jid error "éÇÒÁ ÕÖÅ ÚÁÐÕÝÅÎÁ" {}
     }
 }
 
@@ -185,6 +204,9 @@
     variable attempts
     variable prefix
 
+    set connid [chat::get_connid $chatid]
+    set jid [chat::get_jid $chatid]
+
     if {[info exists game($chatid)]} {
 	foreach n [array names word "$chatid,*"] {
 	    unset word($n)
@@ -193,11 +215,12 @@
 	    unset attempts($n)
 	}
 	unset game($chatid)
-	message::send_msg $chatid -type groupchat \
-	    -body "${prefix}éÇÒÁ ÏÓÔÁÎÏ×ÌÅÎÁ."
+	message::send_msg $jid -type groupchat \
+	    -body "${prefix}éÇÒÁ ÏÓÔÁÎÏ×ÌÅÎÁ." \
+	    -connection $connid
 	top $chatid
     } else {
-	chat::add_message $chatid $chatid error "éÇÒÁ ÎÅ ÚÁÐÕÝÅÎÁ" {}
+	chat::add_message $chatid $jid error "éÇÒÁ ÎÅ ÚÁÐÕÝÅÎÁ" {}
     }
 }
 
@@ -206,17 +229,21 @@
     variable word
     variable prefix
 
+    set connid [chat::get_connid $chatid]
+    set jid1 [chat::get_jid $chatid]
+
     if {[info exists game($chatid)]} {
 	if {[info exists word($chatid,$jid)]} {
 	    set nick [get_nick $chatid $jid $type]
-	    message::send_msg $chatid -type $type \
-		-body "$nick: ${prefix}ðÒÅÄÙÄÕÝÅÅ ÓÌÏ×Ï: $word($chatid,$jid)."
+	    message::send_msg $jid1 -type $type \
+		-body "$nick: ${prefix}ðÒÅÄÙÄÕÝÅÅ ÓÌÏ×Ï: $word($chatid,$jid)." \
+		-connection $connid
 	}
 	
 	catch {unset word($chatid.$jid)}
 	after idle [list [namespace current]::ask $chatid $jid]
     } else {
-	chat::add_message $chatid $chatid error "éÇÒÁ ÎÅ ÚÁÐÕÝÅÎÁ" {}
+	chat::add_message $chatid $jid1 error "éÇÒÁ ÎÅ ÚÁÐÕÝÅÎÁ" {}
     }
 }
 
@@ -226,13 +253,17 @@
     variable attempts
     variable prefix
 
+    set connid [chat::get_connid $chatid]
+    set jid1 [chat::get_jid $chatid]
+
     after cancel [list [namespace current]::ask $chatid $jid]
 
     set word($chatid,$jid) [get_question]
     set attempts($chatid,$jid) 0
     set nick [get_nick $chatid $jid groupchat]
-    message::send_msg $chatid -type groupchat \
-	-body "$nick: ${prefix}óÌÏ×Ï ÚÁÇÁÄÁÎÏ. õÇÁÄÙ×ÁÊ."
+    message::send_msg $jid1 -type groupchat \
+	-body "$nick: ${prefix}óÌÏ×Ï ÚÁÇÁÄÁÎÏ. õÇÁÄÙ×ÁÊ." \
+	-connection $connid
 }
 
 
@@ -260,6 +291,9 @@
     variable top
     variable prefix
 
+    set connid [chat::get_connid $chatid]
+    set jid [chat::get_jid $chatid]
+
     if {[info exists top($chatid)]} {
 	set t [lsort -integer -increasing -index 2 $top($chatid)]
 
@@ -269,11 +303,12 @@
 	    append ts "$score\t$word\t$nick\n"
 	}
 
-	message::send_msg $chatid -type groupchat \
-	    -body "${prefix}Top scores:\n$ts"
+	message::send_msg $jid -type groupchat \
+	    -body "${prefix}Top scores:\n$ts" \
+	    -connection $connid
 	
     } else {
-	chat::add_message $chatid $chatid error "îÅÔ ÄÁÎÎÙÈ Ï top scores" {}
+	chat::add_message $chatid $jid error "îÅÔ ÄÁÎÎÙÈ Ï top scores" {}
     }
 }
 
@@ -306,6 +341,8 @@
 proc bc::printrules {chatid to} {
     variable game
 
+    set connid [chat::get_connid $chatid]
+
     if {[info exists game($chatid)]} {
 	message::send_msg $to -type chat \
 	    -body "ðÒÁ×ÉÌÁ ÉÇÒÙ \"ïÔÇÁÄÁÊ ÓÌÏ×Ï\"\n\
@@ -318,7 +355,8 @@
 × ÎÁÚ×ÁÎÎÏÍ.\n\
 3) åÓÌÉ ÓÌÏ×Ï ÕÇÁÄÁÎÏ, ÔÏ ÉÇÒÁ ÚÁËÁÎÞÉ×ÁÅÔÓÑ.\n\
 \n\
-äÌÑ ÔÏÇÏ, ÞÔÏÂÙ ÚÁÐÕÓÔÉÔØ ÉÇÒÕ, ×ÅÒÎÉÔÅÓØ × ËÏÎÆÅÒÅÎÃÉÀ É ÎÁÂÅÒÉÔÅ !bcstart"
+äÌÑ ÔÏÇÏ, ÞÔÏÂÙ ÚÁÐÕÓÔÉÔØ ÉÇÒÕ, ×ÅÒÎÉÔÅÓØ × ËÏÎÆÅÒÅÎÃÉÀ É ÎÁÂÅÒÉÔÅ !bcstart" \
+	    -connection $connid
     }
 }
 

Modified: trunk/tkabber-plugins/mute/mute.tcl
===================================================================
--- trunk/tkabber-plugins/mute/mute.tcl	2007-02-11 14:39:45 UTC (rev 928)
+++ trunk/tkabber-plugins/mute/mute.tcl	2007-02-11 18:14:45 UTC (rev 929)
@@ -3,43 +3,46 @@
 set ::NS(mute_ancestor) "http://jabber.org/protocol/mute#ancestor"
 set ::NS(mute_editor) "http://jabber.org/protocol/mute#editor"
 
+package require msgcat
+
 namespace eval mute {}
-namespace eval mute::editor {}
-
-proc mute::editor::get_winid {jid id} {
-    return [win_id mute $jid//@mute@//$id]
+namespace eval mute::editor {
+    ::msgcat::mcload [file join [file dirname [info script]] msgs]
 }
 
-proc mute::editor::add_user_menu_item {m connid jids} {
-    ifacetk::roster::add_menu_item $m "MUTE" \
-	[list eval [namespace current]::list_request \$curuser] $jids
+proc mute::editor::get_winid {connid jid id} {
+    return [win_id mute [list $connid $jid]//@mute@//$id]
 }
 
-hook::add roster_create_user_menu_hook \
-    [namespace current]::mute::editor::add_user_menu_item
-
-proc mute::editor::add_groupchat_user_menu_item {m connid jid} {
-    $m add command -label "MUTE" \
-	-command [list eval [namespace current]::list_request $jid]
+proc mute::editor::add_user_menu_item {m connid jid} {
+    $m add command \
+	-label [::msgcat::mc "MUTE"] \
+	-command [list [namespace current]::list_request $connid $jid]
 }
 
 hook::add roster_create_groupchat_user_menu_hook \
-    [namespace current]::mute::editor::add_groupchat_user_menu_item
+    [namespace current]::mute::editor::add_user_menu_item 49
+hook::add chat_create_user_menu_hook \
+    [namespace current]::mute::editor::add_user_menu_item 49
+hook::add roster_jid_popup_menu_hook \
+    [namespace current]::mute::editor::add_user_menu_item 49
 
 
-proc mute::editor::list_request {jid} {
+proc mute::editor::list_request {connid jid} {
     jlib::send_iq get \
 	[jlib::wrapper:createtag list \
 	     -vars [list xmlns $::NS(mute_ancestor)]] \
-	-to $jid -command [list [namespace current]::list_recv $jid]
+	-to $jid \
+	-command [list [namespace current]::list_recv $connid $jid] \
+	-connection $connid
 }
 
-proc mute::editor::list_recv {jid res child} {
+proc mute::editor::list_recv {connid jid res child} {
     variable txts
 
     if {$res != "OK"} {
 	after idle MessageDlg .mute_list_error -icon error \
-	    -message [list "Error getting list: $child"] \
+	    -message [::msgcat::mc "Error getting list: %s" [error_to_string $child]] \
 	    -type ok
 	return ""
     }
@@ -54,18 +57,18 @@
 	set desc($id) [jlib::wrapper:getattr $vars1 desc]
     }
 
-    set w .chess_invite
+    set w .mute_invite
 
     if {[winfo exists $w]} {
 	destroy $w
     }
 
-    Dialog $w -title "List of texts from $jid" \
+    Dialog $w -title [::msgcat::mc "List of texts from %s" $jid] \
 	-separator 1 -anchor e -default 0
 
     foreach id $ids {
 	$w add -text "$id: $desc($id)" \
-	    -command [list [namespace current]::subscribe_request $jid $id]
+	    -command [list [namespace current]::subscribe_request $connid $jid $id]
     }
 
     $w add -text Cancel -command [list destroy $w]
@@ -73,77 +76,77 @@
     $w draw
 }
 
-proc mute::editor::subscribe_request {jid id} {
+proc mute::editor::subscribe_request {connid jid id} {
     jlib::send_iq set \
 	[jlib::wrapper:createtag subscribe \
 	     -vars [list xmlns $::NS(mute_ancestor)] \
 	     -subtags [list [jlib::wrapper:createtag item \
 				 -vars [list id $id]]]] \
-	-to $jid -command [list [namespace current]::subscribe_recv $jid $id]
+	-to $jid \
+	-command [list [namespace current]::subscribe_recv $connid $jid $id] \
+	-connection $connid
 }
 
-proc mute::editor::subscribe_recv {jid id res child} {
+proc mute::editor::subscribe_recv {connid jid id res child} {
     variable txts
 
     if {$res != "OK"} {
 	after idle MessageDlg .mute_list_error -icon error \
-	    -message [list "Error getting list: $child"] \
+	    -message [::msgcat::mc "Error getting list: %s" [error_to_string $child]] \
 	    -type ok
 	return ""
     }
-
-
 }
 
-proc mute::editor::open_win {jid id} {
+proc mute::editor::open_win {connid jid id} {
     global font
     variable txts
 
-    set w [get_winid $jid $id]
+    set w [get_winid $connid $jid $id]
     if {[winfo exists $w]} {
 	return
     }
 
-    add_win $w -title "Edit $id" -tabtitle "Edit $id" \
-	-class Mute
+    add_win $w -title [::msgcat::mc "Edit %s" $id] \
+	       -tabtitle [::msgcat::mc "Edit %s" $id] \
+	       -class Mute
 
+    set bbox [ButtonBox $w.bbox -spacing 10 -padx 10]
+    pack $bbox -side bottom -anchor e
+
+    $bbox add -text [::msgcat::mc "Commit current version"] \
+	-command [list [namespace current]::commit $connid $jid $id]
+    $bbox add -text [::msgcat::mc "Revert to master version"] \
+	-command [list [namespace current]::revert $connid $jid $id]
+
+    set sep [Separator::create $w.sep -orient horizontal]
+    pack $sep -pady 2m -fill x -side bottom
+
     set sw [ScrolledWindow $w.sw]
     set text [text $w.text -font $font]
     pack $sw -side top -anchor w -expand yes -fill both
     $sw setwidget $text
-
-    bind $text <Control-Key-c> \
-	[list [namespace current]::commit [double% $jid] [double% $id]]
-
-    set sep [Separator::create $w.sep -orient horizontal]
-    pack $sep -pady 2m -fill x -side top
-
-    set bbox [ButtonBox $w.bbox -spacing 10 -padx 10]
-    pack $bbox -side top -anchor e
-
-    $bbox add -text "Revert to master version" \
-	-command [list [namespace current]::revert $jid $id]
 }
 
-proc mute::editor::get_textw {jid id} {
-    return "[get_winid $jid $id].text"
+proc mute::editor::get_textw {connid jid id} {
+    return "[get_winid $connid $jid $id].text"
 }
 
-proc mute::editor::set_text {jid id text} {
+proc mute::editor::set_text {connid jid id text} {
     variable txts
 
-    set txts(text,$jid,$id) $text
-    set t [get_textw $jid $id]
+    set txts(text,$connid,$jid,$id) $text
+    set t [get_textw $connid $jid $id]
 
     $t delete 1.0 end
     $t insert 0.0 $text
 }
 
-proc mute::editor::revert {jid id} {
+proc mute::editor::revert {connid jid id} {
     variable txts
 
-    set text $txts(text,$jid,$id)
-    set tw [get_textw $jid $id]
+    set text $txts(text,$connid,$jid,$id)
+    set tw [get_textw $connid $jid $id]
 
     lassign [split [$tw index insert] .] line pos
     $tw delete 1.0 end
@@ -151,12 +154,12 @@
     $tw mark set insert "$line.$pos"
 }
 
-proc mute::editor::commit {jid id} {
+proc mute::editor::commit {connid jid id} {
     variable txts
 
-    set orig $txts(text,$jid,$id)
+    set orig $txts(text,$connid,$jid,$id)
 
-    set tw [get_textw $jid $id]
+    set tw [get_textw $connid $jid $id]
     set edit [$tw get 1.0 "end -1 chars"]
 
     if {[cindex $edit end] != "\n"} {
@@ -193,23 +196,24 @@
 		 -vars [list xmlns $::NS(mute_ancestor) id $id] \
 		 -chdata $diff] \
 	    -to $jid \
-	    -command [list [namespace current]::patch_res $jid $id]
+	    -command [list [namespace current]::patch_res $connid $jid $id] \
+	    -connection $connid
     }
 }
 
-proc mute::editor::patch_res {jid id res child} {
+proc mute::editor::patch_res {connid jid id res child} {
     variable txts
 
     if {$res != "OK"} {
 	after idle MessageDlg .mute_list_error -icon error \
-	    -message [list "Error patching: $child"] \
+	    -message [::msgcat::mc "Error patching: %s" [error_to_string $child]] \
 	    -type ok
 	return ""
     }
 
-    set text $txts(text,$jid,$id)
+    set text $txts(text,$connid,$jid,$id)
 
-    set tw [get_textw $jid $id]
+    set tw [get_textw $connid $jid $id]
 
     lassign [split [$tw index insert] .] line pos
     $tw delete 1.0 end
@@ -217,16 +221,16 @@
     $tw mark set insert "$line.$pos"
 }
 
-proc mute::editor::patch {jid id patch} {
+proc mute::editor::patch {connid jid id patch} {
     variable txts
 
-    set tw [get_textw $jid $id]
+    set tw [get_textw $connid $jid $id]
 
-    if {![info exists txts(text,$jid,$id)] || ![winfo exists $tw]} {
-	return [list error 405 "Not Allowed"]
+    if {![info exists txts(text,$connid,$jid,$id)] || ![winfo exists $tw]} {
+	return [list error cancel not-allowed]
     }
 
-    set text $txts(text,$jid,$id)
+    set text $txts(text,$connid,$jid,$id)
 
     set edit [$tw get 1.0 "end -1 chars"]
 
@@ -274,7 +278,7 @@
 
     file delete $fn.old $fn.orig $fn.patch $fn.edit
 
-    set txts(text,$jid,$id) $new
+    set txts(text,$connid,$jid,$id) $new
 
     $tw delete 1.0 end
     $tw insert 0.0 $newedit
@@ -300,16 +304,16 @@
     switch -- $tag {
 	text {
 	    set id [jlib::wrapper:getattr $vars id]
-	    open_win $from $id
-	    set_text $from $id $chdata
+	    open_win $connid $from $id
+	    set_text $connid $from $id $chdata
 	}
 	patch {
 	    set id [jlib::wrapper:getattr $vars id]
 	    set patch $chdata
-	    return [patch $from $id $patch]
+	    return [patch $connid $from $id $patch]
 	}
 	default {
-	    return [list error 501 "Not Implemented"]
+	    return [list error cancel feature-not-implemented]
 	}
     }
 }
@@ -342,24 +346,23 @@
     set txts(text,id2) ""
 }
 
-
-
-proc mute::ancestor::send_text {jid id} {
+proc mute::ancestor::send_text {connid jid id} {
     variable txts
 
     jlib::send_iq set \
 	[jlib::wrapper:createtag text \
 	     -vars [list xmlns $::NS(mute_editor) id $id] \
-	     -chdata $txts(text,$id)] \
-	-to $jid
-# -command [list [namespace current]::subscribe_recv $jid $id]
+	     -chdata $txts(text,$connid,$id)] \
+	-to $jid \
+	-connection $connid
+#	-command [list [namespace current]::subscribe_recv $connid $jid $id]
 }
 
 
-proc mute::ancestor::patch {jid id patch} {
+proc mute::ancestor::patch {connid jid id patch} {
     variable txts
 
-    set text $txts(text,$id)
+    set text $txts(text,$connid,$id)
 
     # TODO: check temp files
     set fn "/tmp/mute[random 1000000]"
@@ -375,9 +378,7 @@
     close $fd
 
     if {[catch { exec patch $fn.orig $fn.patch }]} {
-
-
-	return [list error 405 "Not Allowed"]
+	return [list error cancel not-allowed]
     }
 
     set fd [open $fn.orig r]
@@ -387,32 +388,34 @@
 
     file delete $fn.orig $fn.patch
 
-    set txts(text,$id) $new
-    after idle [list [namespace current]::distribute_patch $id $patch]
+    set txts(text,$connid,$id) $new
+    after idle [list [namespace current]::distribute_patch $connid $id $patch]
 
     return [list result ""]
 }
 
-proc mute::ancestor::distribute_patch {id patch} {
+proc mute::ancestor::distribute_patch {connid id patch} {
     variable txts
 
-    foreach subscriber $txts(subscribed,$id) {
+    foreach subscriber $txts(subscribed,$connid,$id) {
 	jlib::send_iq set \
 	    [jlib::wrapper:createtag patch \
 		 -vars [list xmlns $::NS(mute_editor) id $id] \
 		 -chdata $patch] \
 	    -to $subscriber \
 	    -command [list [namespace current]::unsubscribe_on_error \
-			  $subscriber $id]
+			  $connid $subscriber $id] \
+	    -connection $connid
     }
 }
 
-proc mute::ancestor::unsubscribe_on_error {jid id res child} {
+proc mute::ancestor::unsubscribe_on_error {connid jid id res child} {
+    variable txts
+
     if {$res != "OK"} {
-	variable txts
-	set idx [lsearch -exact $txts(subscribed,$id) $jid]
-	set txts(subscribed,$id) [lreplace $txts(subscribed,$id) $idx $idx]
-	puts "REMOVE $jid"
+	set idx [lsearch -exact $txts(subscribed,$connid,$id) $jid]
+	set txts(subscribed,$connid,$id) [lreplace $txts(subscribed,$connid,$id) $idx $idx]
+	puts "REMOVE $connid $jid"
     }
 }
 
@@ -422,17 +425,26 @@
     switch -- $tag {
 	list {
 	    variable txts
+	    # TODO
+	    if {![info exists txts(ids,$connid)]} {
+		set txts(ids,$connid) $txts(ids)
+		foreach id $txts(ids) {
+		    set txts(desc,$connid,$id) $txts(desc,$id)
+		    set txts(text,$connid,$id) $txts(text,$id)
+		}
+	    }
+
 	    set items {}
-	    foreach id $txts(ids) {
+	    foreach id $txts(ids,$connid) {
 		lappend items [jlib::wrapper:createtag item \
-				   -vars [list id $id desc $txts(desc,$id)]]
+				   -vars [list id $id desc $txts(desc,$connid,$id)]]
 	    }
 	    return [list result [jlib::wrapper:createtag list \
 				     -vars [list xmlns $::NS(mute_ancestor)] \
 				     -subtags $items]]
 	}
 	default {
-	    return [list error 501 "Not Implemented"]
+	    return [list error cancel feature-not-implemented]
 	}
     }
     return ""
@@ -450,27 +462,27 @@
 	    variable txts
 
 	    foreach ch $children {
-		jlib::wrapper:splitxml $ch \
-		    tag1 vars1 isempty1 chdata1 children1
+		jlib::wrapper:splitxml $ch tag1 vars1 isempty1 chdata1 children1
+
 		set id [jlib::wrapper:getattr $vars1 id]
-		if {[lcontain $txts(ids) $id]} {
-		    lappend txts(subscribed,$id) $from
-		    set txts(subscribed,$id) [lrmdups $txts(subscribed,$id)]
-		    after idle [list [namespace current]::send_text $from $id]
+		if {[lcontain $txts(ids,$connid) $id]} {
+		    lappend txts(subscribed,$connid,$id) $from
+		    set txts(subscribed,$connid,$id) [lrmdups $txts(subscribed,$connid,$id)]
+		    after idle [list [namespace current]::send_text $connid $from $id]
 		    return [list result ""]
 		} else {
-		    return [list error 400 "Bad request"]
+		    return [list error modify bad-request]
 		}
 	    }
-	    return [list error 400 "Bad request"]
+	    return [list error modify bad-request]
 	}
 	patch {
 	    set id [jlib::wrapper:getattr $vars id]
 	    set patch $chdata
-	    return [patch $from $id $patch]
+	    return [patch $connid $from $id $patch]
 	}
 	default {
-	    return [list error 501 "Not Implemented"]
+	    return [list error cancel feature-not-implemented]
 	}
     }
     return ""

Modified: trunk/tkabber-plugins/osd/osd.tcl
===================================================================
--- trunk/tkabber-plugins/osd/osd.tcl	2007-02-11 14:39:45 UTC (rev 928)
+++ trunk/tkabber-plugins/osd/osd.tcl	2007-02-11 18:14:45 UTC (rev 929)
@@ -43,7 +43,7 @@
     }
 }
 
-proc ::osd::presence_notify {connid from type x opts} {
+proc ::osd::presence_notify {connid from type x args} {
     variable statuses
 
     if {[catch  { set nick [get_nick $connid $from chat] }]} {
@@ -59,7 +59,7 @@
 
     set status ""
     set show ""
-    foreach {attr val} $opts {
+    foreach {attr val} $args {
 	switch -- $attr {
 	    -status   {set status $val}
 	    -show     {set show   $val}

Modified: trunk/tkabber-plugins/quiz/quiz.tcl
===================================================================
--- trunk/tkabber-plugins/quiz/quiz.tcl	2007-02-11 14:39:45 UTC (rev 928)
+++ trunk/tkabber-plugins/quiz/quiz.tcl	2007-02-11 18:14:45 UTC (rev 929)
@@ -1,20 +1,14 @@
 # $Id$
 
-if {![file readable [file join [file dirname [info script]] 3hauka.txt]]} {
-    puts "Can't find file 3hauka.txt"
-    return
-}
-
 namespace eval quiz {
     set prefix {[QUIZ]: }
 }
 
 
-proc quiz::load {filename {enc utf-8}} {
+proc quiz::load_file {filename {enc utf-8}} {
     variable questions
 
-    set f [file join [file dirname [info script]] $filename]
-    set fd [open $f]
+    set fd [open $filename]
     fconfigure $fd -encoding $enc
 
     set questions(qa) {}
@@ -32,9 +26,22 @@
     close $fd
 }
 
-quiz::load 3hauka.txt koi8-r
+namespace eval quiz {
+    # A hack (reload the script in koi8-r encoding)
+    if {![info exists questions(qa)]} {
+	set file [file join [file dirname [info script]] quizdata.txt]
+	if {[catch {load_file $file koi8-r}]} {
+	    puts "Can't load file $file"
+	    return
+	}
+	set fd [open [info script]]
+	fconfigure $fd -encoding koi8-r
+	uplevel 1 [read $fd]
+	close $fd
+	return
+    }
+}
 
-
 proc quiz::get_question {} {
     variable questions
 
@@ -66,8 +73,6 @@
 proc quiz::handle_commands {chatid user body type} {
     variable game
 
-    set jid [chat::get_jid $chatid]
-
     if {$type != "groupchat"} return
     if {[string index $body 0] != "/"} return
 
@@ -75,19 +80,19 @@
 
     switch -- $command {
 	/quizstart {
-	    start $jid
+	    start $chatid
 	    return stop
 	}
 	/quizstop {
-	    stop $jid
+	    stop $chatid
 	    return stop
 	}
 	/quiznext {
-	    next $jid
+	    next $chatid
 	    return stop
 	}
 	/quiztop {
-	    top $jid
+	    top $chatid
 	    return stop
 	}
     }
@@ -108,7 +113,7 @@
     variable prefix
 
     set connid [chat::get_connid $chatid]
-    set chatid [chat::get_jid $chatid]
+    set group [chat::get_jid $chatid]
 
     set s [string trim $body]
 
@@ -163,16 +168,18 @@
 		    set stats(quick,$chatid) $time
 		}
 
-		message::send_msg $chatid -type groupchat \
+		message::send_msg $group -type groupchat \
 		    -body "${prefix}íÏÌÏÄÅÃ, $nick!  ðÒÁ×ÉÌØÎÙÊ\
 ÏÔ×ÅÔ \"$answer($chatid)\" ÂÙÌ ÄÁÎ ÚÁ $time [lindex {. ÓÅËÕÎÄÕ ÓÅËÕÎÄÙ \
 ÓÅËÕÎÄ} [numgrp $time]]$msg_time\
 É ÐÒÉÎ£Ó ÔÅÂÅ $points($chatid) [lindex {. ÏÞËÏ ÏÞËÁ ÏÞËÏ×} [numgrp \
-$points($chatid)]]."
+$points($chatid)]]." \
+		    -connection $connid
 
 		if {[info exists msg_cont]} {
-		    message::send_msg $chatid -type groupchat \
-			-body $msg_cont
+		    message::send_msg $group -type groupchat \
+			-body $msg_cont \
+			-connection $connid
 		}
 
 		add_score $chatid $nick $points($chatid) $time
@@ -192,16 +199,19 @@
     variable game
     variable prefix
 
+    set connid [chat::get_connid $chatid]
+    set group [chat::get_jid $chatid]
+
     if {![info exists game($chatid)]} {
 	set game($chatid) ""
-	message::send_msg $chatid -type groupchat \
-	    -body "${prefix}äÏÂÒÏ ÐÏÖÁÌÏ×ÁÔØ ÎÁ ÎÁÛÕ ×ÉËÔÏÒÉÎÕ!\
-  îÁÞÉÎÁÅÍ ÉÇÒÕ."
+	message::send_msg $group -type groupchat \
+	    -body "${prefix}äÏÂÒÏ ÐÏÖÁÌÏ×ÁÔØ ÎÁ ÎÁÛÕ ×ÉËÔÏÒÉÎÕ! îÁÞÉÎÁÅÍ ÉÇÒÕ." \
+	    -connection $connid
 	variable lost
 	set lost($chatid) 0
 	next $chatid
     } else {
-	chat::add_message $chatid $chatid error "÷ÉËÔÏÒÉÎÁ ÕÖÅ ÚÁÐÕÝÅÎÁ" {}
+	chat::add_message $chatid $group error "÷ÉËÔÏÒÉÎÁ ÕÖÅ ÚÁÐÕÝÅÎÁ" {}
     }
 }
 
@@ -210,6 +220,9 @@
     variable question
     variable prefix
 
+    set connid [chat::get_connid $chatid]
+    set group [chat::get_jid $chatid]
+
     if {[info exists game($chatid)]} {
 	after cancel [list [namespace current]::ask $chatid]
 	after cancel [list [namespace current]::next $chatid]
@@ -219,11 +232,12 @@
 	catch { unset question($chatid) }
 	catch { unset answer($chatid) }
 	unset game($chatid)
-	message::send_msg $chatid -type groupchat \
-	    -body "${prefix}÷ÉËÔÏÒÉÎÁ ÏÓÔÁÎÏ×ÌÅÎÁ."
+	message::send_msg $group -type groupchat \
+	    -body "${prefix}÷ÉËÔÏÒÉÎÁ ÏÓÔÁÎÏ×ÌÅÎÁ." \
+	    -connection $connid
 	top $chatid
     } else {
-	chat::add_message $chatid $chatid error "÷ÉËÔÏÒÉÎÁ ÎÅ ÚÁÐÕÝÅÎÁ" {}
+	chat::add_message $chatid $group error "÷ÉËÔÏÒÉÎÁ ÎÅ ÚÁÐÕÝÅÎÁ" {}
     }
 }
 
@@ -234,6 +248,9 @@
     variable hint
     variable prefix
 
+    set connid [chat::get_connid $chatid]
+    set group [chat::get_jid $chatid]
+
     after cancel [list [namespace current]::ask $chatid]
     after cancel [list [namespace current]::next $chatid]
     after cancel [list [namespace current]::hint $chatid]
@@ -244,9 +261,10 @@
 	    variable lost
 	    incr lost($chatid)
 	    if {$lost($chatid) > 4} {
-		message::send_msg $chatid -type groupchat \
+		message::send_msg $group -type groupchat \
 		    -body "${prefix}îÕ ÎÅ ÈÏÔÉÔÅ ÐÒÁ×ÉÌØÎÏ ÏÔ×ÅÞÁÔØ\
--- É ÎÅ ÎÁÄÏ :-/"
+			   -- É ÎÅ ÎÁÄÏ :-/" \
+		    -connection $connid
 		stop $chatid
 		return
 	    }
@@ -255,9 +273,10 @@
 	    catch { unset last(nick,$chatid) }
 	    catch { unset last(num,$chatid) }
 
-	    message::send_msg $chatid -type groupchat \
+	    message::send_msg $group -type groupchat \
 		-body "${prefix}îÉËÔÏ ÎÅ ÏÔ×ÅÔÉÌ ÎÁ ×ÏÐÒÏÓ, ÓÌÅÄÕÀÝÉÊ ÞÅÒÅÚ\
-5 ÓÅËÕÎÄ."
+		       5 ÓÅËÕÎÄ." \
+		-connection $connid
 	}
 	
 	catch { unset question($chatid) }
@@ -265,7 +284,7 @@
 	catch { unset hint($chatid) }
 	after 5000 [list [namespace current]::ask $chatid]
     } else {
-	chat::add_message $chatid $chatid error "÷ÉËÔÏÒÉÎÁ ÎÅ ÚÁÐÕÝÅÎÁ" {}
+	chat::add_message $chatid $group error "÷ÉËÔÏÒÉÎÁ ÎÅ ÚÁÐÕÝÅÎÁ" {}
     }
 }
 
@@ -277,14 +296,18 @@
     variable asktime
     variable prefix
 
+    set connid [chat::get_connid $chatid]
+    set group [chat::get_jid $chatid]
+
     after cancel [list [namespace current]::ask $chatid]
     after cancel [list [namespace current]::next $chatid]
 
     lassign [get_question] question($chatid) answer($chatid)
     set points($chatid) 3
     set asktime($chatid) [clock seconds]
-    message::send_msg $chatid -type groupchat \
-	-body "${prefix}$question($chatid)"
+    message::send_msg $group -type groupchat \
+	-body "${prefix}$question($chatid)" \
+	-connection $connid
 
     after 60000 [list [namespace current]::next $chatid]
 }
@@ -297,6 +320,9 @@
     variable points
     variable prefix
 
+    set connid [chat::get_connid $chatid]
+    set group [chat::get_jid $chatid]
+
     if {![info exists game($chatid)] || \
 	    ![info exists answer($chatid)] || \
 	    ([info exists hint($chatid)] && !$cont)} return
@@ -310,7 +336,8 @@
 
     message::send_msg $chatid -type groupchat \
 	-body "${prefix}ðÏÄÓËÁÚËÁ: [crange $answer($chatid) \
-0 [expr 3 - $points($chatid)]]...?"
+	       0 [expr 3 - $points($chatid)]]...?" \
+	-connection $connid
     
     after 20000 [list [namespace current]::hint $chatid 1]
 }
@@ -341,6 +368,9 @@
     variable prefix
     variable stats
 
+    set connid [chat::get_connid $chatid]
+    set group [chat::get_jid $chatid]
+
     if {[info exists top($chatid)]} {
 	set t [lsort -integer -decreasing -index 1 $top($chatid)]
 
@@ -356,11 +386,12 @@
 	    append ts "$score\t$avgp\t$answ\t$quick\t$avgt\t$nick\n"
 	}
 
-	message::send_msg $chatid -type groupchat \
+	message::send_msg $group -type groupchat \
 	    -body "${prefix}Top scores:
-points\tavg p\tansw\tmin t\tavg t\tnick\n$ts"
+points\tavg p\tansw\tmin t\tavg t\tnick\n$ts" \
+	    -connection $connid
     } else {
-	chat::add_message $chatid $chatid error "îÅÔ ÄÁÎÎÙÈ Ï top scores" {}
+	chat::add_message $chatid $group error "îÅÔ ÄÁÎÎÙÈ Ï top scores" {}
     }
 }
 

Added: trunk/tkabber-plugins/quiz/quizdata.txt
===================================================================
--- trunk/tkabber-plugins/quiz/quizdata.txt	                        (rev 0)
+++ trunk/tkabber-plugins/quiz/quizdata.txt	2007-02-11 18:14:45 UTC (rev 929)
@@ -0,0 +1,5 @@
+ðÏÓÌÅÄÏ×ÁÔÅÌØÎÏÅ ÉÚÌÏÖÅÎÉÅ ÓÁÍÉÍ ÇÏ×ÏÒÑÝÉÍ ÉÌÉ ÐÉÛÕÝÉÍ ÏÓÎÏ×ÎÙÈ ÜÔÁÐÏ× ÅÇÏ ÖÉÚÎÉ.|Á×ÔÏÂÉÏÇÒÁÆÉÑ
+íÕÚÙËÁÌØÎÏÅ ÓÏÐÒÏ×ÏÖÄÅÎÉÅ ÓÏÌØÎÏÊ ×ÏËÁÌØÎÏÊ ÉÌÉ ÉÎÓÔÒÕÍÅÎÔÁÌØÎÏÊ ÐÁÒÔÉÉ, ÏÓÎÏ×ÎÏÊ ÔÅÍÙ ÉÌÉ ÍÅÌÏÄÉÉ ÍÕÚÙËÁÌØÎÏÇÏ ÐÒÏÉÚ×ÅÄÅÎÉÑ.|ÁËËÏÍÐÁÎÅÍÅÎÔ
+óÉÓÔÅÍÁ ×ÚÇÌÑÄÏ× ÎÁ ÒÁÚ×ÉÔÉÅ ÏÒÇÁÎÉÞÅÓËÏÇÏ ÍÉÒÁ, ÏÔÒÉÃÁÀÝÁÑ ÂÉÏÌÏÇÉÞÅÓËÕÀ Ü×ÏÌÀÃÉÀ ×ÏÏÂÝÅ ÉÌÉ ÕÞÅÎÉÅ Ï ÅÓÔÅÓÔ×ÅÎÎÏÍ ÏÔÂÏÒÅ.|ÁÎÔÉÄÁÒ×ÉÎÉÚÍ
+óÔÒÏÉÔÅÌØÓÔ×Ï ÂÁÒÖ.|ÂÁÒÖÅÓÔÒÏÅÎÉÅ
+îÅÄÏÓÔÁÔÏË ÈÕÄÏÖÅÓÔ×ÅÎÎÏÊ ÏÂÒÁÚÎÏÓÔÉ (× ÐÒÏÉÚ×ÅÄÅÎÉÉ ÉÓËÕÓÓÔ×Á, ÌÉÔÅÒÁÔÕÒÙ).|ÂÅÚÏÂÒÁÚÎÏÓÔØ


Property changes on: trunk/tkabber-plugins/quiz/quizdata.txt
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native



More information about the Tkabber-dev mailing list