examples/attention.lua
author Myhailo Danylenko <isbear@ukrpost.net>
Sat, 01 Aug 2009 23:05:11 +0300
changeset 79 05328c643696
parent 68 742878c74b8e
child 99 ed4676536ed9
permissions -rw-r--r--
Mcabber-lm includes moved into a project tree
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50
12d8dd774fcc Attention
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
     1
68
742878c74b8e Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents: 66
diff changeset
     2
local lm        = require 'lm'
742878c74b8e Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents: 66
diff changeset
     3
local attention = require 'lm.attention'
50
12d8dd774fcc Attention
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
     4
68
742878c74b8e Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents: 66
diff changeset
     5
attention.handler (
742878c74b8e Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents: 66
diff changeset
     6
	function ( mesg )
742878c74b8e Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents: 66
diff changeset
     7
		local times = 0
742878c74b8e Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents: 66
diff changeset
     8
		main.timer ( 1,
742878c74b8e Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents: 66
diff changeset
     9
			function ()
742878c74b8e Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents: 66
diff changeset
    10
				if times < 6 then
742878c74b8e Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents: 66
diff changeset
    11
					main.beep ()
742878c74b8e Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents: 66
diff changeset
    12
					times = times + 1
742878c74b8e Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents: 66
diff changeset
    13
					return true
742878c74b8e Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents: 66
diff changeset
    14
				end
742878c74b8e Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents: 66
diff changeset
    15
				return false
742878c74b8e Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents: 66
diff changeset
    16
			end )
742878c74b8e Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents: 66
diff changeset
    17
	end )
50
12d8dd774fcc Attention
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    18
68
742878c74b8e Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents: 66
diff changeset
    19
main.command ( 'attention',
742878c74b8e Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents: 66
diff changeset
    20
	function ( args )
742878c74b8e Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents: 66
diff changeset
    21
		local who
742878c74b8e Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents: 66
diff changeset
    22
		if args.t then
742878c74b8e Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents: 66
diff changeset
    23
			who = args.t
742878c74b8e Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents: 66
diff changeset
    24
		else
742878c74b8e Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents: 66
diff changeset
    25
			who = main.full_jid ()
742878c74b8e Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents: 66
diff changeset
    26
		end
742878c74b8e Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents: 66
diff changeset
    27
		attention.send ( lm.connection.bless ( main.connection () ), who, args[1] )
742878c74b8e Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents: 66
diff changeset
    28
	end, true, 'jid' )
742878c74b8e Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents: 66
diff changeset
    29
742878c74b8e Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents: 66
diff changeset
    30
commands_help['attention'] = "[-t to] [message]\n\nTries to get buddy's attention."
50
12d8dd774fcc Attention
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    31
68
742878c74b8e Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents: 66
diff changeset
    32
local attention_handler = lm.message_handler.new ( attention.message_handler )
742878c74b8e Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents: 66
diff changeset
    33
local attention_handler_registered = false
66
542f61e113cb Modularization, I
Myhailo Danylenko <isbear@ukrpost.net>
parents: 50
diff changeset
    34
68
742878c74b8e Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents: 66
diff changeset
    35
hooks_d['hook-post-connect'].attention =
742878c74b8e Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents: 66
diff changeset
    36
	function ( args )
742878c74b8e Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents: 66
diff changeset
    37
		lm.connection.bless( main.connection () ):handler ( attention_handler, 'message', 'normal' )
742878c74b8e Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents: 66
diff changeset
    38
		attention_handler_registered = true
742878c74b8e Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents: 66
diff changeset
    39
		hooks_d['hook-post-connect'].attention = nil
742878c74b8e Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents: 66
diff changeset
    40
		hooks_d['hook-quit'].attention =
742878c74b8e Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents: 66
diff changeset
    41
			function ( args )
742878c74b8e Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents: 66
diff changeset
    42
				if attention_handler_registered then
742878c74b8e Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents: 66
diff changeset
    43
					lm.connection.bless( main.connection () ):handler ( attention_handler, 'message' )
742878c74b8e Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents: 66
diff changeset
    44
				end
742878c74b8e Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents: 66
diff changeset
    45
			end
50
12d8dd774fcc Attention
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    46
	end
12d8dd774fcc Attention
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    47
68
742878c74b8e Lm separation, privacy
Myhailo Danylenko <isbear@ukrpost.net>
parents: 66
diff changeset
    48
main.add_feature ( 'urn:xmpp:attention:0' )
50
12d8dd774fcc Attention
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    49
12d8dd774fcc Attention
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    50
-- vim: se ts=4: --