X-Git-Url: https://git.harvie.cz/?a=blobdiff_plain;f=purple%2Fanswerscripts.sh;h=3b72f961a438905d4ff97246aae90e2777e110b8;hb=586c555829ec40f5d123206fca93adf811bb2a26;hp=032d6fc27243a183b10a60d70b6b5346ce7f7506;hpb=4c3335b4ed3c610750eb0b0886a44743ced2b78c;p=mirrors%2Flibpurple-core-answerscripts.git diff --git a/purple/answerscripts.sh b/purple/answerscripts.sh index 032d6fc..3b72f96 100755 --- a/purple/answerscripts.sh +++ b/purple/answerscripts.sh @@ -1,35 +1,49 @@ -#!/bin/sh - +#!/bin/bash +# # This file is called for every message received by libpurple clients (pidgin,finch,...) - # Env variables PURPLE_MSG and PURPLE_FROM are passed to this script - # Which means you should mind security (don't let attackers to execute their messages) - # Each line of output is sent as reply to that message - # You can try to rewrite this script in PERL or C for better performance - # This script have .exe suffix as i hope it can be eventualy replaced by some binary on windows +# - You can try to rewrite this script in PERL or C for better performance (or different platform) - let me know +# - On M$ Windows answerscripts.exe from libpurple directory will be called instead of this script +# +# Maybe you will want to add more hooks for receiving messages, so i've made following script +# - It just executes all +x files in answerscripts.d directory so you should do your magic there +# - To disable some of those scripts simply use: chmod -x ./script +# - There is some basic structure, which means that all scripts should start their names with two-digit number +# - Files are executed in order specified by those numbers and some numbers have special meanings: +# - AB?!_ scripts without numbers are NOT executed! +# - 00 executed immediately, zero or single line output (parallel async processing) +# - 01-48 executed immediately, multiline output (serial processing) +# - 49 delay script (adds random delay to emulate human factor, no user scripts at this level!) +# - 50 executed after delay, zero or single line output (parallel async processing) +# - 51-79 executed after delay, multiline output (serial processing) +# - 80-99 reserved for future -# Basic example can look like this: - # echo "<$PURPLE_FROM> $PURPLE_MSG"; +#this may be modified to use run-parts from coreutils in future (can't get it to work): -# There are lot of hacks that you can do with this simple framework if you know some scripting. eg.: - # Forward your instant messages to email, SMS gateway, text-to-speach (eg. espeak) or something... - # Smart auto-replying messages based on regular expressions - # Remote control your music player (or anything else on your computer) using instant messages - # Simple IRC/Jabber/ICQ bot (accepts PM only) - # Providing some service (Searching web, Weather info, System status, RPG game...) - # BackDoor (even unintentional one - you've been warned) - # Loging and analyzing messages - # Connect IM with Arduino - # Annoy everyone with spam (and probably get banned everywhere) - # Anything else that you can imagine... +dir="$(dirname "$0")"; cd "$dir" #chdir to ~/.purple/ or similar +dir="${dir}/answerscripts.d" +if test -d "$dir"; then + for i in {00..99}; do -# Maybe you will want to add more hooks for receiving messages, so i've made following script - # It just executes all +x files in answerscripts.d directory so you should do your magic there - # To disable some of those scripts just use chmod -x script + #sleep at 49 (this can be replaced by 49-delay.sh, but this should be faster) + [ $i -eq 49 ] && { + find "$dir"/[5-9][0-9]-* -executable | grep . >/dev/null && #check if it's worth waiting + sleep $(( 2 + ($RANDOM % 8) )); #2-9 seconds of sleep + continue; + } -dir="$(dirname "$0")"/answerscripts.d -if test -d "$dir"; then - for script in "$dir"/*; do - test -x "$script" && "$script" - done -fi + #execute scripts + ls -1 "$dir/$i"* 2>/dev/null | while read script; do + test -x "$script" && { + #determine wheter execute on background or foreground + if [ $i -eq 00 ] || [ $i -eq 50 ]; then + "$script" & + else + "$script" + fi; + } + done; + wait; #wait for processes on background + + done; +fi