Created
March 18, 2014 01:23
-
-
Save inertia186/9611852 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| ## Just a link, without the [Server] prepend. This is used by link-triggers.sh. | |
| MC="/path/to/server" | |
| WGET="/opt/local/bin/wget" | |
| W3M="/opt/local/bin/w3m" | |
| function urldecode { | |
| echo -e "$(sed 's/+/ /g;s/%\(..\)/\\x/g;')" | |
| } | |
| if [ -z "$1" ]; then | |
| echo $0 \<player\> \<link\> | |
| echo length: | |
| echo "============================================================================================================" | |
| exit | |
| fi | |
| player="$1" | |
| link="$2" | |
| if echo "$link" | grep -qi "^\.png\$"; then | |
| sleep 0 # noop | |
| elif echo "$link" | grep -qi "^\.jpg\$"; then | |
| sleep 0 # noop | |
| elif echo "$link" | grep -qi "^\.gif\$"; then | |
| sleep 0 # noop | |
| elif echo "$link" | grep -qi "is.gd"; then | |
| sleep 0 # noop | |
| else | |
| dump=`$WGET -T 2 -q "$link" -O -` | |
| title=`echo "$dump" | grep "<title>" -A4` | |
| title=`echo $title | cut -f 2 -d ">" | cut -f 1 -d "<"` | |
| #TODO The quick parse didn't work, so let's be a bit more creative. | |
| fi | |
| if [ -n "$title" ]; then | |
| title=`echo $title | $W3M -dump -T text/html` | |
| title=${title//[\"]/} | |
| title="$link :: $title" | |
| else | |
| title="$link" | |
| fi | |
| $MC/scripts/rcon.sh tellraw $player "{\"text\":\"\",\"extra\":[{\"text\":\"$title\",\"color\":\"dark_purple\",\"underlined\":\"true\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"$link\"}}]}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment