examples/mc_attention.lua
changeset 66 542f61e113cb
equal deleted inserted replaced
65:f1be8dbb209c 66:542f61e113cb
       
     1 
       
     2 local lm        = require 'lm'
       
     3 local attention = require 'attention'
       
     4 
       
     5 attention.handler (
       
     6 	function ( mesg )
       
     7 		local times = 0
       
     8 		main.timer ( 1,
       
     9 			function ()
       
    10 				if times < 6 then
       
    11 					main.beep ()
       
    12 					times = times + 1
       
    13 					return true
       
    14 				end
       
    15 				return false
       
    16 			end )
       
    17 	end )
       
    18 
       
    19 main.command ( 'attention',
       
    20 	function ( args )
       
    21 		local who
       
    22 		if args.t then
       
    23 			who = args.t
       
    24 		else
       
    25 			who = main.full_jid ()
       
    26 		end
       
    27 		attention.send ( lm.connection.bless ( main.connection () ), who, args[1] )
       
    28 	end, true, 'jid' )
       
    29 
       
    30 commands_help['attention'] = "[-t to] [message]\n\nTries to get buddy's attention."
       
    31 
       
    32 local attention_handler = lm.message_handler.new ( attention.message_handler )
       
    33 local attention_handler_registered = false
       
    34 
       
    35 hooks_d['hook-post-connect'].attention =
       
    36 	function ( args )
       
    37 		lm.connection.bless( main.connection () ):handler ( attention_handler, 'message', 'normal' )
       
    38 		attention_handler_registered = true
       
    39 		hooks_d['hook-post-connect'].attention = nil
       
    40 		hooks_d['hook-quit'].attention =
       
    41 			function ( args )
       
    42 				if attention_handler_registered then
       
    43 					lm.connection.bless( main.connection () ):handler ( attention_handler, 'message' )
       
    44 				end
       
    45 			end
       
    46 	end
       
    47 
       
    48 main.add_feature ( 'urn:xmpp:attention:0' )
       
    49 
       
    50 -- vim: se ts=4: --