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

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Sun Apr 26 06:19:41 MSD 2009


Author: bigote
Date: 2009-04-26 06:19:41 +0400 (Sun, 26 Apr 2009)
New Revision: 221

Modified:
   trunk/plugins/bldjid/ChangeLog
   trunk/plugins/bldjid/README
   trunk/plugins/bldjid/TODO
   trunk/plugins/bldjid/bldjid.tcl
Log:
Some changes were made in order to prepare the plugin's code for splitting to several modules:
- Some code refactoring.
- Some behaviour improvements.
- The option 'options(enabled)' renamed to 'options(enable_jids_gathering)'.
- Some changes also applied to README file.


Modified: trunk/plugins/bldjid/ChangeLog
===================================================================
--- trunk/plugins/bldjid/ChangeLog	2009-04-25 22:14:21 UTC (rev 220)
+++ trunk/plugins/bldjid/ChangeLog	2009-04-26 02:19:41 UTC (rev 221)
@@ -1,3 +1,17 @@
+2009-04-26  Serge Yudin  <xmpp:bigote at jabber.ru> <mailto:bigote at gmail.com>
+
+--- Version 0.5.18 of the plugin.
+--- Files modified:
+    bldjid.tcl, README, TODO, ChangeLog.
+
+--- Changes:
+	Some changes were made in order to prepare the plugin's code for splitting
+	to several modules:
+	Some code refactoring.
+	Some behaviour improvements.
+	The option 'options(enabled)' renamed to 'options(enable_jids_gathering)'.
+	Some changes also applied to README file.
+
 2009-04-25  Serge Yudin  <xmpp:bigote at jabber.ru> <mailto:bigote at gmail.com>
 
 --- Version 0.5.17 of the plugin.

Modified: trunk/plugins/bldjid/README
===================================================================
--- trunk/plugins/bldjid/README	2009-04-25 22:14:21 UTC (rev 220)
+++ trunk/plugins/bldjid/README	2009-04-26 02:19:41 UTC (rev 221)
@@ -78,10 +78,15 @@
 -	Autocompletion also works in the same way for matching JIDs and nicks
 	when you use commands /bldjid, /banjid, /unban, /unbldjid
 	after generating a user list by any of /visit* commands.
-	If there is no such list, only nicks autocompletion works
-	(which is not what you need).
+-	If there is no argument specified after the command, autocompletion
+	starts checking nicks and only after them, JIDs (if there is a search result
+	available). So if you choose autocompletion to specify a JID for banning,
+	type at least the first letter of the JID you want to ban to avoid
+	checking of all nicks (however, those that start with this letter
+	will be offered, too). I will try to fix such inconvenient behaviour
+	in the future.
 -   Please note that autocompletion doesn't work if you have not created
-	any user list, i.e. you have not used any of /visit* commands yet.
+	any user list, i.e. you have not used any of /visit* commands at least once.
 
 =====================
 ####  CUSTOMIZE  ####
@@ -90,7 +95,7 @@
 There are Customize options for this plugin at
 Tkabber -> Customize -> Plugins -> Bldjid
 
---- ::plugins::bldjid::options(enabled)
+--- ::plugins::bldjid::options(enable_jids_gathering)
 	Turns on JIDs gathering.
 
 --- ::plugins::bldjid::options(filter_admin_rooms)
@@ -101,20 +106,21 @@
 --- ::plugins::bldjid::options(verbosity_level)
 -	Minimum level means that there will be no repeated JIDs in each room list.
 	However, if the same JID enters the same room with a different nick
-	(or even changes his or her nick), such entrance will be also logged.
+	(or even changes his or her nick while staying in the room),
+	such entrance will be also logged.
+	Timestamps will also be added to every entry to keep it easier tracking
+	user entrances.
 -	Maximum level means that every entrance	of every user will be logged.
-	Timestamps will be added to every entry to keep it easier tracking
-	user entrances.
 
 --- ::plugins::bldjid::options(matching_rules)
 -	"Exact" matching obliges you to provide exact parameters
-	for /visit* commands to search.
+	for /visit* commands to search (if you want to see any relevant result).
 -	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(custom_separator)
-	Custom field separator for /visit* commands. Default value is "||".
+	Custom field separator for /visit* commands output. Default value is "||".
 
 --- ::plugins::bldjid::options(redirect_output)
 	Disabled by default.
