2020-03-13 17:52:08 +01:00
#!/bin/bash
################################################################################
2020-03-20 17:17:58 +01:00
#
2020-03-13 17:52:08 +01:00
# Authors:
2020-03-20 17:17:58 +01:00
#
2020-03-13 17:52:08 +01:00
# [@cel](@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519)
# [@Fred](@9BbJwPDjcyIqrOUPNn0nJZBduWdIrpMk3Cjz5MP361s=.ed25519)
2020-03-14 01:50:28 +01:00
# [@Boris](@l5nYExWYIgDLV6BYHOJPoI97jIUyTdSm8CTLpQ0XeOg=.ed25519)
2020-03-20 17:17:58 +01:00
# [@poka](@vDQif9KU3T78XJx+NliK+wdo1vmehHZCWqD+3X700Uk=.ed25519)
# @[chamalow](@qio8/4L4vnzq3qRD0dqKI7sTpey54u8ZWbaICfpJOZw=.ed25519)
#
2020-03-13 17:52:08 +01:00
# Version: 1.0
2020-03-20 17:17:58 +01:00
#
2020-03-13 17:52:08 +01:00
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
2020-03-20 17:17:58 +01:00
#
2020-03-13 17:52:08 +01:00
###########################################################################################
# PREVENT DOUBLE PAYEMENT
2020-03-18 20:41:11 +01:00
# ADD Ğ1 Layer 10 LOVE to message writer you like !
2020-03-13 17:52:08 +01:00
############################################################################################
2020-03-20 17:03:27 +01:00
# Customizable
# debugMsgMode, when set to 1 does doesn't send transaction and does not update "last timestamp"
debugMsgMode = 0
# If you don't want to wait
readable = 1
minimumAmountPerLikeInUD = "0.1"
############################################################################################
2020-03-18 20:41:11 +01:00
# Let's get Ğ1 public and private keys
2020-03-13 17:52:08 +01:00
g1pub = $( cat ~/.ssb/secret.dunikey | grep "pub" | cut -d ' ' -f 2)
g1priv = $( cat ~/.ssb/secret.dunikey | grep "sec" | cut -d ' ' -f 2)
2020-03-20 17:03:27 +01:00
2020-03-13 17:52:08 +01:00
# SSB pubkey
ssbpub = $( cat ~/.ssb/secret | grep public\" | cut -d ' ' -f 4 | cut -d '.' -f 1 | sed s/\" //g)
2020-03-19 16:04:23 +01:00
defaultAmountPerLikeInUD = "0.1"
2020-03-18 20:41:11 +01:00
bold = $( tput bold)
normal = $( tput sgr0)
2020-03-19 00:56:23 +01:00
ssbMaxSize = 8192
2020-03-20 17:03:27 +01:00
baseSizeOfAMessageFile = $( wc -c samples/message.json | awk '{print $1}' )
sizeOfATagMention = $( wc -c samples/tag_mention.json | awk '{print $1}' )
sizeOfAUserMention = $( wc -c samples/user_mention.json | awk '{print $1}' )
sizeOfAPostMention = $( wc -c samples/post_mention.json | awk '{print $1}' )
2020-03-13 17:52:08 +01:00
############################################################################################
#### CHECK LIKE AND SEND LOVE
2020-03-18 20:41:11 +01:00
# Let's get Ğ1 account balance
2020-03-13 17:52:08 +01:00
echo ""
2020-03-18 20:41:11 +01:00
echo -e " ${ bold } Welcome ${ normal } to the Ğ1/SSB-like microdonation system!\n "
2020-03-20 17:03:27 +01:00
if [ [ $readable -eq 1 ] ] ; then sleep 1; fi
2020-03-18 20:41:11 +01:00
echo " MMMMMMMMMMMMMNk;'cdxxd:,c0WMMMMMMMMMMMMM
2020-03-13 17:52:08 +01:00
MMMMMMMMMMMMMNx,. .; kWMMMMMMMMMMMMM
MMMMMMMMMMMMMMMNOdlccld0NMMMMMMMMMMMMMMM
MMMMMMMMMMMWXko:,'....' ,:okXWMMMMMMMMMMM
MMMMMMMMMNk:. .cOWMMMMMMMMM
2020-03-18 20:41:11 +01:00
MMMMMMMW0: .c0MMMMMMMM"
2020-03-20 17:03:27 +01:00
if [ [ $readable -eq 1 ] ] ; then sleep 1; fi
2020-03-18 20:41:11 +01:00
echo " MMMMMMWk. 'lxkOOkdc' .cOWMMMMMMM
2020-03-13 17:52:08 +01:00
MMMMMMO' ' kNMMMMMMMMNxcoOXWMMMMMMMMM
MMMMMNl ' 0MMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMX; cNMMMMMMMNOkkkkkkkkkkONMMMMM
MMMMMNc ; XMMMMMMMNd' .OMMMMM
MMMMMWx. cKMMMMMMMWKc. .OMMMMM
2020-03-18 20:41:11 +01:00
MMMMMMNo. .lkKXNNXKkc. .OMMMMM"
2020-03-20 17:03:27 +01:00
if [ [ $readable -eq 1 ] ] ; then sleep 1; fi
2020-03-18 20:41:11 +01:00
echo " MMMMMMMNd. ...... .OMMMMM
2020-03-13 17:52:08 +01:00
MMMMMMMMWKl. ' c:. .OMMMMM
MMMMMMMMMMWXkc,.. ..,lkXWWO:; OMMMMM
MMMMMMMMMMMMMMWX0OxddxO0XWMMMMMMWXNMMMMM
MMMMMMMMMMMMMMMMNx; '' ,dNMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMK, ' 0MMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMNd. .oNMMMMMMMMMMMMMMMM
"
2020-03-20 17:03:27 +01:00
if [ [ $readable -eq 1 ] ] ; then sleep 1; fi
2020-03-18 20:41:11 +01:00
printf "You know your SSB pubkey:\n%s\n\n" $ssbpub
2020-03-20 17:03:27 +01:00
if [ [ $readable -eq 1 ] ] ; then sleep 2; fi
2020-03-18 20:41:11 +01:00
printf "...but did you know it is also a valid Ğ1 wallet?\n%s\n\n" $g1pub
2020-03-20 17:03:27 +01:00
if [ [ $readable -eq 1 ] ] ; then sleep 2; fi
2020-03-18 20:41:11 +01:00
printf "Let's check the current balance of your wallet!\n\n"
2020-03-20 17:03:27 +01:00
if [ [ $readable -eq 1 ] ] ; then sleep 1; fi
2020-03-19 00:56:23 +01:00
printf "I am interrogating the Ğ1 blockchain to check if anyone has already sent you Ğ1...\n\n"
2020-03-20 17:03:27 +01:00
if [ [ $readable -eq 1 ] ] ; then sleep 2; fi
2020-03-18 20:41:11 +01:00
printf "A moment please...\n\n"
2020-03-20 17:03:27 +01:00
if [ [ $readable -eq 1 ] ] ; then sleep 1; fi
2020-03-13 17:52:08 +01:00
2020-03-18 20:41:11 +01:00
silkajRelativeAmountPattern = 'Total\sRelative\s+=\s+(.*)\s+UD'
2020-03-19 00:56:23 +01:00
duniter_servers[ 0] = "duniter-g1.p2p.legal:443"
duniter_servers[ 1] = "g1.duniter.org:443"
duniter_servers[ 2] = "g1.presles.fr:443"
duniter_servers[ 3] = "balboa.altsysnet.com:10900"
duniter_servers[ 4] = "remuniter.cgeek.fr:16120"
duniter_servers[ 5] = "duniter.moul.re:443"
duniter_servers[ 6] = "77.152.31.154:20901"
duniter_servers[ 7] = "duniter.g1.1000i100.fr:443"
silkajExitCode = 1
i = 0
while [ $silkajExitCode -ne 0 ] && [ $i -lt ${# duniter_servers [@] } ]
do
echo " Testing server ${ duniter_servers [ $i ] } ... "
2020-03-13 17:52:08 +01:00
echo ""
2020-03-19 00:56:23 +01:00
silkajOutput = $( silkaj -p " ${ duniter_servers [ $i ] } " balance $g1pub 2>/dev/null)
silkajExitCode = $?
( ( i++) )
done
2020-03-13 17:52:08 +01:00
2020-03-19 00:56:23 +01:00
if [ $silkajExitCode -eq 1 ]
then
echo "The server did not respond well. Please try again."
exit 1
2020-03-13 17:52:08 +01:00
fi
2020-03-18 20:41:11 +01:00
if [ [ $silkajOutput = ~ $silkajRelativeAmountPattern ] ]
then
balance = " ${ BASH_REMATCH [1] } "
else
echo "Account balance wasn't found."
exit 1
fi
printf " You have ${ bold } %s UDĞ1 ${ normal } on your Duniter Ğ1 wallet.\n\n " " $balance "
2020-03-20 17:03:27 +01:00
if [ [ $readable -eq 1 ] ] ; then sleep 2; fi
2020-03-18 20:41:11 +01:00
printf "Want to show your appreciation of your fellow butts' posts while helping spreading awareness about libre currencies?\n\n"
2020-03-20 17:03:27 +01:00
if [ [ $readable -eq 1 ] ] ; then sleep 3; fi
2020-03-18 20:41:11 +01:00
# BEGIN timestamp computation
2020-03-13 17:52:08 +01:00
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
2020-03-18 20:41:11 +01:00
current_ts = $( date -u +%s%N | cut -b1-13)
2020-03-13 17:52:08 +01:00
if [ -s " $state_file " ]
2020-03-18 20:41:11 +01:00
then
last_ts = $( cat " $state_file " ) || exit 1
2020-03-13 17:52:08 +01:00
else
2020-03-20 17:03:27 +01:00
# timestamp from 24h ago
2020-03-20 23:16:09 +01:00
last_ts = $(( current_ts - 24 * 3600 * 1000 - 1 ))
2020-03-13 17:52:08 +01:00
#else last_ts=null
fi
2020-03-18 20:41:11 +01:00
days_from_last_tx = $(( ( current_ts - last_ts) / ( 24 * 60 * 60 * 1000 ) ))
# END timestamp computation
printf "First, let's see how much ❤ you gave lately...\n\n"
2020-03-20 17:03:27 +01:00
if [ [ $readable -eq 1 ] ] ; then sleep 1; fi
2020-03-18 20:41:11 +01:00
declare -A likesNbPerAuthor
declare -A likedPosts
declare -A likesNbPerPost
declare -A postsTimestamps
declare -A excerpts
totalLikesGiven = 0
2020-03-13 17:52:08 +01:00
process_msg( ) {
2020-03-18 20:41:11 +01:00
2020-03-13 17:52:08 +01:00
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
2020-03-18 20:41:11 +01:00
msg_content = $( printf %s " $target_msg " | jq -r .content?.text) || return 1
# beware of markdown !
msg_excerpt = ${ msg_content : 0 : 10 }
#root_id=$(printf %s "$target_msg" | jq -r .content?.root) || return 1
#[[ $root_id = "null" ]] && root_id=$target_id
2020-03-13 17:52:08 +01:00
}
2020-03-15 01:36:51 +01:00
2020-03-18 20:41:11 +01:00
process_author( ) {
author_id = $1
g1_author = $( echo $author_id | cut -d '.' -f 1 | cut -d '@' -f2 | base64 -d | base58)
author_name = $( sbotc query.read '{"query":[{"$filter":{"value":{"author": "' " $author_id " '", "content":{"type":"about", "about": "' " $author_id " '"}}}}]}' | jq .value?.content?.name | grep -v null | tail -n 1)
2020-03-20 17:03:27 +01:00
author_name = ${ author_name : 1 :- 1 }
2020-03-18 20:41:11 +01:00
}
authorsNb = 0
i = 0
messages = $( sbotc query.read '{"query":[{"$filter":{"value":{"author":"' " $self " '","content":{"type":"vote", "vote":{"expression":"Like"}},"timestamp":{"$gt":' " $last_ts " '}}}}]}' )
while read -r msg
2020-03-13 17:52:08 +01:00
do
2020-03-18 20:41:11 +01:00
2020-03-16 01:15:07 +01:00
priv = $( printf %s " $msg " | jq .value.content.private)
2020-03-18 20:41:11 +01:00
if [ [ $priv = true ] ]
2020-03-16 01:15:07 +01:00
then
printf " Private message $priv , continue to next one\n " >& 2
continue
fi
2020-03-13 17:52:08 +01:00
if ! process_msg " $msg "
then
msg_id = $( printf %s " $msg " | jq -r .key)
2020-03-18 20:41:11 +01:00
printf '\nUnable to process message %s\n' " $msg_id " >& 2
2020-03-13 17:52:08 +01:00
exit 1
fi
2020-03-15 01:36:51 +01:00
2020-03-18 20:41:11 +01:00
if [ [ $g1_author = $g1pub ] ] ; then
2020-03-15 01:36:51 +01:00
2020-03-18 20:41:11 +01:00
echo " I LIKE MY MESSAGE $target_id "
else
( ( totalLikesGiven++) )
2020-03-15 04:21:45 +01:00
2020-03-18 20:41:11 +01:00
if [ [ ${ likesNbPerAuthor [ $target_author ] } -eq 0 ] ]
then
likesNbPerAuthor[ $target_author ] = 1
likedPosts[ $target_author ] = ""
else
likesNbPerAuthor[ $target_author ] = $(( ${ likesNbPerAuthor [ $target_author ] } + 1 ))
2020-03-15 04:21:45 +01:00
fi
2020-03-18 20:41:11 +01:00
if [ [ ${ likesNbPerPost [ $target_id ] } -eq 0 ] ]
then
likesNbPerPost[ $target_id ] = 1
likedPosts[ $target_author ] += $target_id
likedPosts[ $target_author ] += "\n"
else
( ( likesNbPerPost[ $target_id ] ++) )
2020-03-15 04:21:45 +01:00
fi
2020-03-15 01:36:51 +01:00
2020-03-18 20:41:11 +01:00
excerpts[ $target_id ] = $msg_excerpt
2020-03-20 17:03:27 +01:00
# We cannot use this anymore
# (now saving current_ts once all tx have been sent)
#
# if ! postsTimestamps[$target_id]=$(printf %s "$msg" | jq -r .value.timestamp)
#then
# printf 'Unable to get message timestamp\n' >&2
# exit 1
#fi
2020-03-18 20:41:11 +01:00
( ( i++) )
2020-03-13 17:52:08 +01:00
fi
2020-03-18 20:41:11 +01:00
done < <( printf '%s\n' " $messages " )
if [ [ $totalLikesGiven -eq 0 ] ]
then
printf "You did not give any like during the past %s days or they have already been processed.\n\n" " $days_from_last_tx "
printf "Try again in a few days.\n\n"
fi
printf " You gave ${ bold } %s❤ ${ normal } during the past %s days.\n\n " " $totalLikesGiven " " $days_from_last_tx "
2020-03-20 17:03:27 +01:00
if [ [ $readable -eq 1 ] ] ; then sleep 2; fi
2020-03-18 20:41:11 +01:00
2020-03-19 00:56:23 +01:00
tx_are_possible = 0
2020-03-18 20:41:11 +01:00
2020-03-19 00:56:23 +01:00
while [ [ $tx_are_possible -eq 0 ] ]
do
2020-03-19 10:55:02 +01:00
2020-03-20 17:03:27 +01:00
printf " How many UDĞ1 do you want to send per each like you gave? (minimum is ${ bold } %s UDĞ1 ${ normal } ) " " $minimumAmountPerLikeInUD "
2020-03-19 10:55:02 +01:00
read a
printf "\n"
if [ [ -z $a ] ]
then
2020-03-20 17:03:27 +01:00
amountPerLikeInUD = $minimumAmountPerLikeInUD
2020-03-19 10:55:02 +01:00
else
amountPerLikeInUD = $a
fi
2020-03-19 00:56:23 +01:00
amountGiven = $( echo " $totalLikesGiven * $amountPerLikeInUD " | bc -l)
2020-03-19 10:55:02 +01:00
2020-03-20 17:03:27 +01:00
has_enough_money = $(( $( echo " $amountGiven <= $balance " | bc -l) ))
amountPerLike_is_enough = $(( $( echo " $amountPerLikeInUD >= $minimumAmountPerLikeInUD " | bc -l) ))
tx_are_possible = $(( $has_enough_money & & $amountPerLike_is_enough ))
if [ [ $readable -eq 1 ] ] ; then sleep 1; fi
if [ [ $tx_are_possible -eq 0 ] ] ; then
if [ [ $has_enough_money -eq 0 ] ] ; then
printf "You don't have enough UDĞ1 to send all transactions.\n\n"
if [ [ $readable -eq 1 ] ] ; then sleep 1; fi
printf " ${ bold } %s UDĞ1 ${ normal } are needed.\n\n " " $amountGiven "
if [ [ $readable -eq 1 ] ] ; then sleep 1; fi
elif [ [ $amountPerLike_is_enough -eq 0 ] ] ; then
printf "Minimum amount per like is %s UDĞ1.\n\n" $minimumAmountPerLikeInUD
if [ [ $readable -eq 1 ] ] ; then sleep 1; fi
fi
printf "Try again with a different amount per like.\n\n"
maxAmountPerLike = $( awk -vp= $balance -vq= $totalLikesGiven 'BEGIN{printf "%.2f" ,p / q}' )
if [ [ $readable -eq 1 ] ] ; then sleep 1; fi
printf " Maximum amount per like possible: ${ bold } %s UDĞ1 ${ normal } \n\n " " $maxAmountPerLike "
if [ [ $readable -eq 1 ] ] ; then sleep 1; fi
else
2020-03-19 00:56:23 +01:00
newBalance = $( echo " $balance - $amountGiven " | bc -l)
printf " ${ bold } %s UDĞ1 ${ normal } will be given.\n\n " " $amountGiven "
2020-03-20 17:03:27 +01:00
if [ [ $readable -eq 1 ] ] ; then sleep 1; fi
2020-03-19 00:56:23 +01:00
printf " After sending transactions, your new balance will be ${ bold } %s UDĞ1 ${ normal } \n\n " " $newBalance "
2020-03-20 17:03:27 +01:00
if [ [ $readable -eq 1 ] ] ; then sleep 1; fi
2020-03-19 00:56:23 +01:00
printf "Press ENTER to continue: " && read
printf "\n"
fi
done
2020-03-18 20:41:11 +01:00
2020-03-20 17:03:27 +01:00
# Let's construct thank you posts (tyPosts) and send transactions!
tyPostIndex = 0
tyPosts[ 0] = ""
tyPosts[ 0] += "# I tipped you for your posts!\n\n"
tyPosts[ 0] += $( printf "Huge thanks to the ScuttleButt community for all the fascinating posts you allowed me to read in the past %s days." " $days_from_last_tx " )
tyPosts[ 0] += "\n\nAs a means to thank you further, I have just sent you #Ğ1 libre money.\n\n"
tyPosts[ 0] += "These messages, though they might feel spammy (sorry) are also a way for the Ğ1 community to spread awareness about [libre currencies](https://libre-currency.org/) so we can build #resilience at every level.\n\n"
2020-03-20 17:17:58 +01:00
tyPosts[ 0] += "You can learn how to spend your freshly earned money at [https://git.p2p.legal/Axiom-Team/ssb-g1-tip](https://git.p2p.legal/Axiom-Team/ssb-g1-tip)\n\n"
2020-03-20 17:03:27 +01:00
tyPosts[ 0] += "Below is the list of SSB users whose content I liked recently, and the amount each one was given:\n\n"
tableHeaders = '| thanks to | for their posts | tip |\n'
tableHeaders += '| --- | --- | ---- |\n'
sizeOfTableHeaders = $( printf "%s" " $tableHeaders " | wc -c)
tyPosts[ 0] += $tableHeaders
# for message size calculation
# update following if you add tags in the message :
tags[ 0] = "Ğ1"
tags[ 1] = "resilience"
2020-03-18 20:41:11 +01:00
2020-03-20 17:03:27 +01:00
sizeOfTags = 0
for t in ${ !tags[@] }
do
tagSize = $( printf "%s" " ${ tags [t] } " | wc -c)
( ( sizeOfTags += sizeOfATagMention + tagSize ) )
done
2020-03-19 00:56:23 +01:00
2020-03-20 17:03:27 +01:00
firstPostContentSize = $( printf "%s" " ${ tyPosts [0] } " | wc -c)
tyPostsSizes[ 0] = $(( baseSizeOfAMessageFile + firstPostContentSize + sizeOfTags))
2020-03-19 00:56:23 +01:00
2020-03-20 17:03:27 +01:00
nbOfAuthors = ${# likesNbPerAuthor [@] }
authorNum = 1
2020-03-18 20:41:11 +01:00
for author_id in ${ !likesNbPerAuthor[@] }
do
process_author $author_id
2020-03-20 17:03:27 +01:00
2020-03-18 20:41:11 +01:00
# (Legacy) saving authors we have already mentionned in a message
likedAuthorsFile = $ssb_dir /db/g1likes
if [ ! -f $likedAuthorsFile ] ; then
touch $likedAuthorsFile
fi
if ! grep -Fxq $author_id $likedAuthorsFile ; then
echo $author_id >> $likedAuthorsFile
fi
2020-03-19 00:56:23 +01:00
2020-03-20 17:03:27 +01:00
tipAmount = $( bc <<< " ${ likesNbPerAuthor [ $author_id ] } * $amountPerLikeInUD " )
2020-03-19 00:56:23 +01:00
newLine = ''
2020-03-20 17:03:27 +01:00
newLine += $( printf "| [@%s](%s) " " $author_name " " $author_id " )
2020-03-19 00:56:23 +01:00
newLine += "| "
2020-03-18 20:41:11 +01:00
2020-03-20 17:03:27 +01:00
sizeOfAuthorName = $( printf "%s" " $author_name " | wc -c)
sizeOfAuthorId = $( printf "%s" " $author_id " | wc -c)
newLineSize = 0
( ( newLineSize += sizeOfAUserMention + sizeOfAuthorName + sizeOfAuthorId) )
2020-03-18 20:41:11 +01:00
2020-03-20 17:03:27 +01:00
p = ${ likedPosts [ $author_id ] }
thisAuthorLikedPosts = ( ${ p // \\ n / } )
2020-03-18 20:41:11 +01:00
2020-03-20 17:03:27 +01:00
isFirstPostOfThisAuthor = 1
for likedPostId in ${ thisAuthorLikedPosts [@] }
2020-03-18 20:41:11 +01:00
do
2020-03-20 17:03:27 +01:00
if [ [ $isFirstPostOfThisAuthor -eq 1 ] ]
2020-03-18 20:41:11 +01:00
then
2020-03-20 17:03:27 +01:00
isFirstPostOfThisAuthor = 0
2020-03-19 00:56:23 +01:00
else
newLine += ", "
2020-03-20 17:03:27 +01:00
( ( newLineSize += 2 ) )
2020-03-18 20:41:11 +01:00
fi
2020-03-20 17:03:27 +01:00
newLine += $( printf " %s❤" " ${ likesNbPerPost [ $likedPostId ] } " )
newLine += $( printf "[\`%s\`](%s)" " ${ excerpts [ $likedPostId ] } " " $likedPostId " )
sizeOfExcerpt = ${# excerpts [ $likedPostId ] }
( ( sizeOfExcerpt += 2 ) ) # for before ` and after `
sizeOfLikedPostId = $( printf "%s" " $likedPostId " | wc -c)
( ( newLineSize += sizeOfAPostMention + sizeOfExcerpt + sizeOfLikedPostId ) )
2020-03-18 20:41:11 +01:00
done
2020-03-20 17:03:27 +01:00
newLine += $( printf "| %s UDĞ1 " " $tipAmount " )
2020-03-19 00:56:23 +01:00
newLine += "|\n"
2020-03-20 17:03:27 +01:00
( ( newLineSize += $( printf "%s" " $newLine " | wc -c) ) )
# printf "total size: %s\n\n" "$((${tyPostsSizes[$tyPostIndex]} + $newLineSize))"
# If adding new line would exceed max size, we create a new thank you post
sizeWithNewLine = ${ tyPostsSizes [ $tyPostIndex ] }
( ( sizeWithNewLine += newLineSize ) )
if [ [ $sizeWithNewLine -gt $ssbMaxSize ] ]
2020-03-19 00:56:23 +01:00
then
2020-03-20 17:03:27 +01:00
printf "size before split: %s\n\n" " ${ tyPostsSizes [ $tyPostIndex ] } "
printf "size with new line: %s\n\n" " $sizeWithNewLine "
printf "size of new line: %s\n\n" " $newLineSize "
( ( tyPostIndex++ ) )
tyPosts[ $tyPostIndex ] += $tableHeaders
( ( tyPostsSizes[ $tyPostIndex ] = baseSizeOfAMessageFile + sizeOfTableHeaders ) )
2020-03-19 00:56:23 +01:00
fi
2020-03-20 17:03:27 +01:00
tyPosts[ $tyPostIndex ] += $newLine
( ( tyPostsSizes[ $tyPostIndex ] += newLineSize ) )
2020-03-19 00:56:23 +01:00
2020-03-18 20:41:11 +01:00
2020-03-20 17:03:27 +01:00
if [ [ $debugMsgMode -eq 0 ] ]
then
2020-03-18 20:41:11 +01:00
2020-03-20 17:03:27 +01:00
if [ [ $authorNum -ne 1 ] ]
then
sleep 20 # DO NOT OVER CHARGE DUNITER
fi
#printf '%s\n' "silkaj -af --file ~/.ssb/secret.dunikey tx --output $g1_author --amountUD $tipAmount --comment "Thx for your cool posts on ScuttleButt"
silkaj -p " $duniter_server " -af --file ~/.ssb/secret.dunikey tx --output $g1_author --amountUD $tipAmount --comment "Thx for your cool posts on ScuttleButt" -y 2>/dev/null
printf " \n ${ bold } %s UDĞ1 ${ normal } sent to %s!\n\n " " $tipAmount " " $author_name "
fi
2020-03-18 20:41:11 +01:00
2020-03-20 17:03:27 +01:00
( ( authorNum++ ) )
done
# Let's save the current timestamp
if [ [ $debugMsgMode -eq 0 ] ]
then
if ! echo " $current_ts " > " $state_file " ~
2020-03-13 17:52:08 +01:00
then
2020-03-18 20:41:11 +01:00
printf 'Unable to write to backup state file.\n' >& 2
2020-03-13 17:52:08 +01:00
exit 1
fi
2020-03-20 17:03:27 +01:00
2020-03-19 02:05:25 +01:00
if ! mv " $state_file " ~ " $state_file "
then
2020-03-20 17:03:27 +01:00
printf 'Unable to write to state file. Update state file manually to prevent tips to %s from being processed twice.\n' " $author_name " >& 2
2020-03-19 02:05:25 +01:00
exit 1
fi
2020-03-20 17:03:27 +01:00
fi
2020-03-18 20:41:11 +01:00
2020-03-19 00:56:23 +01:00
printf "\n%s UDĞ1 sent to %s butts!\n\n" " $amountGiven " " ${# likesNbPerAuthor [@] } "
2020-03-18 20:41:11 +01:00
# Let's publicly thank everyone!
2020-03-20 17:03:27 +01:00
#echo -e "${tyPosts[$n]}"
2020-03-18 20:41:11 +01:00
# the following produces error:
# "sbotc: unexpected end of parent stream"
# must be a non-escaped quote problem...
2020-03-20 17:03:27 +01:00
#thank_you_msg=$(printf "%q" "${tyPosts[$n]}")
2020-03-18 20:41:11 +01:00
#sbotc publish '{"type":"post","text":"'"$thank_you_msg"'"}' 2>&1>/dev/null
printf "What now ?\n\n"
2020-03-20 17:03:27 +01:00
if [ [ $readable -eq 1 ] ] ; then sleep 1; fi
2020-03-18 20:41:11 +01:00
2020-03-19 00:56:23 +01:00
date = $( date -u +%Y-week-%W)
2020-03-18 20:41:11 +01:00
2020-03-20 17:03:27 +01:00
if [ [ ${# tyPosts [@] } -eq 1 ] ]
2020-03-19 00:56:23 +01:00
then
msg_filename = thank-your-butts-$date
2020-03-20 17:03:27 +01:00
echo -e ${ tyPosts [ $n ] } > ~/$msg_filename .md
2020-03-19 00:56:23 +01:00
else
2020-03-20 17:03:27 +01:00
for i in ${ !tyPosts[@] }
2020-03-19 00:56:23 +01:00
do
part = $(( i + 1 ))
msg_filename = thank-your-butts-$date
2020-03-20 17:03:27 +01:00
echo -e ${ tyPosts [ $i ] } > ~/$msg_filename -part-$part .md
2020-03-19 00:56:23 +01:00
done
fi
2020-03-18 20:41:11 +01:00
2020-03-19 00:56:23 +01:00
printf "A surprise is awaiting in your home dir (~).\n\n"
2020-03-18 20:41:11 +01:00
2020-03-20 17:03:27 +01:00
if [ [ $readable -eq 1 ] ] ; then sleep 2; fi
2020-03-18 20:41:11 +01:00
2020-03-20 17:03:27 +01:00
if [ [ ${# tyPosts [@] } -eq 1 ] ]
2020-03-19 00:56:23 +01:00
then
printf "It's a file.\n\n"
2020-03-20 17:03:27 +01:00
if [ [ $readable -eq 1 ] ] ; then sleep 2; fi
2020-03-19 00:56:23 +01:00
printf " It's called $msg_filename .md\n\n "
else
2020-03-20 17:03:27 +01:00
printf "It's %s files.\n\n" " ${# tyPosts [@] } "
if [ [ $readable -eq 1 ] ] ; then sleep 2; fi
2020-03-19 00:56:23 +01:00
printf " The first one is called $msg_filename -part-1.md.\n\n "
fi
2020-03-18 20:41:11 +01:00
2020-03-20 17:03:27 +01:00
if [ [ $readable -eq 1 ] ] ; then sleep 2; fi
2020-03-18 20:41:11 +01:00
2020-03-19 10:55:02 +01:00
printf "Customize it to your needs to thank your fellow butts publicly and help spread awareness about libre currencies :-)\n\n"
2020-03-18 20:41:11 +01:00
2020-03-20 17:03:27 +01:00
if [ [ $readable -eq 1 ] ] ; then sleep 3; fi
2020-03-18 20:41:11 +01:00
printf "Then delete it.\n\n"
2020-03-20 17:03:27 +01:00
if [ [ $readable -eq 1 ] ] ; then sleep 2; fi
2020-03-18 20:41:11 +01:00
printf "...because it won't self-destruct, haha :D \n\n"
2020-03-18 22:18:15 +01:00