mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-17 19:03:42 +01:00
contrib/plugins: cowsay
___________________________________________________________________________ / The most important plugin. Ever. Much thanks to @practicalswift and @jb55 \ \ for their improvements! / --------------------------------------------------------------------------- \ ^__^ \ (oo)\_______ (__)\ )\/\ ||----w | || || Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
0ec8304901
commit
c2f58aec9d
37
contrib/plugins/cowsay.sh
Executable file
37
contrib/plugins/cowsay.sh
Executable file
@ -0,0 +1,37 @@
|
||||
#! /bin/sh
|
||||
|
||||
maybe_cowsay()
|
||||
{
|
||||
cowsay || cat <<EOF
|
||||
_________________________________
|
||||
< Please install 'cowsay' program >
|
||||
---------------------------------
|
||||
\\ ^__^
|
||||
\\ (xx)\\_______
|
||||
(__)\\ )\\/\\
|
||||
U ||----w |
|
||||
|| ||
|
||||
EOF
|
||||
}
|
||||
|
||||
# Eg. {"jsonrpc":"2.0","id":2,"method":"getmanifest","params":{}}\n\n
|
||||
read -r JSON
|
||||
read -r _
|
||||
id=$(echo "$JSON" | sed 's/.*"id" *: *\([0-9]*\),.*/\1/')
|
||||
|
||||
echo '{"jsonrpc":"2.0","id":'"$id"',"result":{"dynamic":true,"options":[],"rpcmethods":[{"name":"cowsay","usage":"<string>","description":"Have a cow, man!"}]}}'
|
||||
|
||||
# Eg. {"jsonrpc":"2.0","id":5,"method":"init","params":{"options":{},"configuration":{"lightning-dir":"/home/rusty/.lightning","rpc-file":"lightning-rpc","startup":false}}}\n\n
|
||||
read -r JSON
|
||||
read -r _
|
||||
|
||||
# eg. { "jsonrpc" : "2.0", "method" : "cowsay", "id" : 6, "params" :[ "hello"] }
|
||||
while read -r JSON; do
|
||||
read -r _
|
||||
id=$(echo "$JSON" | sed 's/.*"id" *: *\([0-9]*\),.*/\1/')
|
||||
params=$(echo "$JSON" | sed 's/.*"params" *: *//' | tr -d '[{}]"')
|
||||
echo '{"jsonrpc":"2.0","id":'"$id"',"result":{"format-hint":"simple","cowsay":"'
|
||||
# FIXME: lightning-cli does not unescape \\, so we replace with an L.
|
||||
printf "%s" "$params" | maybe_cowsay | sed 's/\\/L/g' | sed ':a;N;$!ba;s/\n/\\n/g' | tr '\012' '"'
|
||||
echo '}}'
|
||||
done
|
Loading…
Reference in New Issue
Block a user