@@ -124,18 +130,23 @@
 	at any moment.
 -	Closing this monitor window doesn't mean you lose your search result.
 	You can still use ban and unban commands with a list number
-	if you remember it or using it with JID autocompletion.
+	if you remember it, or using it with JID autocompletion.
 	Even more, your search history is kept in each monitor window
-	until you clear it by /clearmon command.
-	You can scroll monitor window up and down by pressing
+	until you clear it by /clearmon command. However, keep in mind
+	that only the last search result is used for "ban by item number"
+	so use this mode carefully so that not to ban an innocent person :)
+	Make sure you have invoked a new /visit* command before banning
+	to get a fresh user list.
+-	You can scroll monitor window up and down by pressing
 	Alt-Shift-PgUp and Alt-Shift-PgDown correspondingly.
+-	You cannot open/close monitor window manually if this option is disabled.
 
 --- ::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)
-	these only appear once per JID. That's why it only works
-	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).
+	Disabled by default.
+	If enabled, chat system messages are published besides of logging
+	user entrances. Unlike usual messages that are sent
+	by ::muc::options(gen_enter_exit_msgs) these only appear once per JID.
+	That's why it only works if Minimum verbosity level is chosen.
 
 --- ::plugins::bldjid::options(log_length)
 	Sets log length limit for each room. Default value is 0 that means no limit.

Modified: trunk/plugins/bldjid/TODO
===================================================================
--- trunk/plugins/bldjid/TODO	2009-04-25 22:14:21 UTC (rev 220)
+++ trunk/plugins/bldjid/TODO	2009-04-26 02:19:41 UTC (rev 221)
@@ -1,6 +1,3 @@
-=== Some refactoring should be perfomed before releasing
-	a new major version and starting to work on the next one.
-
 For the next major version:
 === It seems that the plugin becomes too big ;) Most likely, it will be
 	splitted in three parts: bldjid.tcl, visits.tcl and monitor.tcl

Modified: trunk/plugins/bldjid/bldjid.tcl
===================================================================
--- trunk/plugins/bldjid/bldjid.tcl	2009-04-25 22:14:21 UTC (rev 220)
+++ trunk/plugins/bldjid/bldjid.tcl	2009-04-26 02:19:41 UTC (rev 221)
@@ -1,4 +1,4 @@
-# "Bldjid" plugin for Tkabber. 2009-04-25 v. 0.5.17
+# "Bldjid" plugin for Tkabber. 2009-04-26 v. 0.5.18
 # Written by Serge Yudin xmpp:bigote at jabber.ru
 # See README file for usage.
 
@@ -34,7 +34,7 @@
 
 		custom::defgroup Bldjid [::msgcat::mc "Bldjid options."] -group Plugins
 
-		custom::defvar options(enabled) 1 \
+		custom::defvar options(enable_jids_gathering) 1 \
 			[::msgcat::mc "Enable JIDs logging.\
 			Disabling it doesn't prevent /bldjid-like commands to work."] \
 			-type boolean -group Bldjid
@@ -87,7 +87,7 @@
 	global grouproster
 	global jids_by_chats
 	variable options
-	if {!$options(enabled)} {
+	if {!$options(enable_jids_gathering)} {
 		return
 	}
 	set group [::xmpp::jid::stripResource $jid]
@@ -176,15 +176,8 @@
 }
 
 proc bldjid::handle_commands {chatid user body type} {
-	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]} {
 		set cmd /bldjid
@@ -206,9 +199,10 @@
 
 	if {$type != "groupchat"} return
 
-	set xlib [chat::get_xlib $chatid]
+	set group [chat::get_jid $chatid]
 	set room ""
 	set nick ""
+
 	if {[string equal [string range $body 0 9] "/unbldjid "]} {
 		set jid [muc::parse_nick $body 10]
 	} elseif {[string equal [string range $body 0 7] "/bldjid "]} {
@@ -229,18 +223,21 @@
 			lassign [muc::parse_nick_reason $body 9] nick room
 		}
 	} elseif {[string equal [string range $body 0 7] "/bldhelp"]} {
-		[namespace current]::help $chatid
+		[namespace current]::help $chatid $group
 	} elseif {[string equal [string range $body 0 8] "/clearmon"]} {
 		[namespace current]::clear_monitor $chatid
 	} else {
 		return stop
 	}
 
