[Tkabber-dev] r15 - trunk/plugins/presencecmd

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Sat Jul 14 04:48:55 MSD 2007


Author: kostix
Date: 2007-07-14 04:48:55 +0400 (Sat, 14 Jul 2007)
New Revision: 15

Added:
   trunk/plugins/presencecmd/README
Modified:
   trunk/plugins/presencecmd/TODO
   trunk/plugins/presencecmd/presencecmd.tcl
Log:
presencecmd:
* presencecmd.tcl: fixed regexp, implemented sending of presence.
* README: added readme file with description and examples.
* TODO: updated.

First working version.


Added: trunk/plugins/presencecmd/README
===================================================================
--- trunk/plugins/presencecmd/README	                        (rev 0)
+++ trunk/plugins/presencecmd/README	2007-07-14 00:48:55 UTC (rev 15)
@@ -0,0 +1,112 @@
+"Presence command" chat plugin for Tkabber.
+$Id$
+
+I. The idea.
+
+This plugin provides additional set of what is called "IRC-style
+chat command" in Tkabber -- specially formatted messages which
+are recognized as commands to Tkabber. They are parsed and
+executed and their text is thrown away (widely known examples of
+standard chat commands are: /clear, /nick, /ban, etc).
+
+Provided commands are:
+* /presence allows to change "master" (i.e. basic, main,
+  global) presence of the user [1];
+* /chatpresence (or its alias /thispresence) allows to change
+  the presence in this chat session (which may be a MUC room)
+  only, in other words it sends what is called "directed
+  presence" to the chat peer or room [2]. (See also "Notes"
+  section below.)
+
+II. Usage.
+
+Both commands have identical syntax and they behave identical --
+only the "presence instance" they operate on changes.
+
+The formal syntax is:
+/presence ?presence|clear[status]?
+?status message?
+
+(Fields surrounded by "?" represent optional parts.)
+
+Note that while both presence and status message are marked
+optional at least one of them MUST appear. Otherwise the command
+has no sense and the usage message is shown in the chat log
+window.
+
+The presence field may have this (standard) values, literally:
+* available -- user is available;
+* avail -- shortcut for "available";
+* away -- user is away;
+* xa -- user is extended away;
+* dnd -- user doesn't want to be disturbed;
+* chat -- user is free for chat.
+
+Note that there's currently no support for "unavail"
+presence.
+
+The special value of the presence field is "clearstatus"
+("clear" is a shortcut to it). When spceified, the status
+message is set to the empty string; the presence itself isn't
+changed. (See also section "Notes" below.)
+
+The status message field may be used to provide status message
+for the presence. Any text, on a new line after the command (and
+the presence value, if specified) is theated as the status
+message, so it can span multiple lines and have empty lines in
+between. The only transformation that is applied to the status
+message is removal of any leading and trailing whitespace.
+
+Any of this fields (but not all) may be omitted. In this case
+its current value is kept intact.
+
+III. Examples:
+
+Set the "do not disturb" master presence:
+/presence dnd
+
+Set the "free to chat" presence with a fancy status message:
+/presence chat
+Hey girls!
+
+Just change the status message while keeping the presence
+intact:
+/presence
+To be, or not to be --
+That is the question.
+
+Send directed presence to the chat peer (or to the room you're
+in):
+/chatpresence xa
+Gone shopping
+
+Just change the status message seen by the chat peer (or in the
+room):
+/thispresence
+Gone nuts emerging ebuilds
+
+IV. Notes.
+
+1. You should understand that directed presence is somewhat odd
+in its behaviour to many (not to say most) users: any change in
+master presence invalidates any directed presences which were
+set before. In other words if you set, say, "dnd" presence in
+some MUC room and then change your master presence to "chat",
+this one will be broadcasted to that room also changing your
+presence there to "chat".
+
+2. Oddly enough, but currently there's no easy way in Tkabber to
+sent *really* empty status message: if Tkabber is told to send
+one it replaces it with the "canonical" spelling of the presence
+being set in your locale. I.e. when you set the available
+presence with the empty status message and have an English
+locale, Tkabber will cook the "Available" status message for
+you. This is done so that presence stanzas can be PGP-signed, if
+PGP encryption is enabled.
+
+V. References:
+
+1. http://www.xmpp.org/rfcs/rfc3921.html#presence
+2. http://www.xmpp.org/rfcs/rfc3921.html#presence-resp-directed
+
+vim:et:ts=4:sw=4:tw=64


Property changes on: trunk/plugins/presencecmd/README
___________________________________________________________________
Name: svn:keywords
   + Id

Modified: trunk/plugins/presencecmd/TODO
===================================================================
--- trunk/plugins/presencecmd/TODO	2007-07-13 18:29:53 UTC (rev 14)
+++ trunk/plugins/presencecmd/TODO	2007-07-14 00:48:55 UTC (rev 15)
@@ -2,15 +2,16 @@
 
 HIGH:
 
-* Fix regexp so that it:
-  * Allows for empty presence;
-  * Allows for non-empty status.
+* Occasionally "status change only" commands are parsed incorrectly --
+  the status gets parsed as presence, say, in:
+  /chatstatus
+  suxx
 
