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

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Tue Mar 17 06:06:29 MSK 2009


Author: bigote
Date: 2009-03-17 06:06:29 +0300 (Tue, 17 Mar 2009)
New Revision: 178

Added:
   trunk/plugins/bldjid/ChangeLog
   trunk/plugins/bldjid/INSTALL
   trunk/plugins/bldjid/README
   trunk/plugins/bldjid/TODO
   trunk/plugins/bldjid/bldjid.tcl
   trunk/plugins/bldjid/license.terms
   trunk/plugins/bldjid/muc_save_entrance_message.diff
Log:
Version 0.4a of the plugin uploaded.


Added: trunk/plugins/bldjid/ChangeLog
===================================================================
--- trunk/plugins/bldjid/ChangeLog	                        (rev 0)
+++ trunk/plugins/bldjid/ChangeLog	2009-03-17 03:06:29 UTC (rev 178)
@@ -0,0 +1,31 @@
+2009-03-17  Serge Yudin  <xmpp:bigote at jabber.ru> <mailto:bigote at gmail.com>
+
+--- Version 0.4a of the plugin.
+---	Files:
+	bldjid.tcl		plugin file.
+	INSTALL			installation instruction file.
+	license.terms	license file.
+	README			usage file.
+	TODO			my plans of plugin developing.
+	muc_save_entrance_message.diff	a patch that must be applied to muc.tcl
+									in order Alpha commands (see below) could work.
+	ChangeLog		this file.
+
+---	Commands:
+	/banjid	JID	
+	reason			ban 'JID' in the current conference if you have admin rights there.
+	/bldjid JID
+	reason			ban 'JID' in every conference where you have admin rights.
+	/unbldjid JID	unban 'JID' in all your conferences.
+	/amnesty		unban all outcasts in the current conference.
+
+	Alpha commands (also, muc.tcl should be patched), can be used when
+	::muc::options(gen_enter_exit_msgs) is disabled.
+	/visitors		show all visitors of the current room.
+	/visitors room	show all visitors of rooms that match *room*.
+	/visited		show all visits to all rooms.
+	/visited nick	show visits made by someone whose nick or JID matches *nick*
+	/visited nick
+	room			shows visits made by *nick*, to the rooms that match *room*
+
+	See README file for more info.

Added: trunk/plugins/bldjid/INSTALL
===================================================================
--- trunk/plugins/bldjid/INSTALL	                        (rev 0)
+++ trunk/plugins/bldjid/INSTALL	2009-03-17 03:06:29 UTC (rev 178)
@@ -0,0 +1,17 @@
+To install this plugin just place its directory (bldjid) 
+into Tkabber's plugin directory. Most likely it is either 
+~/.tkabber/plugins
+or
+C:\Documents and Settings\YourUser\Application Data\Tkabber\plugins
+where C: is the drive your system is installed on.
+
+So, you'll have something like this:
+~/.tkabber/plugins/bldjid/bldjid.tcl
+or
+C:\Documents and Settings\YourUser\Application Data\Tkabber\plugins\bldjid\bldjid.tcl
+
+After that you have to restart Tkabber in order to get plugin's functionality.
+
+
+See README file for usage and...
+Happy banning! :-D

