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