2020-03-13 17:52:08 +01:00
#!/bin/bash
################################################################################
# Authors:
# [@cel](@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519)
# [@Fred](@9BbJwPDjcyIqrOUPNn0nJZBduWdIrpMk3Cjz5MP361s=.ed25519)
2020-03-14 01:50:28 +01:00
# [@Boris](@l5nYExWYIgDLV6BYHOJPoI97jIUyTdSm8CTLpQ0XeOg=.ed25519)
2020-03-13 17:52:08 +01:00
# Version: 1.0
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
###########################################################################################
# ADD G1 Layer 10 LOVE to message writer you like !
# PREVENT DOUBLE PAYEMENT
############################################################################################
2020-03-14 01:50:28 +01:00
2020-03-13 17:52:08 +01:00
fn_exists( ) {
# appended double quote is an ugly trick to make sure we do get a string -- if $1 is not a known command, type does not output anything
[ ` type -t $1 ` "" = = 'file' ]
}
# Let's get G1 public and private keys
g1pub = $( cat ~/.ssb/secret.dunikey | grep "pub" | cut -d ' ' -f 2)
g1priv = $( cat ~/.ssb/secret.dunikey | grep "sec" | cut -d ' ' -f 2)
# SSB pubkey
ssbpub = $( cat ~/.ssb/secret | grep public\" | cut -d ' ' -f 4 | cut -d '.' -f 1 | sed s/\" //g)
############################################################################################
#### CHECK LIKE AND SEND LOVE
# Let's get G1 account balance
echo ""
echo "Welcome to the G1 SSB "
echo "
MMMMMMMMMMMMMNk; ' cdxxd:,c0WMMMMMMMMMMMMM
MMMMMMMMMMMMMNx,. .; kWMMMMMMMMMMMMM
MMMMMMMMMMMMMMMNOdlccld0NMMMMMMMMMMMMMMM
MMMMMMMMMMMWXko:,'....' ,:okXWMMMMMMMMMMM
MMMMMMMMMNk:. .cOWMMMMMMMMM
MMMMMMMW0: .c0MMMMMMMM
MMMMMMWk. 'lxkOOkdc' .cOWMMMMMMM
MMMMMMO' ' kNMMMMMMMMNxcoOXWMMMMMMMMM
MMMMMNl ' 0MMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMX; cNMMMMMMMNOkkkkkkkkkkONMMMMM
MMMMMNc ; XMMMMMMMNd' .OMMMMM
MMMMMWx. cKMMMMMMMWKc. .OMMMMM
MMMMMMNo. .lkKXNNXKkc. .OMMMMM
MMMMMMMNd. ...... .OMMMMM
MMMMMMMMWKl. ' c:. .OMMMMM
MMMMMMMMMMWXkc,.. ..,lkXWWO:; OMMMMM
MMMMMMMMMMMMMMWX0OxddxO0XWMMMMMMWXNMMMMM
MMMMMMMMMMMMMMMMNx; '' ,dNMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMK, ' 0MMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMNd. .oNMMMMMMMMMMMMMMMM
"
sleep 1
echo ""
echo "You know your SSB pubkey:"
echo $ssbpub
sleep 1
echo ""
echo "...but did you know it is also a valid G1 wallet?"
echo $g1pub
sleep 2
echo ""
echo "Let's check the current balance of your wallet!"
sleep 2
echo ""
echo "We are interrogating the G1 blockchain to check if anyone has already sent G1..."
sleep 1
echo ""
echo "A moment please..."
echo ""
sleep 1
duniter_server = "duniter-g1.p2p.legal:443"
echo " Testing server $duniter_server ... "
echo ""
silkaj -p " $duniter_server " balance $g1pub 2>/dev/null
if [ $? -eq 1 ]
then
duniter_server = "g1.duniter.org:443"
echo " Testing server $duniter_server ... "
echo ""
silkaj -p " $duniter_server " balance $g1pub 2>/dev/null
if [ $? -eq 1 ]
then
echo "The server did not respond well. Please try again."
exit 1
fi
fi
echo "Have any money? Then let's send G1love. Press ENTER to continue. " && read
###########################################################################################
self = $( sbotc whoami | jq -r .id) || exit 1
ssb_dir = ~/.${ ssb_appname :- ssb }
id_part = $( echo " $self " | sed 's/\//_/g' | tail -c +2 | head -c 9)
state_file = $ssb_dir /likes-g1-$id_part .ts
if [ -s " $state_file " ]
then last_ts = $( cat " $state_file " ) || exit 1
else
last_ts = $( date -u +%s%N | cut -b1-13)
last_ts = $(( last_ts - 3600000 )) # timestamp from 1h ago
#else last_ts=null
fi
process_msg( ) {
msg = $1
target_id = $( printf %s " $msg " | jq -r '.value?.content?.vote?.link' ) || return 1
target_msg = $( sbotc -e get " $target_id " ) || return 1
target_author = $( printf %s " $target_msg " | jq -r .author) || return 1
root_id = $( printf %s " $target_msg " | jq -r .content?.root) || return 1
[ [ $root_id = = "null" ] ] && root_id = $target_id
g1_author = $( echo $target_author | cut -d '.' -f 1 | cut -d '@' -f2 | base64 -d | base58)
}
sbotc query.read '{"query":[{"$filter":{"value":{"author":"' " $self " '","content":{"type":"vote", "vote":{"expression":"Like"}},"timestamp":{"$gt":' " $last_ts " '}}}}]}' | while read -r msg
do
if ! ts = $( printf %s " $msg " | jq -r .value.timestamp)
then
printf 'Unable to get message timestamp\n' >& 2
exit 1
fi
if ! echo " $ts " > " $state_file " ~
then
printf 'Unable to write to backup state file.\n' >& 2
exit 1
fi
if ! process_msg " $msg "
then
msg_id = $( printf %s " $msg " | jq -r .key)
printf 'Unable to process message %s\n' " $msg_id " >& 2
exit 1
fi
printf 'Message: %s ( Author: %s )\n' " $target_id " " $target_author "
if [ [ $g1_author != $g1pub ] ] ; then
sleep 3
#printf '%s\n' "silkaj -af --file ~/.ssb/secret.dunikey tx --output $g1_author --amountUD 0.1 --comment _SSB:LIKE:$target_id"
2020-03-14 01:50:28 +01:00
silkaj -p " $duniter_server " -af --file ~/.ssb/secret.dunikey tx --output $g1_author --amountUD 0.1 --comment " _SSB:LIKE: $target_id " -y 2>/dev/null
2020-03-13 17:52:08 +01:00
#thank_you_msg="Hi there! I liked your post and thus sent you Ğ1 #libremoney. We don\'t really know how you may be able to use it but, hey, that is still money, right? Cheers!"
2020-03-14 01:50:28 +01:00
sbotc publish '{"type":"post","text":"Thanks for this post ; I have just sent you G1 libre money. Claim it at [https://git.p2p.legal/Axiom-Team/ssb-g1like](https://git.p2p.legal/Axiom-Team/ssb-g1like) ", "branch": "' " $target_id " '", "root": "' " $root_id " '"}' 2>& 1>/dev/null
2020-03-13 17:52:08 +01:00
2020-03-14 01:50:28 +01:00
sleep 60 # DO NOT OVER CHARGE DUNITER
2020-03-13 17:52:08 +01:00
else
echo " I LIKE MY MESSAGE $target_id "
fi
if ! mv " $state_file " ~ " $state_file "
then
msg_id = $( printf %s " $msg " | jq -r .key)
printf 'Unable to write to state file. Update state file manually to prevent %s from being processed twice.\n' " $msg_id " >& 2
exit 1
fi
done