+	variable user_list
+	set xlib [chat::get_xlib $chatid]
+
 	switch -- $cmd {
 		/unbldjid {
 			set groupjids [[namespace current]::valid_groups $xlib admin {}]
-			foreach group $groupjids {
-				muc::unban $xlib $group $jid
+			foreach gr $groupjids {
+				muc::unban $xlib $gr $jid
 			}
 		}
 
@@ -250,12 +247,11 @@
 				set jid [[namespace current]::pickup $jid $chatid]
 			}
 			if {$jid != ""} {
-				foreach group $groupjids {
+				foreach gr $groupjids {
 					[namespace current]::send_ban_request \
-						$xlib $group $params $jid $reason
+						$xlib $gr $params $jid $reason
 				}
 			} else {
-				set group [chat::get_jid $chatid]
 				chat::add_message $chatid $group error $no_jid {}
 			}
 		}
@@ -264,7 +260,6 @@
 			if {[string is integer $jid] && [info exists user_list]} {
 				set jid [[namespace current]::pickup $jid $chatid]
 			}
-			set group [chat::get_jid $chatid]
 			if {$jid != ""} {
 				[namespace current]::send_ban_request \
 				$xlib $group $params $jid $reason
@@ -274,7 +269,6 @@
 		}
 
 		/amnesty {
-			set group [chat::get_jid $chatid]
 			variable winid
 			set w .amn$winid
 			incr winid
@@ -297,138 +291,12 @@
 		}
 
 		/visitors {
-			variable options
-			set group [chat::get_jid $chatid]
-		if {$options(enabled)} {
-			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
-					append header "current room:"
-			} elseif {$options(matching_rules) == "exact"} {
-				append header "room $room:"
-			} else {
-				append header "rooms that match *$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
-					}
-				}
-				if {[info exists jids_by_chats($room)]} {
-					set user_list $jids_by_chats($room)
-				}
-			} else {
-				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 {![string match "*current room:" $header]} {
-								lappend item $grp
-							}
-							lappend user_list $item
-						}
-					}
-				}
-			}
-			set msg ""
-			set n 0
-			foreach user $user_list {
-				lappend msg [[namespace current]::format_msg $user $n]
-				incr n
-			}
-			if {$options(enabled) && $options(redirect_output)} {
-				[namespace current]::toggle_monitor $chatid 0
-				[namespace current]::add_message_to_monitor $chatid $header
-				[namespace current]::add_message_to_monitor $chatid "[join $msg]\n\n"
-			} elseif {$options(enabled)} {
-				chat::add_message $chatid $group error $header {}
-				chat::add_message $chatid $group info "[join $msg]" {}
-			}
-		} else {
-			chat::add_message $chatid $group error "JIDs gathering is disabled." {}
+			[namespace current]::visitors $xlib $chatid $room $group
 		}
-		}
 
 		/visited {
-			variable options
-			set group [chat::get_jid $chatid]
-		if {$options(enabled)} {
-			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 == ""} {
-				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 {}]
-				[namespace current]::prepare_user_list $groupjids $nick
-			} else {
-				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")} {
-						chat::add_message $chatid $group error $filter_turned_on {}
-						return stop
-					}
-				}
-				set groupjids [[namespace current]::valid_groups $xlib $which $room]
-				[namespace current]::prepare_user_list $groupjids $nick
-			}
-			set msg ""
-			set n 0
-			foreach user $user_list {
-				lappend msg [[namespace current]::format_msg $user $n]
-				incr n
-			}
-			if {$options(redirect_output)} {
-				[namespace current]::toggle_monitor $chatid 0
-				[namespace current]::add_message_to_monitor $chatid $header
-				[namespace current]::add_message_to_monitor $chatid "[join $msg]\n\n"
-			} else {
-				chat::add_message $chatid $group error $header {}
-				chat::add_message $chatid $group info "[join $msg]" {}
-			}
-		} else {
-			chat::add_message $chatid $group error "JIDs gathering is disabled." {}
+			[namespace current]::visited $xlib $chatid $room $group $nick
 		}
-		}
 	}
 	return stop
 }
@@ -618,11 +486,147 @@
 	}
 }
 