-* Provide for actual change of presence and/or status if parsed successfully.
+  (Actual cause unknown.)
 
 LOW:
 
-* Write README, provide ChangeLog and VERSION files.
+* Write provide ChangeLog and VERSION files.
 
 * Russian message catalog.
 

Modified: trunk/plugins/presencecmd/presencecmd.tcl
===================================================================
--- trunk/plugins/presencecmd/presencecmd.tcl	2007-07-13 18:29:53 UTC (rev 14)
+++ trunk/plugins/presencecmd/presencecmd.tcl	2007-07-14 00:48:55 UTC (rev 15)
@@ -18,58 +18,104 @@
 	upvar 0 $compsvar comps
     
 	if {!$wordstart} {
-		lappend comps {/presence } {/chatpresence }
+		lappend comps {/presence } {/chatpresence } {/thispresence }
 	}
 }
 
-if 0 {
-	Use cases:
-	/presence avail
-	/presence xa
-	gone shopping!
-	/presence
-	woohoo!
-}
+proc presencecmd::handle_command {chatid user body type} {
+	global userstatus
 
-# RE1: {^(/presence|/chatpresence)(?!\S+)([^\n]+)(?!\n?(.+))$}
-
-proc presencecmd::handle_command {chatid user body type} {
 	if {!([string match {/presence*} $body] \
-	|| [string match {/chatpresence*} $body])} return
+	|| [string match {/chatpresence*} $body] \
+	|| [string match {/thispresence*} $body])} return
 
-	# TODO fix regexp: must allow empty presence and non-empty status
-	if {![regexp {^(/presence|/chatpresence)(?!\S+)([^\n]+)(?!\n?(.+))$} \
+	if {![regexp {^(/presence|/chatpresence|/thispresence)(?:\s*)(\w*)(?:\s*\n(.*))?$} \
 		$body - cmd pres status]} {
-		show info $chatid [::msgcat::mc "Usage:\
-			\t/presence PRESENCE\n\
-			\t?status message?\n\
-			or\n\
-			\t/chatpresence PRESENCE\n\
-			\t?status message?\n\
-			Where PRESENCE is one of: avail\[able\], away, xa, dnd"]
+		show_usage $chatid
 		return stop
 	}
 
-	set pres [string trim $pres]
+	set status [string trim $status]
+	set sendstatus [expr {$status != ""}]
 
-	switch -- $pres {
-		avail -
-		available -
-		away -
-		xa -
-		dnd {}
-		default {
-			show error $chatid [::msgcat::mc "Unknown presence: %s" $pres]
-			return stop
+	if {$pres == "" && !$sendstatus} {
+		show_usage $chatid
+		return stop
+	}
+
+	if {$pres != ""} {
+		switch -- $pres {
+			avail {
+				set pres available
+			}
+			available -
+			away -
+			xa -
+			dnd -
+			chat {
+			}
+			clear -
+			clearstatus {
+				set sendstatus true
+				set pres $userstatus
+				set status ""
+			}
+			default {
+				show error $chatid [::msgcat::mc "Unknown presence: %s" $pres]
+				return stop
+			}
 		}
+	} else {
+		set pres $userstatus
 	}
 
-	show info $chatid "pres: <$pres>\nstatus: <$status>"
-	# TODO change presence here
+	switch -- $cmd {
+		/presence {
+			set_master_presence $pres $status $sendstatus
+		}
+		/chatpresence -
+		/thispresence {
+			send_directed_presence $chatid $pres $status $sendstatus
+		}
+	}
 
 	return stop
 }
 
+proc presencecmd::set_master_presence {pres status sendstatus} {
+	global userstatus textstatus
+
+	if {$sendstatus} { set textstatus $status }
+	set userstatus $pres ;# this triggers sending the presence
+}
+
+proc presencecmd::send_directed_presence {chatid pres status sendstatus} {
+	global userpriority
+
+	set cmd [list send_presence $pres \
+		-to [chat::get_jid $chatid] \
+		-pri $userpriority \
+		-connection [chat::get_connid $chatid]]
+
+	if {$sendstatus} {
+		lappend cmd -stat $status
+	}
+
+	eval $cmd
+}
+
+proc presencecmd::show_usage chatid {
+	show error $chatid [::msgcat::mc "Usage:\
+\t/presence ?presence|clear\[status\]?\n\
+\t?status message?\n\
+or\n\
+\t/chatpresence ?presence|clear\[status\]?\n\
+\t?status message?\n\
+Where presence is one of: avail\[able\], away, xa, dnd, chat.\n\
+Special presence \"clear\[status\]\" just clears the current status.\n\
+/thispresence is an alias for /chatpresence"]
+}
+
 # $type should be either "info" or "error"
 proc presencecmd::show {type chatid msg} {
 	set jid [chat::get_jid $chatid]
@@ -77,3 +123,4 @@
 
 	chat::add_message $chatid $jid $type $msg {}
 }
+



More information about the Tkabber-dev mailing list