summaryrefslogtreecommitdiffstats
path: root/konversation/scripts/tinyurl
blob: 14efde9e46765317ba0fe2ab7d7c155585a0a5bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env bash
#
# Creates a TinyURL from a long URL
# Licensed under GPL v2 or later at your option
# Copyright 2007 Terence Simpson

PORT=$1
SERVER=$2
TARGET=$3
export URL="$4"
NICK="$5"

if test ! -z $URL; then
  if test $(which curl); then
    TINYURL="$(curl -s -i http://tinyurl.com/create.php?url=$URL|grep "The following URL" -A3|tail -1|awk -F\> '{print $3}'|sed 's,</b,,')"
  else
    TINYURL="$(wget -T10 -t2 -qO- http://tinyurl.com/create.php?url=$URL|grep "The following URL" -A3|tail -1|awk -F\> '{print $3}'|sed 's,</b,,')"
  fi
else dcop $PORT default error "No url given: usage is \"/tinyurl URL [NickName]\""
    exit 1
fi

if test -z $TINYURL; then
    dcop $PORT default error "Unable run tinyurl script, please make sure you have curl or wget installed"
else
    if test ! -z $NICK; then
        dcop $PORT default say $SERVER "$TARGET" "${NICK}: $TINYURL"
    else
        dcop $PORT default say $SERVER "$TARGET" "$TINYURL"
    fi
fi