[Tkabber-dev] r197 - trunk/plugins/bldjid

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Mon Apr 6 03:24:06 MSD 2009


Author: bigote
Date: 2009-04-06 03:24:05 +0400 (Mon, 06 Apr 2009)
New Revision: 197

Modified:
   trunk/plugins/bldjid/ChangeLog
   trunk/plugins/bldjid/README
   trunk/plugins/bldjid/TODO
   trunk/plugins/bldjid/bldjid.tcl
Log:
Loose matching rules (which is default setting) added to plugin's
/visit* commands. Now you can provide only a part of a room's name
or a nick to search in the lists.


Modified: trunk/plugins/bldjid/ChangeLog
===================================================================
--- trunk/plugins/bldjid/ChangeLog	2009-04-05 11:18:24 UTC (rev 196)
+++ trunk/plugins/bldjid/ChangeLog	2009-04-05 23:24:05 UTC (rev 197)
@@ -1,3 +1,14 @@
+2009-04-06  Serge Yudin  <xmpp:bigote at jabber.ru> <mailto:bigote at gmail.com>
+
+--- Version 0.5.2 of the plugin.
+--- Files modified:
+    bldjid.tcl, TODO, README, ChangeLog.
+
+--- Changes:
+	Loose matching rules (which is default setting) added to plugin's
+	/visit* commands. Now you can provide only a part of a room's name
+	or a nick to search in the lists.
+
 2009-04-05  Serge Yudin  <xmpp:bigote at jabber.ru> <mailto:bigote at gmail.com>
 
 --- Version 0.5.1 of the plugin.

Modified: trunk/plugins/bldjid/README
===================================================================
--- trunk/plugins/bldjid/README	2009-04-05 11:18:24 UTC (rev 196)
+++ trunk/plugins/bldjid/README	2009-04-05 23:24:05 UTC (rev 197)
@@ -92,6 +92,12 @@
 	Maximum level means that every entrance	of every user
 	will be logged, with a corresponding timestamp.
 
+--- ::plugins::bldjid::options(matching_rules)
+	"Exact" matching obliges you provide exact parameters for /visit* commands
+	to search. So the default setting is "Loose" matching that allows you
+	to put only a group name or even its part instead of full room's JID.
+	The same applies for nicks.
+
 --- ::plugins::bldjid::options(send_chat_messages)
 	Besides of logging user entrances, chat system messages are published.
 	Unlike usual messages that are sent by ::muc::options(gen_enter_exit_msgs)
@@ -99,12 +105,6 @@
 	if Minimum verbosity level is chosen. If not, if would be almost the same
 	as ::muc::options(gen_enter_exit_msgs) messages (without exit messages).
 
-If ::muc::options(gen_enter_exit_msgs) is enabled again,
-no new entries are added to the existing list. However,
-it's still kept alive to be consulted at any time.
-The option above only affects gathering new entries:
-they are put either to the list or to chat windows.
-
 ================
 ####  MISC  ####
 ================

Modified: trunk/plugins/bldjid/TODO
===================================================================
--- trunk/plugins/bldjid/TODO	2009-04-05 11:18:24 UTC (rev 196)
+++ trunk/plugins/bldjid/TODO	2009-04-05 23:24:05 UTC (rev 197)
@@ -8,9 +8,6 @@
 	of user list to your feelings. Now the separator is '||'
 	and it is set within plugin's code.
 
-=== Add matching rules for /visit* commands to be able processing
-	not only exact room and nick names.
-
 === Add possibility to track nick changes when logging.
 
 === Add autocompletion for JIDs when using /bldjid-like commands

Modified: trunk/plugins/bldjid/bldjid.tcl
===================================================================
--- trunk/plugins/bldjid/bldjid.tcl	2009-04-05 11:18:24 UTC (rev 196)
+++ trunk/plugins/bldjid/bldjid.tcl	2009-04-05 23:24:05 UTC (rev 197)
@@ -1,4 +1,4 @@
-# "Bldjid" plugin for Tkabber. 2009-04-05 v. 0.5.1
+# "Bldjid" plugin for Tkabber. 2009-04-06 v. 0.5.2
 # Written by Serge Yudin xmpp:bigote at jabber.ru
 # See README file for usage.
 
@@ -22,6 +22,10 @@
 		max [::msgcat::mc "Maximum: Also log timestamps\
 		(all entrances of each user will be logged)."]]
 
+		set matching_rules [list \
+		exact [::msgcat::mc "Exact match."]\
+		loose [::msgcat::mc "Loose match."]]
+
 		custom::defgroup Plugins [::msgcat::mc "Plugins options."] -group Tkabber
 
 		custom::defgroup Bldjid [::msgcat::mc "Bldjid options."] -group Plugins