Added: trunk/plugins/bldjid/README
===================================================================
--- trunk/plugins/bldjid/README	                        (rev 0)
+++ trunk/plugins/bldjid/README	2009-03-17 03:06:29 UTC (rev 178)
@@ -0,0 +1,81 @@
+This plugin is a would-be right hand of any conference administrator.
+
+First of all, it is intended to help you banning nasty people
+in all conferences where you have corresponding privileges.
+Let them waste as least of your time as possible!
+
+Usage:
+---	To ban in all rooms where you have admin privileges:
+/bldjid JID
+Some reason for banning.
+
+---	To unban a banned person in these rooms:
+/unbldjid JID
+
+Also a command is added to ban a user in the current room by his/her JID.
+The user is not necessarily has to be in the room at the moment.
+(Tkabber's command /ban only bans by nickname 
+and only if the user is still in the room).
+
+---	Usage:
+/banjid JID
+Some reason for banning.
+
+---	If you're in a good mood (it's your birthday, for instance),
+you might want to unban all people banned in a certain room.
+To do so, just write there the following command:
+/amnesty
+and after a confirmation all outcasts from that room will be unbanned.
+
+
+New commands added that could be helpful 
+when ::muc::options(gen_enter_exit_msgs) is disabled.
+=================================================
+= At the moment muc.tcl must be patched         =
+= so that these commands could work.            =
+= The patch is placed in the plugin's directory =
+= If the patch cannot be applied because of     =
+= muc.tcl recent updates, please add necessary  =
+= lines manually depending on the context.      =
+=================================================
+
+---	Show all visitors of the current room
+/visitors
+
+---	Show all visitors of rooms that match *room*
+/visitors room
+
+---	Show all visits to all rooms
+/visited
+
+---	Show visits made by someone whose nick or JID matches *nick*
+/visited nick
+
+---	Shows visits made by *nick*, to the rooms that match *room*
+/visited nick
+room
+
+An enumerated list styled as 'info' will be shown in the current chat window.
+In order to choose a line from it use the following command
+/pickup ?n?
+
+where ?n? is an integer between 0 and the last item number.
+
+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 affect gathering new entries:
+they are put either to the list or to chat windows.
+
+ATTENTION: At the moment the whole chosen line is printed as an error message.
+It should be analized and a JID from it (if any) should be inserted 
+into the current edit box, the cursor is to be moved to the beginning of the line.
+This way you can start typing a new bldjid command 
+that could be autocompleted as well.
+
+Autocompletion works for all these commands: write a couple 
+of the first letters of a command and hit TAB one of more times.
+
+Plugin's name takes its origin from a Russian word "bldjad" and "JID."
+It also could be taken as an acronim: "Ban Lousy Dorks (by) JID."
+Most part of its code is stolen^W taken from "Urlcmd" plugin and muc.tcl module.

Added: trunk/plugins/bldjid/TODO
===================================================================
--- trunk/plugins/bldjid/TODO	                        (rev 0)
+++ trunk/plugins/bldjid/TODO	2009-03-17 03:06:29 UTC (rev 178)
@@ -0,0 +1,17 @@
+---	At the moment the whole chosen line is printed as an error message.
+	(Just for test sake.)
+	It should be analized and a JID from it (if any) should be inserted
+	into the current edit box, the cursor is to be moved to the beginning 
+	of the line. This way you can start typing a new bldjid command
+	that could be autocompleted as well.
+---	Add /blcommands command that shows a short usage example list.
+---	Add some limit for the list for /visitors and /visited commands.
+	How much? I have about 12 rooms and a couple of them are quite populated.
+	So the list grows some 700 records a day. I think 5000 would be OK.
+	However, I'd betted add an option into Customize.
+
+---	Add "Bldjid" menu item with all commands to room MUC menu.
+	Note that a list of rooms must be done for these commands to work.
+---	Add "Antiflood & Autokick" functionality.
+---	Add options to Customize (for visites list limit, visites list clearing,
+	"Antiflood & Autokick" options).

