# HG changeset patch # User Myhailo Danylenko # Date 1237690469 -7200 # Node ID 12d8dd774fcc24a181871d33be4acb1e1f731240 # Parent 95f3bf77c5985cf6a75efaff9a934360c0a5781f Attention diff -r 95f3bf77c598 -r 12d8dd774fcc examples/attention.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/attention.lua Sun Mar 22 04:54:29 2009 +0200 @@ -0,0 +1,89 @@ + +-- ATTENTION (XEP-0224) + +-- library + +require 'lm' + +-- public + +attention = { + handler = + function ( mesg ) + end, +} + +function attention.send ( conn, to, message ) + local body = nil + if message then + body = { message } + end + conn:send ( + lm.message.create { mtype = 'message-headline', to = to, + attention = { xmlns = 'urn:xmpp:attention:0' }, + body = body, + } ) +end + +-- private + +local attention_incoming_message_handler = lm.message_handler.new ( + function ( conn, mess ) + local a = mess:child ( 'attention' ) + if a and a:attribute ( 'xmlns' ) == 'urn:xmpp:attention:0' then + local body = mess:child ( 'body' ) + if body then + body = body:value () + end + attention.handler ( body ) + end + return false + end ) + +-- mcabber + +attention.handler = + function ( mesg ) + local times = 0 + main.timer ( 1, + function () + if times < 6 then + main.beep () + times = times + 1 + return true + end + return false + end ) + end + +main.command ( 'attention', + function ( args ) + local who + if args.t then + who = args.t + else + who = main.full_jid () + end + attention.send ( lm.connection.bless ( main.connection () ), who, args[1] ) + end, true, 'jid' ) + +commands_help['attention'] = "[-t to] [message]\n\nTries to get buddy's attention." + +local attention_handler_registered = false + +hooks_d['hook-post-connect'].attention = + function ( args ) + lm.connection.bless( main.connection () ):handler ( attention_incoming_message_handler, 'message', 'normal' ) + attention_handler_registered = true + hooks_d['hook-post-connect'].attention = nil + hooks_d['hook-quit'].attention = + function ( args ) + if attention_handler_registered then + lm.connection.bless( main.connection () ):handler ( attention_incoming_message_handler, 'message' ) + end + end + end + +main.add_feature ( 'urn:xmpp:attention:0' ) + +-- vim: se ts=4: -- diff -r 95f3bf77c598 -r 12d8dd774fcc examples/mcabberrc.lua --- a/examples/mcabberrc.lua Sun Mar 22 04:14:36 2009 +0200 +++ b/examples/mcabberrc.lua Sun Mar 22 04:54:29 2009 +0200 @@ -249,6 +249,14 @@ dopath 'marking' +-- JOBS + +dopath 'jobs' + +-- ROOM NICK COMPLETION + +dopath 'room_priv' + -- DATA FORMS (XEP-0004) dopath 'x_data' @@ -281,12 +289,8 @@ dopath 'pep' --- JOBS - -dopath 'jobs' +-- ATTENTION (XEP-0224) --- ROOM NICK COMPLETION - -dopath 'room_priv' +dopath 'attention' -- The End -- vim: se ts=4: --