[Tkabber-dev] r163 - trunk/plugins/autosubscribe

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Mon Nov 24 20:23:07 MSK 2008


Author: kostix
Date: 2008-11-24 20:23:07 +0300 (Mon, 24 Nov 2008)
New Revision: 163

Added:
   trunk/plugins/autosubscribe/autosubscribe.tcl
Log:
autosubscribe/autosubscribe.tcl: Added actual plugin code
 missed in previous commit.


Added: trunk/plugins/autosubscribe/autosubscribe.tcl
===================================================================
--- trunk/plugins/autosubscribe/autosubscribe.tcl	                        (rev 0)
+++ trunk/plugins/autosubscribe/autosubscribe.tcl	2008-11-24 17:23:07 UTC (rev 163)
@@ -0,0 +1,85 @@
+# $Id$
+# Allows to automatically approve incoming presence subscription
+# requests, optionally asking for the mutual presence subscription.
+# Written by Konstantin Khomoutov <flatworm at users.sourceforge.net>
+# See licence.terms for the terms of distribution.
+# See README for details.
+
+namespace eval autosubscribe {
+	variable options
+
+	custom::defgroup Plugins [::msgcat::mc "Plugins options."] -group Tkabber
+
+	set group "Auto-subscribe"
+
+	custom::defgroup $group \
+		[::msgcat::mc "Automatically approves presence subscription\
+			requests coming from remote entities.\
+			Optionally can add the the requesting entity to your roster\
+			and send mutual presence subscription request to it."] \
+		-group Plugins
+
+	custom::defvar options(enabled) 0 \
+		[::msgcat::mc "Enables or disables automatic approving\
+			of presence subscription requests."] \
+		-group $group \
+		-type boolean
+
+if 0 {
+	custom::defvar options(add_to_roster) 1 \
+		[::msgcat::mc "Adds subscribed entities to your roster."] \
+		-group $group \
+		-type boolean
+
+	custom::defvar options(roster_group) "Auto-subscribed" \
+		[::msgcat::mc "Roster group to assign auto-subscribed\
+			entities to."] \
+		-group $group \
+		-type string
+}
+
+	custom::defvar options(ask_subscription) 0 \
+		[::msgcat::mc "Sends mutual presence subscription requst to\
+			subscribed entities.\
+			Note that this setting has no effect if adding subscribed\
+			entities to the roster is disabled."] \
+		-group $group \
+		-type boolean
+
+	custom::defvar options(reason) "Please approve my subscription" \
+		[::msgcat::mc "Presence subscription reason used for requesting\
+			mutual subscription requests."] \
+		-group $group \
+		-type string
+
+	hook::add client_presence_hook \
+		[namespace current]::subscribe 40
+}
+
+proc autosubscribe::subscribe {xlib from type x args} {
+	variable options
+
+	if {!([string equal $type subscribe] && $options(enabled))} return
+
+if 0 {
+	if {$options(add_to_roster)} {
+		upvar 0 options(roster_group) roster_group
+		lappend attrs jid $from
+		if {$roster_group != ""} {
+			lappend attrs group $roster_group
+		}
+		::xmpp::sendIQ $xlib set \
+			-query [::xmpp::xml::create query \
+				-xmlns jabber:iq:roster \
+				-subelement [::xmpp::xml::create item -attrs $attrs]]
+	}
+}
+
+	::xmpp::sendPresence $xlib -to $from -type subscribed
+
+	if {$options(ask_subscription)} {
+		::xmpp::sendPresence $xlib -to $from -type subscribe \
+			-status $options(reason)
+	}
+}
+


Property changes on: trunk/plugins/autosubscribe/autosubscribe.tcl
___________________________________________________________________
Added: svn:keywords
   + Id
Added: svn:eol-style
   + native



More information about the Tkabber-dev mailing list