plugins/mod_time.lua
author Waqas Hussain <waqas20@gmail.com>
Thu, 04 Dec 2008 20:16:30 +0500
changeset 541 3521e0851c9e
parent 519 cccd610a0ef9
child 615 4ae3e81513f3
permissions -rw-r--r--
Change modules to use the new add_feature module API method. This also fixes the bug causing disco features being added to every disco reply for every host.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
519
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
     1
-- Prosody IM v0.1
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
     2
-- Copyright (C) 2008 Matthew Wild
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
     3
-- Copyright (C) 2008 Waqas Hussain
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
     4
-- 
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
     5
-- This program is free software; you can redistribute it and/or
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
     6
-- modify it under the terms of the GNU General Public License
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
     7
-- as published by the Free Software Foundation; either version 2
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
     8
-- of the License, or (at your option) any later version.
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
     9
-- 
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
    10
-- This program is distributed in the hope that it will be useful,
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
    11
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
    12
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
    13
-- GNU General Public License for more details.
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
    14
-- 
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
    15
-- You should have received a copy of the GNU General Public License
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
    16
-- along with this program; if not, write to the Free Software
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
    17
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
    18
--
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
    19
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 438
diff changeset
    20
423
c9c7f026a108 Added mod_time with support for [XEP-0202: Entity Time] and [XEP-0090: Entity Time] (deprecated)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
    21
c9c7f026a108 Added mod_time with support for [XEP-0202: Entity Time] and [XEP-0090: Entity Time] (deprecated)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
    22
local st = require "util.stanza";
c9c7f026a108 Added mod_time with support for [XEP-0202: Entity Time] and [XEP-0090: Entity Time] (deprecated)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
    23
local datetime = require "util.datetime".datetime;
424
3eb22492e8ab Changed format for XEP-0090 to the legacy format
Waqas Hussain <waqas20@gmail.com>
parents: 423
diff changeset
    24
local legacy = require "util.datetime".legacy;
423
c9c7f026a108 Added mod_time with support for [XEP-0202: Entity Time] and [XEP-0090: Entity Time] (deprecated)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
    25
c9c7f026a108 Added mod_time with support for [XEP-0202: Entity Time] and [XEP-0090: Entity Time] (deprecated)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
    26
-- XEP-0202: Entity Time
c9c7f026a108 Added mod_time with support for [XEP-0202: Entity Time] and [XEP-0090: Entity Time] (deprecated)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
    27
541
3521e0851c9e Change modules to use the new add_feature module API method.
Waqas Hussain <waqas20@gmail.com>
parents: 519
diff changeset
    28
module:add_feature("urn:xmpp:time");
423
c9c7f026a108 Added mod_time with support for [XEP-0202: Entity Time] and [XEP-0090: Entity Time] (deprecated)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
    29
438
193f9dd64f17 Bumper commit for the new modulemanager API \o/ Updates all the modules, though some more changes may be in store.
Matthew Wild <mwild1@gmail.com>
parents: 424
diff changeset
    30
module:add_iq_handler({"c2s", "s2sin"}, "urn:xmpp:time",
423
c9c7f026a108 Added mod_time with support for [XEP-0202: Entity Time] and [XEP-0090: Entity Time] (deprecated)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
    31
	function(session, stanza)
c9c7f026a108 Added mod_time with support for [XEP-0202: Entity Time] and [XEP-0090: Entity Time] (deprecated)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
    32
		if stanza.attr.type == "get" then
c9c7f026a108 Added mod_time with support for [XEP-0202: Entity Time] and [XEP-0090: Entity Time] (deprecated)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
    33
			session.send(st.reply(stanza):tag("time", {xmlns="urn:xmpp:time"})
c9c7f026a108 Added mod_time with support for [XEP-0202: Entity Time] and [XEP-0090: Entity Time] (deprecated)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
    34
				:tag("tzo"):text("+00:00"):up() -- FIXME get the timezone in a platform independent fashion
c9c7f026a108 Added mod_time with support for [XEP-0202: Entity Time] and [XEP-0090: Entity Time] (deprecated)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
    35
				:tag("utc"):text(datetime()));
c9c7f026a108 Added mod_time with support for [XEP-0202: Entity Time] and [XEP-0090: Entity Time] (deprecated)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
    36
		end
c9c7f026a108 Added mod_time with support for [XEP-0202: Entity Time] and [XEP-0090: Entity Time] (deprecated)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
    37
	end);
c9c7f026a108 Added mod_time with support for [XEP-0202: Entity Time] and [XEP-0090: Entity Time] (deprecated)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
    38
c9c7f026a108 Added mod_time with support for [XEP-0202: Entity Time] and [XEP-0090: Entity Time] (deprecated)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
    39
-- XEP-0090: Entity Time (deprecated)
c9c7f026a108 Added mod_time with support for [XEP-0202: Entity Time] and [XEP-0090: Entity Time] (deprecated)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
    40
541
3521e0851c9e Change modules to use the new add_feature module API method.
Waqas Hussain <waqas20@gmail.com>
parents: 519
diff changeset
    41
module:add_feature("jabber:iq:time");
423
c9c7f026a108 Added mod_time with support for [XEP-0202: Entity Time] and [XEP-0090: Entity Time] (deprecated)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
    42
438
193f9dd64f17 Bumper commit for the new modulemanager API \o/ Updates all the modules, though some more changes may be in store.
Matthew Wild <mwild1@gmail.com>
parents: 424
diff changeset
    43
module:add_iq_handler({"c2s", "s2sin"}, "jabber:iq:time",
423
c9c7f026a108 Added mod_time with support for [XEP-0202: Entity Time] and [XEP-0090: Entity Time] (deprecated)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
    44
	function(session, stanza)
c9c7f026a108 Added mod_time with support for [XEP-0202: Entity Time] and [XEP-0090: Entity Time] (deprecated)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
    45
		if stanza.attr.type == "get" then
c9c7f026a108 Added mod_time with support for [XEP-0202: Entity Time] and [XEP-0090: Entity Time] (deprecated)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
    46
			session.send(st.reply(stanza):tag("query", {xmlns="jabber:iq:time"})
424
3eb22492e8ab Changed format for XEP-0090 to the legacy format
Waqas Hussain <waqas20@gmail.com>
parents: 423
diff changeset
    47
				:tag("utc"):text(legacy()));
423
c9c7f026a108 Added mod_time with support for [XEP-0202: Entity Time] and [XEP-0090: Entity Time] (deprecated)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
    48
		end
c9c7f026a108 Added mod_time with support for [XEP-0202: Entity Time] and [XEP-0090: Entity Time] (deprecated)
Waqas Hussain <waqas20@gmail.com>
parents:
diff changeset
    49
	end);