Added: trunk/plugins/bldjid/bldjid.tcl
===================================================================
--- trunk/plugins/bldjid/bldjid.tcl	                        (rev 0)
+++ trunk/plugins/bldjid/bldjid.tcl	2009-03-17 03:06:29 UTC (rev 178)
@@ -0,0 +1,312 @@
+# "Bldjid" plugin for Tkabber. 2009-03-15 v. 0.4a
+# Written by Serge Yudin xmpp:bigote at jabber.ru
+# See README file for usage.
+
+
+namespace eval bldjid {
+	variable hid_grp_msg
+	variable list_to_show
+	set winid 0
+    ::msgcat::mcload [file join [file dirname [info script]] msgs]
+
+    hook::add generate_completions_hook \
+        [namespace current]::command_comps
+    hook::add chat_send_message_hook \
+        [namespace current]::handle_commands 17
+}
+
+proc bldjid::command_comps {chatid compsvar wordstart line} {
+    upvar 0 $compsvar comps
+
+    if {!$wordstart} {
+        lappend comps {/bldjid } {/unbldjid } {/banjid } {/amnesty } \
+		{/visitors } {/visited } {/pickup }
+    }
+}
+
+proc bldjid::handle_commands {chatid user body type} {
+    # Detect the command.
+    if {[string match {/bldjid*} $body]} {
+        set cmd /bldjid
+    } elseif {[string match {/unbldjid*} $body]} {
+        set cmd /unbldjid
+	} elseif {[string match {/banjid*} $body]} {
+		set cmd /banjid
+	} elseif {[string match {/amnesty*} $body]} {
+		set cmd /amnesty
+	} elseif {[string match {/visitors*} $body]} {
+		set cmd /visitors
+	} elseif {[string match {/visited*} $body]} {
+        set cmd /visited
+	} elseif {[string match {/pickup*} $body]} {
+        set cmd /pickup
+    } else return
+
+    if {$type != "groupchat"} return
+
+    set xlib [chat::get_xlib $chatid]
+    set groupjids {}
+	# 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.
+    foreach tmpchatid [lsort [lfilter chat::is_groupchat [chat::opened $xlib]]] {
+		set tmpgrp [chat::get_jid $tmpchatid]
+		if {([lindex [whoami $xlib $tmpgrp] 1] == "admin" \
+		||   [lindex [whoami $xlib $tmpgrp] 1] == "owner") \
+		&&  ![string match *%*@irc* $tmpgrp]} {
+			 lappend groupjids $tmpgrp
+		}
+	}
+   	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 "]} {
+        lassign [muc::parse_nick_reason $body 8] jid reason
+        set params {affiliation outcast}
+	} elseif {[string equal [string range $body 0 7] "/banjid "]} {
+        lassign [muc::parse_nick_reason $body 8] jid reason
+        set params {affiliation outcast}
+	} elseif {[string equal [string range $body 0 7] "/amnesty"]} {
+		set attr affiliation
+		set val outcast
+	} elseif {[string equal [string range $body 0 8] "/visitors"]} {
+		if {[string index $body 9] == " " && [string length $body] > 10} {
+			set room [muc::parse_nick $body 10]
+		}
+    } elseif {[string equal [string range $body 0 7] "/visited"]} {
+        if {[string index $body 8] == " " && [string length $body] > 9} {
+			lassign [muc::parse_nick_reason $body 9] nick room
+        }
+	} elseif {[string equal [string range $body 0 7] "/pickup "]} {
+		set index [muc::parse_nick $body 8]
+	} else {
+    	return
+    }
+	
+	switch -- $cmd {
+		/unbldjid {
+	    foreach group $groupjids {
+           	muc::unban $xlib $group $jid
+		}
+		}
+
+		/bldjid {
+	    foreach group $groupjids {
+			[namespace current]::send_ban_request $xlib $group $params $jid $reason
+		}
+		}
+
+		/banjid {
+			set group [chat::get_jid $chatid]
+            [namespace current]::send_ban_request $xlib $group $params $jid $reason
+		}
+		
+		/amnesty {
+		set group [chat::get_jid $chatid]
+    	variable winid
+	    set w .amn$winid
+    	incr winid
+	    if {[winfo exists $w]} {
+    	    destroy $w
+	    }
+	    Dialog $w -title [::msgcat::mc "Forgive all outcasts here?"]] \
+    	    -modal none -separator 1 -anchor e -default 0 -cancel 1 \
+        	-parent .
+	    set f [$w getframe]
+    	$w add -text [::msgcat::mc "OK"] \
+        	-command [list [namespace current]::amnesty $chatid $attr $val $w $f]
+	    $w add -text [::msgcat::mc "Cancel"] -command [list destroy $w]
+
+		label $w.lsure -padx 10 -pady 5 \
+		-text "Are you sure you want to unban all outcasts in this room?\n\
+		   There will be no backup: you're either kind-hearted or not ;)"
+		pack $w.lsure -expand yes -fill both
+		$w draw
+		}
+		
+		/visitors {
+		variable hid_grp_msg
+		variable list_to_show
+		set group [chat::get_jid $chatid]
+		set list_to_show {}
+		if {$room == ""} {
+			set room $group
+			set header "Show all visits to the current room:"
+		} else {
+			set header "Show all visits to rooms that match *$room*:"
+		}
+		foreach item $muc::hid_grp_msg {
+			if {[string match *$room* [lindex $item 0]]} {
+				lappend list_to_show $item
+			}
+		}
+        set n 0
+		chat::add_message $chatid $group error $header {}
+		foreach msg $list_to_show {
+        	chat::add_message $chatid $group info "$n: [join $msg]" {}
+			incr n
+		}
+		}
+
+        /visited {
+        variable hid_grp_msg
+        variable list_to_show
+        set group [chat::get_jid $chatid]
+        set list_to_show {}
+        if {$nick == ""} {
+            set header "*Show all visits to all rooms*:"
+        } elseif {$room == ""} {
+			set header "Show visits of *$nick* to all rooms:"
+        } else {
+            set header "Show visits of *$nick* to rooms that match *$room*:"
+        }
+        foreach item $muc::hid_grp_msg {
+            if {[string match *$room* [lindex $item 0]] \
+             && [string match *$nick* [lindex $item 2]]} {
+                lappend list_to_show $item
+            }
+        }
+		set n 0
+		chat::add_message $chatid $group error $header {}
+        foreach msg $list_to_show {
+            chat::add_message $chatid $group info "$n: [join $msg]" {}
+			incr n
+        }
+        }
+
+		/pickup {
+        variable list_to_show
+        set group [chat::get_jid $chatid]
+	    set maxindex [expr {[llength $list_to_show] - 1}]
+	    if {$maxindex < 0} {
+       		# Nothing to show: list is empty.
+	        chat::add_message $chatid $group error "The list is empty." {}
+	        return stop
+	    } elseif {$index > $maxindex || $index < 0} {
+			chat::add_message $chatid $group error "Index out of range." {}
+			return stop
+		} elseif {![string is integer $index]} {
+			chat::add_message $chatid $group error "Index must be integer." {}
+			return stop
+		} else {
+			chat::add_message $chatid $group error "TODO: JID from the chosen message has to be put into the editor field.\
+			\nThe cursor should go to the beginning of the line.\
+			\nAt the moment you have the chosen message here:\
+			\n[lindex $list_to_show $index]" {}
+		}
+		}
+	}
+    return stop
+}
+
+proc bldjid::send_ban_request {xlib group params jid reason} {
+		    set itemsubtags {}
+		    if {$reason != ""} {
+		        lappend itemsubtags [::xmpp::xml::create reason -cdata $reason]
+		    }
+		    set vars [list jid $jid]
+		    set item [::xmpp::xml::create item \
+                  -attrs [concat $vars $params] \
+                  -subelements $itemsubtags]
+		    ::xmpp::sendIQ $xlib set \
+        		-query [::xmpp::xml::create query \
+                -xmlns $::NS(muc#admin) \
+                -subelement $item] \
+		        -to $group \
+        		-command [list [namespace current]::test_error_res "$params \'$jid\'" $xlib $group]
+}
+
+proc bldjid::test_error_res {op xlib group res child} {
+        set chatid [chat::chatid $xlib $group]
+    if {![string equal $res ok]} {
+        chat::add_message $chatid $group error \
+            [format "%s: %s" $op [error_to_string $child]] {}
+    } else {
+		chat::add_message $chatid $group info \
+			[format "%s: %s" $op "User is banned"] {}
+	}
+	return
+}
+
+proc bldjid::amnesty {chatid attr val w f} {
+	set group [chat::get_jid $chatid]
+	request_list $attr $val $chatid
+	destroy $w
+}
+
+proc bldjid::request_list {attr val chatid} {
+    set xlib [chat::get_xlib $chatid]
+    set group [chat::get_jid $chatid]
+    ::xmpp::sendIQ $xlib get \
+        -query [::xmpp::xml::create query \
+                        -xmlns $::NS(muc#admin) \
+                        -subelement [::xmpp::xml::create item \
+                                        -attrs [list $attr $val]]] \
+        -to $group \
+        -command [list [namespace current]::receive_send_list $attr $val $chatid]
+}
+
+proc bldjid::receive_send_list {attr val chatid res child} {
+    set xlib [chat::get_xlib $chatid]
+    set group [chat::get_jid $chatid]
+    if {![string equal $res ok]} {
+        chat::add_message $chatid $group error \
+            "$attr $val list: [error_to_string $child]" {}
+        return
+    }
+    ::xmpp::xml::split $child tag xmlns attrs cdata items
+	if {$items == {}} {
+		chat::add_message $chatid $group error \
+        [::msgcat::mc "The blacklist is already empty for $group"] {}
+		return
+	}
+    set items2 {}
+    foreach item $items {
+        ::xmpp::xml::split $item tag xmlns attrs cdata subels
+        switch -- $tag {
+            item {
+                set nick [::xmpp::xml::getAttr $attrs nick]
+                set jid [::xmpp::xml::getAttr $attrs jid]
+                set role [::xmpp::xml::getAttr $attrs role]
+                set affiliation [::xmpp::xml::getAttr $attrs affiliation]
+                set reason ""
+                foreach subitem $subels {
+                    ::xmpp::xml::split $subitem stag sxmlns sattrs scdata ssubels
+                    if {$stag == "reason"} {
+                        set reason $scdata
+                    }
+                }
+				set itemsubtags {}
+				lappend itemsubtags [::xmpp::xml::create reason \
+							-cdata $reason]
+				lappend items2 [::xmpp::xml::create item \
+                               -attrs "affiliation none jid $jid" \
+                               -subelements $itemsubtags]
+            }
+        }
+    }
+    if {$items2 != {}} {
+        ::xmpp::sendIQ $xlib set \
+            -query [::xmpp::xml::create query \
+                               -xmlns $::NS(muc#admin) \
+                               -subelements $items2] \
+            -to $group \
+            -command [list muc::test_error_res \
+                           [::msgcat::mc "Sending %s %s list" $attr $val] \
+                           $xlib $group]
+    }
+    chat::add_message $chatid $group info \
+        [::msgcat::mc "Thank you for your generosity! +10 to Reputation!"] {}
+}
+
+# Here we get our role and affiliation in a room.
+# Thanks to Konstantin Khomoutov (kostix at 007spb.ru)
+proc bldjid::whoami {xlib where} {
+	if {[muc::is_compatible $where]} {
+		set chatid [chat::chatid $xlib $where]
+		set jid $where/[get_our_groupchat_nick $chatid]
+		list $muc::users(role,$xlib,$jid) $muc::users(affiliation,$xlib,$jid)
+	}
+}

Added: trunk/plugins/bldjid/license.terms
===================================================================
--- trunk/plugins/bldjid/license.terms	                        (rev 0)
+++ trunk/plugins/bldjid/license.terms	2009-03-17 03:06:29 UTC (rev 178)
@@ -0,0 +1,19 @@
+Copyright (c) 2009 Serge Yudin <xmpp:bigote at jabber.ru>, <mailto:bigote at gmail.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESSED
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.

Added: trunk/plugins/bldjid/muc_save_entrance_message.diff
===================================================================
--- trunk/plugins/bldjid/muc_save_entrance_message.diff	                        (rev 0)
+++ trunk/plugins/bldjid/muc_save_entrance_message.diff	2009-03-17 03:06:29 UTC (rev 178)
@@ -0,0 +1,56 @@
+Index: muc.tcl
+===================================================================
+--- muc.tcl	(revisión: 1737)
++++ muc.tcl	(copia de trabajo)
+@@ -40,6 +40,8 @@
+ 	[::msgcat::mc "Report the list of current MUC rooms on\
+ 		       disco#items query."] \
+ 	-type boolean -group IQ
++
++	variable hid_grp_msg
+ }
+ 
+ # MUC affiliations (for translation):
+@@ -1061,7 +1063,7 @@
+ 		if {$options(gen_enter_exit_msgs)} {
+ 		    chat::add_message \
+ 			$chatid $group groupchat $msg {}
+-		}
++		} 
+ 	    }
+ 	    status {
+ 		set code [::xmpp::xml::getAttr $attrs code]
+@@ -1203,6 +1205,7 @@
+     variable options
+     variable users
+     variable ignore_available
++    variable hid_grp_msg
+ 
+     set xlib [::chat::get_xlib $chatid]
+     set group [::chat::get_jid $chatid]
+@@ -1213,8 +1216,8 @@
+ 
+     set msg ""
+ 
+-    set report_entered [expr {$entered && $options(gen_enter_exit_msgs) \
+-	&& (![info exists ignore_available] || $ignore_available != $nick)}]
++    set report_entered [expr {$entered \
++        && (![info exists ignore_available] || $ignore_available != $nick)}]
+ 
+     if {$report_entered} {
+ 	set real_jid [get_real_jid $xlib $jid]
+@@ -1246,7 +1249,13 @@
+ 	}
+     }
+ 
+-    ::chat::add_message $chatid $group groupchat $msg {}
++    if {$options(gen_enter_exit_msgs)} {
++	::chat::add_message $chatid $group groupchat $msg {}
++    } elseif {$msg != ""} {
++	lappend my_msg $group \
++	[clock format [clock seconds] -format $::plugins::options(timestamp_format)] $msg
++	lappend hid_grp_msg $my_msg
++    }
+ }
+ 
+ proc muc::track_room_position {xlib jid role affiliation} {



More information about the Tkabber-dev mailing list