-proc bldjid::help {chatid} {
+proc bldjid::visitors {xlib chatid room group} {
 	variable options
-	set group [::chat::get_jid $chatid]
+	variable user_list
+	if {$options(enable_jids_gathering)} {
+		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
+			append header "current room:"
+		} elseif {$options(matching_rules) == "exact"} {
+			append header "room $room:"
+		} else {
+			append header "rooms that match *$room*:"
+		}
+
+		if {$options(matching_rules) == "exact" \
+		&& ![info exists jids_by_chats($room)]} {
+			chat::add_message $chatid $group error "List for the requested room doesn't exist.\
+			Make sure if you provide a full room's JID, if the plugin is turned on,\
+			or if you use Loose match rules." {}
+			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
+				}
+			}
+			if {[info exists jids_by_chats($room)]} {
+				set user_list $jids_by_chats($room)
+			}
+		} else {
+			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 {![string match "*current room:" $header]} {
+							lappend item $grp
+						}
+						lappend user_list $item
+					}
+				}
+			}
+		}
+		set msg [[namespace current]::prepare_print_res]
+		[namespace current]::print_search_res $chatid $group $header $msg
+	} else {
+		chat::add_message $chatid $group error "JIDs gathering is disabled." {}
+	}
+}
+
+proc bldjid::visited {xlib chatid room group nick} {
+	variable options
+	variable user_list
+	if {$options(enable_jids_gathering)} {
+		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 == ""} {
+			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 {}]
+			[namespace current]::prepare_user_list $groupjids $nick
+		} else {
+			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")} {
+					chat::add_message $chatid $group error \
+					"You turned off showing results in the rooms\
+					where you don't have admin privileges." {}
+					return stop
+				}
+			}
+			set groupjids [[namespace current]::valid_groups $xlib $which $room]
+			[namespace current]::prepare_user_list $groupjids $nick
+		}
+		set msg [[namespace current]::prepare_print_res]
+		[namespace current]::print_search_res $chatid $group $header $msg
+	} else {
+		chat::add_message $chatid $group error "JIDs gathering is disabled." {}
+	}
+}
+
+proc bldjid::prepare_print_res {} {
+	variable user_list
+	set msg ""
+	set n 0
+	foreach user $user_list {
+		lappend msg [[namespace current]::format_msg $user $n]
+		incr n
+	}
+	return $msg
+}
+
+proc bldjid::print_search_res {chatid group header msg} {
+	variable options
+	if {$options(redirect_output)} {
+		[namespace current]::toggle_monitor $chatid 0
+		[namespace current]::add_message_to_monitor $chatid $header
+		[namespace current]::add_message_to_monitor $chatid "[join $msg]\n\n"
+	} else {
+		chat::add_message $chatid $group error $header {}
+		chat::add_message $chatid $group info "[join $msg]" {}
+	}
+	return
+}
+
+proc bldjid::help {chatid group} {
 	set header "Short usage examples for Bldjid plugin"
-	set msg "\nBan in all rooms where you have admin privileges:\
+	lappend msg "\nBan in all rooms where you have admin privileges:\
 	\n/bldjid JID\
 	\nSome reason for banning (optional).\
 	\n\nUnban a banned person in these rooms:\
@@ -636,7 +640,7 @@
 	\n/visitors\
 	\n\nShow all visitors of rooms that match *room*:\
 	\n/visitors room\
-	\n\nShow visits made by someone whose nick or JID matches *nick*:\
+	\n\nShow visits made by someone whose nick matches *nick*:\
 	\n/visited nick\
 	\n\nShows visits made by *nick*, to the rooms that match *room*:\
 	\n/visited nick\
@@ -654,14 +658,7 @@
 	\n\nSee README file for more information.\
 	\nVisit Tkabber -> Customize -> Plugins -> Bldjid\
 	\nto tune the plugin for your needs."
-	if {$options(redirect_output)} {
-		[namespace current]::toggle_monitor $chatid 0
-		[namespace current]::add_message_to_monitor $chatid $header
-		[namespace current]::add_message_to_monitor $chatid "$msg\n\n"
-	} else {
-		::chat::add_message $chatid $group error $header {}
-		::chat::add_message $chatid $group info $msg {}
-	}
+	[namespace current]::print_search_res $chatid $group $header $msg
 }
 
 ### Thanks to Alexey Smirnov <alexey.smirnov at gmx.com>
@@ -772,6 +769,8 @@
 
 # I have doubts if it's OK to use catch results as a condition...
 proc bldjid::toggle_monitor {chatid toggle} {
+	variable options
+	if {!$options(redirect_output)} { return }
 	set ccw [::chat::winid $chatid]
 	if {![catch {pack info $ccw.mon} res] && $toggle} {
 		pack forget $ccw.mon $ccw.vsb



More information about the Tkabber-dev mailing list