@@ -40,6 +44,10 @@
 			[::msgcat::mc "Verbosity level."] \
 			-type radio -group Bldjid -layout vertical -values $verbosity
 
+		custom::defvar options(matching_rules) loose \
+			[::msgcat::mc "Matching rules for /visit* commands."] \
+			-type radio -group Bldjid -layout vertical -values $matching_rules
+
 		custom::defvar options(send_chat_messages) 0 \
 			[::msgcat::mc "Generate and send to chats smart system messages\
 			about user entrances (will only work with Minimum verbosity level)."] \
@@ -128,10 +136,12 @@
 }
 
 proc bldjid::handle_commands {chatid user body type} {
-	set list_doesn_exist "List for the requested room doesn't exist.\
-		Make sure you provide a full room's JID or check if the plugin is turned on."
+	set list_doesnt_exist "List for the requested room doesn't exist.\
+		Make sure you provide a full room's JID or check if the plugin is turned on\
+		or if you use Loose match rules."
 	set filter_turned_on "You turned off showing results in the rooms\
 		where you don't have admin privileges."
+	set no_jid "I can't see any JID of this user."
 	variable user_list
 # Detect the command.
 	if {[string match {/bldjid*} $body]} {
@@ -153,7 +163,6 @@
 	if {$type != "groupchat"} return
 
 	set xlib [chat::get_xlib $chatid]
-	set groupjids [[namespace current]::valid_groups $xlib admin]
 	set room ""
 	set nick ""
 	if {[string equal [string range $body 0 9] "/unbldjid "]} {
@@ -182,12 +191,14 @@
 
 	switch -- $cmd {
 		/unbldjid {
+			set groupjids [[namespace current]::valid_groups $xlib admin {}]
 			foreach group $groupjids {
 				muc::unban $xlib $group $jid
 			}
 		}
 
 		/bldjid {
+			set groupjids [[namespace current]::valid_groups $xlib admin {}]
 			if {[string is integer $jid] && [info exists user_list]} {
 				set jid [[namespace current]::pickup $jid $chatid]
 			}
@@ -196,6 +207,9 @@
 					[namespace current]::send_ban_request \
 						$xlib $group $params $jid $reason
 				}
+			} else {
+				set group [chat::get_jid $chatid]
+				chat::add_message $chatid $group error $no_jid {}
 			}
 		}
 
@@ -203,10 +217,12 @@
 			if {[string is integer $jid] && [info exists user_list]} {
 				set jid [[namespace current]::pickup $jid $chatid]
 			}
+			set group [chat::get_jid $chatid]
 			if {$jid != ""} {
-				set group [chat::get_jid $chatid]
 				[namespace current]::send_ban_request \
 				$xlib $group $params $jid $reason
+			} else {
+				chat::add_message $chatid $group error $no_jid {}
 			}
 		}
 
@@ -238,25 +254,45 @@
 			set group [chat::get_jid $chatid]
 			global jids_by_chats
 			set user_list {}
+			set header "Group filtering is "
+			if {$options(filter_admin_rooms)} {
+				set which admin
+				append header "ON."
+			} else {
+				set which all
+				append header "OFF."
+			}
+			append header " Show all visits to the "
 			if {$room == ""} {
 				set room $group
-				set header "Show all visits to the current room:"
+				append header "current room:"
+			} elseif {$options(matching_rules) == "exact"} {
+				append header "room $room:"
 			} else {
-				set header "Show all visits to room $room:"
+				append header "rooms that match *$room*:"
 			}
-			if {$options(filter_admin_rooms)} {
-				set iam [lindex [whoami $xlib $room] 1]
-				if {!($iam == "admin" || $iam == "owner")} {
-					chat::add_message $chatid $group error $filter_turned_on {}
-					return stop
-				}
-			}
 
-			if {![info exists jids_by_chats($room)]} {
+			if {$options(matching_rules) == "exact" \
+			&& ![info exists jids_by_chats($room)]} {
 				chat::add_message $chatid $group error $list_doesnt_exist {}
 				return stop
+			} elseif {$options(matching_rules) == "exact"} {
+				if {$options(filter_admin_rooms)} {
+					set iam [lindex [whoami $xlib $room] 1]
+					if {!($iam == "admin" || $iam == "owner")} {
+						chat::add_message $chatid $group error $filter_turned_on {}
+						return stop
+					}
+				}
+				set user_list $jids_by_chats($room)
+			} else {
+				set groupjids [[namespace current]::valid_groups $xlib $which $room]
+				foreach grp $groupjids {
+					foreach item $jids_by_chats($grp) {
+						lappend user_list $item
+					}
+				}
 			}
-			set user_list $jids_by_chats($room)
 			set msg ""
 			set n 0
 			chat::add_message $chatid $group error $header {}
@@ -272,30 +308,50 @@
 			set group [chat::get_jid $chatid]
 			global jids_by_chats
 			set user_list {}
+			set header "Group filtering is "
+			if {$options(filter_admin_rooms)} {
+				set which admin
+				append header "ON."
+			} else {
+				set which all
+				append header "OFF."
+			}
+			append header " Show visits of "
 			if {$nick == ""} {
 				chat::add_message $chatid $group error \
 				"Parameters expected. Type /bldhelp for usage examples." {}
 				return stop
 			} elseif {$room == ""} {
-				set header "Show visits of $nick to all rooms:"
-				set which all
-				if {$options(filter_admin_rooms)} {
-					set which admin
-					append header " (Group filtering is ON)"
+				if {$options(matching_rules) == "exact"} {
+					append header "$nick to all rooms:"
+				} else {
+					append header "users matching *$nick* to all rooms:"
 				}
-				set groupjids [[namespace current]::valid_groups $xlib $which]
+				set groupjids [[namespace current]::valid_groups $xlib $which {}]
 				foreach grp $groupjids {
 					if {[info exists jids_by_chats($grp)]} {
 						foreach item $jids_by_chats($grp) {
-							if {[string equal [lindex $item 1] $nick]} {
-								lappend item $grp
-								lappend user_list $item
+							if {$options(matching_rules) == "exact"} {
+								if {[string equal [lindex $item 1] $nick]} {
+									lappend item $grp
+									lappend user_list $item
+								}
+							} else {
+								if {[string match -nocase *$nick* [lindex $item 1]]} {
+									lappend item $grp
+									lappend user_list $item
+								}
 							}
 						}
 					}
 				}
 			} else {
-				set header "Show visits of $nick to the room $room:"
+				if {$options(matching_rules) == "exact"} {
+					append header "$nick to the room $room:"
+				} else {
+					append header "users matching *$nick*\
+					to the rooms that match *$room*:"
+				}
 				if {$options(filter_admin_rooms)} {
 					set iam [lindex [whoami $xlib $group] 1]
 					if {!($iam == "admin" || $iam == "owner")} {
@@ -303,13 +359,22 @@
 						return stop
 					}
 				}
-				if {![info exists jids_by_chats($room)]} {
-					chat::add_message $chatid $group error $list_doesnt_exist {}
-					return stop
-				}
-				foreach item $jids_by_chats($room) {
-					if {[string equal [lindex $item 1] $nick]} {
-						lappend user_list $item
+				set groupjids [[namespace current]::valid_groups $xlib $which $room]
+				foreach grp $groupjids {
+					if {[info exists jids_by_chats($grp)]} {
+						foreach item $jids_by_chats($grp) {
+							if {$options(matching_rules) == "exact"} {
+								if {[string equal [lindex $item 1] $nick]} {
+									lappend item $grp
+									lappend user_list $item
+								}
+							} else {
+								if {[string match -nocase *$nick* [lindex $item 1]]} {
+									lappend item $grp
+									lappend user_list $item
+								}
+							}
+						}
 					}
 				}
 			}
@@ -474,15 +539,39 @@
 	}
 }
 
-proc bldjid::valid_groups {xlib which} {
+proc bldjid::valid_groups {xlib which pattern} {
 # Filter out wrong conferences.
 # We assume IRC-channels have to have "irc" part in their transport name.
 # If some transport doesn't have it (1% of probability),
 # a ban request will be sent there and we'll get an error.
+	variable options
 	global grouproster
 	set grpjids ""
 	foreach tmpchatid [lsort [lfilter chat::is_groupchat [chat::opened $xlib]]] {
 		set tmpgrp [chat::get_jid $tmpchatid]
+		if {$pattern != ""} {
+			switch -- $options(matching_rules) {
+				exact {
+					if {[string equal $tmpgrp $pattern]} {
+						lappend grplist $tmpchatid
+					}
+				}
+				loose {
+					if {[string match *$pattern* $tmpgrp]} {
+						lappend grplist $tmpchatid
+					}
+				}
+			}
+		} else {
+			lappend grplist $tmpchatid
+		}
+	}
+	if {![info exists grplist]} {
+#		chat::add_message $chatid $group error "Pattern $pattern has no match." {}
+		return stop
+	}
+	foreach tmpchatid $grplist {
+		set tmpgrp [chat::get_jid $tmpchatid]
 		set jid $tmpgrp/[get_our_groupchat_nick $tmpchatid]
 		if {[lcontain $grouproster(users,$tmpchatid) $jid]} {
 			switch -- $which {



More information about the Tkabber-dev mailing list