[Tkabber-dev] r215 - trunk/plugins/flip

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Sat Apr 11 05:00:06 MSD 2009


Author: bigote
Date: 2009-04-11 05:00:06 +0400 (Sat, 11 Apr 2009)
New Revision: 215

Modified:
   trunk/plugins/flip/README
   trunk/plugins/flip/flip.tcl
Log:
Added multilogin support.


Modified: trunk/plugins/flip/README
===================================================================
--- trunk/plugins/flip/README	2009-04-10 18:00:01 UTC (rev 214)
+++ trunk/plugins/flip/README	2009-04-11 01:00:06 UTC (rev 215)
@@ -4,8 +4,8 @@
 to turn your nick upside down.
 
 This version of plugin, unlike the first one, remembers old nicks
-corresponding to each conference room, in a file named
-/your/configdir/plugins/flip/flip_list before flipping them,
+corresponding to each conference room and the current connected JID,
+in a file named /your/configdir/plugins/flip/flip_list before flipping them,
 and then restores them on the 2nd of April. When a nick is restored,
 its record in the file is removed. When all nicks are restored,
 the file is deleted.

Modified: trunk/plugins/flip/flip.tcl
===================================================================
--- trunk/plugins/flip/flip.tcl	2009-04-10 18:00:01 UTC (rev 214)
+++ trunk/plugins/flip/flip.tcl	2009-04-11 01:00:06 UTC (rev 215)
@@ -74,9 +74,10 @@
 	\u0420 \u0500
 	\u0421 \u0186
     }
+	variable filename [file join $::configdir plugins flip flip_list]
 }
 
-proc flip::flipping {nick group} {
+proc flip::flipping {xlib nick group} {
     variable flipTable
 
     set seconds [clock seconds]
@@ -84,7 +85,7 @@
     # Probability of flipping is 50% at April, 1st
 	set is_fools_day [expr {[clock format $seconds -format %m/%d] == "04/01"}]
     if {$is_fools_day && [expr rand()] < 0.5} {
-	[namespace current]::store_old_nick $nick $group
+	[namespace current]::store_old_nick $xlib $nick $group
 	set newnick ""
 	set map [string map $flipTable $nick]
 	for {set i 0} {$i < [string length $map]} {incr i} {
@@ -94,15 +95,16 @@
     } elseif {$is_fools_day} {
 		return $nick
     } else {
-		set nick [[namespace current]::restore_old_nick $nick $group]
+		set nick [[namespace current]::restore_old_nick $xlib $nick $group]
 		return $nick
 	}
 }
 
 proc flip::slurp {} {
-	if {[info exists ::configdir] \
-	&&  [file exists [file join $::configdir plugins flip flip_list]]} {
-		set f_l [open $::configdir/plugins/flip/flip_list r]
+	variable filename
+	if {[file exists $filename]} {
+		set f_l [open $filename r]
+		fconfigure $f_l -encoding utf-8
 		set f_d [read $f_l]
 		close $f_l
 		return $f_d
@@ -110,44 +112,49 @@
 }
 
 proc flip::puke {f_d} {
+	variable filename
 	if {[llength $f_d] > 0} {
-		set f_l [open $::configdir/plugins/flip/flip_list w]
+		set f_l [open $filename w]
+		fconfigure $f_l -encoding utf-8
 		puts $f_l $f_d
 		close $f_l
-	} elseif {[file exists [file join $::configdir plugins flip flip_list]]} {
-		file delete [file join $::configdir plugins flip flip_list]
+	} elseif {[file exists $filename]} {
+		file delete $filename
 	}
 }
 
-proc flip::store_old_nick {nick group} {
+proc flip::store_old_nick {xlib nick group} {
+	set real_jid [::xmpp::jid::stripResource [connection_jid $xlib]]
 	set flip_data [[namespace current]::slurp]
 	set fd [split $flip_data "\n"]
 	set found 0
 	foreach line $fd {
 		set els [split $line " "]
-		if {[lsearch -exact $els $group] == 0} {
+		if {[lindex $els 0] == $real_jid
+		&&  [lindex $els 1] == $group} {
 			set found 1
 			break
 		}
 	}
 	if {!$found} {
-		append flip_data [join [list $group $nick\n] " "]
+		append flip_data [join [list $real_jid $group $nick\n] " "]
 		[namespace current]::puke $flip_data
 	}
 }
 
-proc flip::restore_old_nick {nick group} {
+proc flip::restore_old_nick {xlib nick group} {
 	set flip_data [[namespace current]::slurp]
 	set new_fd ""
 	if {[llength $flip_data] == 0} {
 		return $nick
 	}
+	set real_jid [::xmpp::jid::stripResource [connection_jid $xlib]]
 	set fd [split $flip_data "\n"]
 	foreach line $fd {
 		if {$line != ""} {
 			set els [split $line " "]
-			if {[lindex $els 0] == $group} {
-				set nick [join [lrange $els 1 end]]
+			if {[lindex $els 0] == $real_jid && [lindex $els 1] == $group} {
+				set nick [join [lrange $els 2 end]]
 			} else {
 				append new_fd [join [list $line\n] " "]
 			}
@@ -161,6 +168,5 @@
 
 proc ::muc::join_group {xlib group nick {password ""}} {
     ::muc::join_group:saved $xlib $group \
-	[::plugins::flip::flipping $nick $group] $password
+	[::plugins::flip::flipping $xlib $nick $group] $password
 }
-



More information about the Tkabber-dev mailing list