[Tkabber-dev] r213 - in trunk/plugins: . flip

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Fri Apr 10 17:51:58 MSD 2009


Author: bigote
Date: 2009-04-10 17:51:58 +0400 (Fri, 10 Apr 2009)
New Revision: 213

Added:
   trunk/plugins/flip/
   trunk/plugins/flip/README
   trunk/plugins/flip/flip.tcl
Log:
"Flip" plugin that was temporarily added to the trunk is moved to 3rd-party-plugins.
Nick storing/restoring added to its functionality. See README for details.


Added: trunk/plugins/flip/README
===================================================================
--- trunk/plugins/flip/README	                        (rev 0)
+++ trunk/plugins/flip/README	2009-04-10 13:51:58 UTC (rev 213)
@@ -0,0 +1,39 @@
+ABOUT PLUGIN:
+
+It's a joke plugin for Tkabber. On the 1st of April it tries
+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,
+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.
+Don't delete it if you want your nicks to be restored automatically.
+
+
+INSTALLING:
+
+Just place the plugin's directory to /your/configdir/plugins directory
+so that to get a structure like this:
+/your/configdir/plugins/flip/flip.tcl
+                             README
+
+
+KNOWN PROBLEMS:
+
+Many letter pairs, especially for Russian letters,
+are yet to be found in UTF-8 tables :)
+
+
+TODO:
+
+Maybe it's a good idea to separate Russian table from the plugin's code
+only leaving English one so that other language tables could be added and used.
+
+
+AUTHORS:
+
+The idea and original JavaScript are taken from http://fliptitle.com/
+The plugin was written by Serge Yudin <xmpp:bigote at jabber.ru>
+and modified by Sergei Golovan <sgolovan at nes.ru>

Added: trunk/plugins/flip/flip.tcl
===================================================================
--- trunk/plugins/flip/flip.tcl	                        (rev 0)
+++ trunk/plugins/flip/flip.tcl	2009-04-10 13:51:58 UTC (rev 213)
@@ -0,0 +1,166 @@
+# Written by Serge Yudin xmpp:bigote at jabber.ru 2009-04-10 v 0.2
+# The idea and original JavaScript are from http://fliptitle.com/
+# Modified by Sergei Golovan
+# $Id: flip.tcl 1741 2009-03-20 15:41:19Z sergei $
+
+namespace eval flip {
+    # Some letters are added compared to the original table version.
+    # For example, capital letters, cyrillic letters.
+
+    variable flipTable {
+	a \u0250
+	b q
+	c \u0254
+	d p
+	e \u01DD
+	f \u025F
+	g \u0183
+	h \u0265
+	i \u0131
+	j \u027E
+	k \u029E
+	l l
+	m \u026F
+	n u
+	r \u0279
+	t \u0287
+	v \u028C
+	w \u028D
+	y \u028E
+	\. \u02D9
+	\[ \]
+	\( \)
+	\{ \}
+	\? \u00BF
+	\! \u00A1
+	\' \,
+	\< \>
+	\_ \u203E
+	\; \u061B
+	\u203F \u2040
+	\u2045 \u2046
+	\u2234 \u2235
+	\r \n
+	A \u2200
+	C \u0186
+	D \u15E1
+	P \u0500
+	R \u1D1A
+	M W
+	\u0430 \u0250
+	\u0431 g
+	\u0433 \u0279
+	\u0435 \u01DD
+	\u0438 n
+	\u043A \u029E
+	\u043B v
+	\u043C w
+	\u043F \u0446
+	\u0440 d
+	\u0441 \u0254
+	\u0443 \u028E
+	\u0447 \u04BB
+	\u0448 m
+	\u044C q
+	\u044D \u0454
+	\u044F \u0281
+	f \u025F
+	h \u0265
+	i \u0131
+	j \u027E
+	t \u0287
+	\u0411 g
+	\u0427 \u04BA
+	\u0420 \u0500
+	\u0421 \u0186
+    }
+}
+
+proc flip::flipping {nick group} {
+    variable flipTable
+
+    set seconds [clock seconds]
+
+    # 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
+	set newnick ""
+	set map [string map $flipTable $nick]
+	for {set i 0} {$i < [string length $map]} {incr i} {
+	    append newnick [string index $map end-$i]
+	}
+		return $newnick
+    } elseif {$is_fools_day} {
+		return $nick
+    } else {
+		set nick [[namespace current]::restore_old_nick $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]
+		set f_d [read $f_l]
+		close $f_l
+		return $f_d
+	}
+}
+
+proc flip::puke {f_d} {
+	if {[llength $f_d] > 0} {
+		set f_l [open $::configdir/plugins/flip/flip_list w]
+		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]
+	}
+}
+
+proc flip::store_old_nick {nick group} {
+	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} {
+			set found 1
+			break
+		}
+	}
+	if {!$found} {
+		append flip_data [join [list $group $nick\n] " "]
+		[namespace current]::puke $flip_data
+	}
+}
+
+proc flip::restore_old_nick {nick group} {
+	set flip_data [[namespace current]::slurp]
+	set new_fd ""
+	if {[llength $flip_data] == 0} {
+		return $nick
+	}
+	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]]
+			} else {
+				append new_fd [join [list $line\n] " "]
+			}
+		}
+	}
+	[namespace current]::puke $new_fd
+	return $nick
+}
+
+rename ::muc::join_group ::muc::join_group:saved
+
+proc ::muc::join_group {xlib group nick {password ""}} {
+    ::muc::join_group:saved $xlib $group \
+	[::plugins::flip::flipping $nick $group] $password
+}
+



More information about the Tkabber-dev mailing list