comparison mcabber/contrib/events/eventcmd.pastebin @ 1516:581d7bc8a404

Add pastebin/tiny-er event script (Alexander Clouter/Jamie Lentin) Patch sent by Alexander Clouter.
author Mikael Berthe <mikael@lilotux.net>
date Sat, 27 Sep 2008 21:14:17 +0200
parents
children 6df03b9b17ba
comparison
equal deleted inserted replaced
1515:9013d23f0a86 1516:581d7bc8a404
1 #!/bin/sh
2 #
3 # event_command url handling script for mcabber
4 # by
5 # * Alexander Clouter <alex@digriz.org.uk>
6 # * Jamie Lentin <jamie@lentin.co.uk>
7 #
8 # For tinyurl'ing (sending tinyurl's of URL's sent to you
9 # resent as a headline to yourself) you set your *own*
10 # jabber id for 'me' and it's probably best leaving
11 # 'tinyurltrigger' unless you know what you are doing.
12 #
13 # For pastebin support (dumping the URL as an HTML anchor
14 # into a local file that could be exported by a webserver
15 # or as a file a web-browser can open) tinker with the
16 # pastebin lines.
17 #
18 # If you want to disable a one of the facilities, just
19 # comment out the pair of variables you do not want.
20 #
21 #set -x
22
23 ## configuration
24 # tinyurl'ifier
25 me=jim@jabber.li
26 tinyurltrigger=24
27 # pastebin support
28 pastebin_file=~/bitbucket/stuff/pastebin.html
29 pastebin_line_count=10
30
31 # Don't do 'owt unless recieving a message
32 [ x$1 != xMSG ] && exit 0
33 [ x$2 != xIN ] && exit 0
34
35 jid=$3
36 # do nothing if it's from self
37 [ "$jid" == "$me" ] && exit 0
38
39 # If receiving a message, scan for links
40 url=$(cat "$4" | awk 'BEGIN { RS="( |\n|\t)+"; FS="¬"; } /http:\/\// { print $1 }')
41
42 if [ -n "$url" ]; then
43 date=$(/bin/date)
44
45 if [ -n "$me" -a ${#url} -ge $tinyurltrigger ]; then
46 tinyurl=`wget -q -O - http://tinyurl.com/api-create.php?url="$url"`
47
48 echo "say_to -q -h $me <= $jid $url" > ~/.mcabber/mcabber.fifo
49 echo "say_to -q -h $me $tinyurl" > ~/.mcabber/mcabber.fifo
50 fi
51 if [ -n "$pastebin_file" ]; then
52 if [ ! -f "$pastebin_file" ]; then
53 touch "$pastebin_file"
54 fi
55
56 sed -i -e :a -e '$q;N;11,$D;ba' "$pastebin_file"
57 printf '%s (%s): <a href="%s">%s</a><br/>\n' "$date" "$jid" "$url" "$url" >> $pastebin_file
58 fi
59 fi
60
61 [ -n "$4" ] && rm "$4"
62
63 exit 0