[Tkabber-dev] r1679 - in trunk/tkabber-plugins: . bc quiz

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Sat Feb 21 00:16:56 MSK 2009


Author: sergei
Date: 2009-02-21 00:16:56 +0300 (Sat, 21 Feb 2009)
New Revision: 1679

Modified:
   trunk/tkabber-plugins/ChangeLog
   trunk/tkabber-plugins/bc/bc.tcl
   trunk/tkabber-plugins/quiz/quiz.tcl
Log:
	* bc/bc.tcl, quiz/quiz.tcl: Made B&C and Quiz plugins unloadable.


Modified: trunk/tkabber-plugins/ChangeLog
===================================================================
--- trunk/tkabber-plugins/ChangeLog	2009-02-20 14:09:53 UTC (rev 1678)
+++ trunk/tkabber-plugins/ChangeLog	2009-02-20 21:16:56 UTC (rev 1679)
@@ -4,6 +4,8 @@
 	  debug/debug.tcl, socials/socials.tcl: Moved plugin preloading code
 	  to the main plugin files.
 
+	* bc/bc.tcl, quiz/quiz.tcl: Made B&C and Quiz plugins unloadable.
+
 2009-02-19  Sergei Golovan <sgolovan at nes.ru>
 
 	* attline/msgs/de.msg, debug/msgs/de.msg: Updated German translation

Modified: trunk/tkabber-plugins/bc/bc.tcl
===================================================================
--- trunk/tkabber-plugins/bc/bc.tcl	2009-02-20 14:09:53 UTC (rev 1678)
+++ trunk/tkabber-plugins/bc/bc.tcl	2009-02-20 21:16:56 UTC (rev 1679)
@@ -1,11 +1,28 @@
 # $Id$
 
-package require textutil
+package require msgcat
 
 namespace eval bc {
+    ::msgcat::mcload [file join [file dirname [info script]] msgs]
+
+    if {![::plugins::is_registered bc]} {
+	::plugins::register bc \
+			    -namespace [namespace current] \
+			    -source [info script] \
+			    -description [::msgcat::mc "Whether the 'Bulls & Cows' plugin is loaded.\
+							The plugin implements game variant where\
+							players guess Russian words instead of numbers\
+							as usual."] \
+			    -loadcommand [namespace code load] \
+			    -unloadcommand [namespace code unload]
+	return
+    }
+
     set prefix {[B&C]: }
 }
 
+package require textutil
+
 proc bc::load_file {filename {enc utf-8}} {
     variable words
 
@@ -33,6 +50,42 @@
     }
 }
 
+proc bc::load {} {
+    hook::add draw_message_hook [namespace current]::handle_messages 79
+    hook::add generate_completions_hook \
+	      [namespace current]::commands_comps
+    hook::add chat_send_message_hook \
+	      [namespace current]::handle_commands 50
+}
+
+proc bc::unload {} {
+    variable prefix
+    variable words
+    variable game
+    variable word
+    variable attempts
+    variable top
+
+    hook::remove draw_message_hook [namespace current]::handle_messages 79
+    hook::remove generate_completions_hook \
+		 [namespace current]::commands_comps
+    hook::remove chat_send_message_hook \
+		 [namespace current]::handle_commands 50
+
+    foreach chatid [chat::opened] {
+	if {[info exists game($chatid)]} {
+	    stop $chatid
+	}
+    }
+
+    catch {unset prefix}
+    catch {unset words}
+    catch {unset game}
+    catch {unset word}
+    catch {unset attempts}
+    catch {unset top}
+}
+
 proc bc::get_question {} {
     variable words
 
@@ -55,9 +108,6 @@
     }
 }
 
-hook::add generate_completions_hook \
-    [namespace current]::bc::commands_comps
-
 proc bc::handle_commands {chatid user body type} {
     variable game
 
@@ -92,9 +142,6 @@
     return
 }
 
-hook::add chat_send_message_hook \
-    [namespace current]::bc::handle_commands 50
-
 proc bc::get_nick {chatid jid type} {
     if {[catch {chat::get_nick [chat::get_xlib $chatid] $jid $type} nick]} {
 	return [chat::get_nick $jid $type]
@@ -170,13 +217,11 @@
 		set attempts($chatid,$from) 1
 	    }
 	    message::send_msg $xlib $jid -type groupchat \
-		-body "$nick: ${prefix} $w: $matches"
+		-body "$nick: ${prefix}$w: $matches"
 	}
     }
 }
 
