New answerscript that implements few new features (numbered scripts, parallel process...
[mirrors/libpurple-core-answerscripts.git] / purple / answerscripts.sh
CommitLineData
b44d7b66
H
1#!/bin/sh
2
3# This file is called for every message received by libpurple clients (pidgin,finch,...)
0636d441
H
4# - Following env values are passed to this script:
5# - ANSW_FROM (who sent you message)
6# - ANSW_MSG (text of the message)
7# - ANSW_STATUS (unique ID of status. eg.: available, away,...)
8# - ANSW_STATUS_MSG (status message set by user)
9# - WARNING: You should mind security (don't let attackers to execute their messages/nicks!)
10# - Each line of output is sent as reply to that message
11# - You can try to rewrite this script in PERL or C for better performance (or different platform)
24623630 12# - On M$ Windows answerscripts.exe from libpurple directory will be called instead of this script
0636d441 13#
b44d7b66 14# Basic example can look like this:
0636d441
H
15# [ "$ANSW_STATUS" != 'available' ] && echo "<$ANSW_FROM> $ANSW_MSG" && echo "My status: $ANSW_STATUS_MSG";
16#
b44d7b66 17# There are lot of hacks that you can do with this simple framework if you know some scripting. eg.:
0636d441
H
18# - Forward your instant messages to email, SMS gateway, text-to-speach (eg. espeak) or something...
19# - Smart auto-replying messages based on regular expressions
20# - Remote control your music player (or anything else on your computer) using instant messages
21# - Simple IRC/Jabber/ICQ bot (accepts PM only, you can run finch in screen on server)
22# - Providing some service (Searching web, Weather info, System status, RPG game...)
23# - BackDoor (even unintentional one - you've been warned)
24# - Loging and analyzing messages
25# - Connect IM with Arduino
26# - Annoy everyone with spam (and probably get banned everywhere)
27# - Anything else that you can imagine...
28#
b44d7b66 29# Maybe you will want to add more hooks for receiving messages, so i've made following script
0636d441 30# - It just executes all +x files in answerscripts.d directory so you should do your magic there
24623630
H
31# - To disable some of those scripts simply use: chmod -x ./script
32# - There is some basic structure, which means that all scripts should start their names with two-digit number
33# - Files are executed in order specified by those numbers and some numbers have special meanings:
34# - AB?!_ scripts without numbers are NOT executed!
35# - 00 executed immediately, zero or single line output (parallel async processing)
36# - 01-48 executed immediately, multiline output (serial processing)
37# - 49 delay script (adds random delay to emulate human factor)
38# - 50 executed after delay, zero or single line output (parallel async processing)
39# - 51-79 executed after delay, multiline output (serial processing)
40# - 80-99 reserved for future
b44d7b66 41
0636d441
H
42#legacy support, please do NOT use PURPLE_* variables in new scripts,
43#this will be removed in future releases:
44export PURPLE_FROM="$ANSW_FROM"
45export PURPLE_MSG="$ANSW_MSG"
46
24623630
H
47#this may be modified to use run-parts from coreutils in future (can't get it to work):
48
49dir="$(dirname "$0")"; cd "$dir" #chdir to ~/.purple/ or similar
50dir="${dir}/answerscripts.d"
b44d7b66 51if test -d "$dir"; then
24623630
H
52 for i in {00..99}; do
53
54 #sleep at 49 (this can be replaced by 49-delay.sh, but this should be faster)
55 [ $i -eq 49 ] && {
56 sleep $[ 2 + ($RANDOM % 8) ]; #2-9 seconds of sleep
57 continue;
58 }
59
60 #execute scripts
61 ls -1 "$dir/$i"* 2>/dev/null | while read script; do
62 test -x "$script" && {
63 #determine wheter execute on background or foreground
64 if [ $i -eq 00 ] || [ $i -eq 50 ]; then
65 "$script" &
66 else
67 "$script"
68 fi;
69 }
70 done;
71
72 wait; #wait for processes on background
73
74 done;
b44d7b66 75fi
This page took 0.139977 seconds and 4 git commands to generate.