Merge pull request #13 from AkselMeola/master
[mirrors/libpurple-core-answerscripts.git] / purple / answerscripts.sh
CommitLineData
555bb790 1#!/bin/bash
086adff4 2#
b44d7b66 3# This file is called for every message received by libpurple clients (pidgin,finch,...)
086adff4 4# - You can try to rewrite this script in PERL or C for better performance (or different platform) - let me know
24623630 5# - On M$ Windows answerscripts.exe from libpurple directory will be called instead of this script
0636d441 6#
b44d7b66 7# Maybe you will want to add more hooks for receiving messages, so i've made following script
0636d441 8# - It just executes all +x files in answerscripts.d directory so you should do your magic there
24623630
H
9# - To disable some of those scripts simply use: chmod -x ./script
10# - There is some basic structure, which means that all scripts should start their names with two-digit number
11# - Files are executed in order specified by those numbers and some numbers have special meanings:
12# - AB?!_ scripts without numbers are NOT executed!
13# - 00 executed immediately, zero or single line output (parallel async processing)
14# - 01-48 executed immediately, multiline output (serial processing)
218061aa 15# - 49 delay script (adds random delay to emulate human factor, no user scripts at this level!)
24623630
H
16# - 50 executed after delay, zero or single line output (parallel async processing)
17# - 51-79 executed after delay, multiline output (serial processing)
18# - 80-99 reserved for future
b44d7b66 19
24623630
H
20#this may be modified to use run-parts from coreutils in future (can't get it to work):
21
22dir="$(dirname "$0")"; cd "$dir" #chdir to ~/.purple/ or similar
23dir="${dir}/answerscripts.d"
b44d7b66 24if test -d "$dir"; then
24623630
H
25 for i in {00..99}; do
26
27 #sleep at 49 (this can be replaced by 49-delay.sh, but this should be faster)
28 [ $i -eq 49 ] && {
218061aa
H
29 find "$dir"/[5-9][0-9]-* -executable | grep . >/dev/null && #check if it's worth waiting
30 sleep $(( 2 + ($RANDOM % 8) )); #2-9 seconds of sleep
24623630
H
31 continue;
32 }
33
34 #execute scripts
35 ls -1 "$dir/$i"* 2>/dev/null | while read script; do
36 test -x "$script" && {
37 #determine wheter execute on background or foreground
38 if [ $i -eq 00 ] || [ $i -eq 50 ]; then
39 "$script" &
40 else
41 "$script"
42 fi;
43 }
44 done;
45
46 wait; #wait for processes on background
47
48 done;
b44d7b66 49fi
49bc37a9
TM
50
51#return 0 = do not block the message
52exit 0
This page took 0.128073 seconds and 4 git commands to generate.