-hook::add draw_message_hook [namespace current]::bc::handle_messages 79
-
 proc bc::start {chatid} {
     variable game
     variable prefix
@@ -210,6 +255,14 @@
 	foreach n [array names attempts "$chatid,*"] {
 	    unset attempts($n)
 	}
+
+	foreach id [after info] {
+	    if {[string first [list [namespace current]::ask $chatid] \
+			      [lindex [after info $id] 0]] == 0} {
+		after cancel $id
+	    }
+	}
+
 	unset game($chatid)
 	message::send_msg $xlib $jid -type groupchat \
 	    -body "${prefix}éÇÒÁ ÏÓÔÁÎÏ×ÌÅÎÁ."
@@ -279,7 +332,6 @@
     }
 }
 
-
 proc bc::top {chatid} {
     variable top
     variable prefix

Modified: trunk/tkabber-plugins/quiz/quiz.tcl
===================================================================
--- trunk/tkabber-plugins/quiz/quiz.tcl	2009-02-20 14:09:53 UTC (rev 1678)
+++ trunk/tkabber-plugins/quiz/quiz.tcl	2009-02-20 21:16:56 UTC (rev 1679)
@@ -1,10 +1,24 @@
 # $Id$
 
+package require msgcat
+
 namespace eval quiz {
+    ::msgcat::mcload [file join [file dirname [info script]] msgs]
+
+    if {![::plugins::is_registered quiz]} {
+	::plugins::register quiz \
+			    -namespace [namespace current] \
+			    -source [info script] \
+			    -description [::msgcat::mc "Whether the 'Quiz' plugin is loaded.\
+							The plugin implements a simple quiz in Russian."] \
+			    -loadcommand [namespace code load] \
+			    -unloadcommand [namespace code unload]
+	return
+    }
+
     set prefix {[QUIZ]: }
 }
 
-
 proc quiz::load_file {filename {enc utf-8}} {
     variable questions
 
@@ -42,6 +56,50 @@
     }
 }
 
+proc quiz::load {} {
+    hook::add generate_completions_hook \
+	      [namespace current]::commands_comps
+    hook::add draw_message_hook [namespace current]::handle_messages 79
+    hook::add chat_send_message_hook \
+	      [namespace current]::handle_commands 50
+}
+
+proc quiz::unload {} {
+    variable prefix
+    variable questions
+    variable game
+    variable question
+    variable answer
+    variable points
+    variable asktime
+    variable hint
+    variable top
+    variable stats
+    
+    hook::remove generate_completions_hook \
+	      [namespace current]::commands_comps
+    hook::remove draw_message_hook [namespace current]::handle_messages 79
+    hook::remove chat_send_message_hook \
+	      [namespace current]::handle_commands 50
+
+    foreach chatid [chat::opened] {
+	if {[info exists game($chatid)]} {
+	    stop $chatid
+	}
+    }
+
+    catch {unset prefix}
+    catch {unset questions}
+    catch {unset game}
+    catch {unset question}
+    catch {unset answer}
+    catch {unset points}
+    catch {unset asktime}
+    catch {unset hint}
+    catch {unset top}
+    catch {unset stats}
+}
+
 proc quiz::get_question {} {
     variable questions
 
@@ -67,9 +125,6 @@
     }
 }
 
-hook::add generate_completions_hook \
-    [namespace current]::quiz::commands_comps
-
 proc quiz::handle_commands {chatid user body type} {
     variable game
 
@@ -100,10 +155,6 @@
     return
 }
 
-hook::add chat_send_message_hook \
-    [namespace current]::quiz::handle_commands 50
-
-
 proc quiz::handle_messages {chatid from type body x} {
     variable game
     variable question
@@ -189,10 +240,7 @@
 	}
     }
 }
-hook::add draw_message_hook [namespace current]::quiz::handle_messages 79
 
-
-
 proc quiz::start {chatid} {
     variable game
     variable prefix
@@ -305,7 +353,6 @@
     after 60000 [list [namespace current]::next $chatid]
 }
 
-
 proc quiz::hint {chatid {cont 0}} {
     variable game
     variable answer



More information about the Tkabber-dev mailing list