Split of thank you message is not a wild guess anymore
This commit is contained in:
parent
e6c309a7ef
commit
15d459d45f
Binary file not shown.
After Width: | Height: | Size: 4.0 MiB |
Binary file not shown.
Before Width: | Height: | Size: 820 KiB |
Binary file not shown.
After Width: | Height: | Size: 61 KiB |
Binary file not shown.
Before Width: | Height: | Size: 77 KiB |
Binary file not shown.
After Width: | Height: | Size: 3.2 MiB |
Binary file not shown.
After Width: | Height: | Size: 146 KiB |
107
readme.md
107
readme.md
|
@ -1,43 +1,11 @@
|
||||||
SSB/Ğ1 like
|
SSB/Ğ1 tip
|
||||||
===
|
===
|
||||||
|
|
||||||
**SSB/Ğ1 like** is a micro donation system, just like Flattr, except:
|
**SSB/Ğ1 tip** is a micro donation system, just like Flattr, except:
|
||||||
- It runs on SSB instead of the centralized web
|
- It runs on SSB instead of the centralized web
|
||||||
- It uses a libre currency (Ğ1) instead of a private one
|
- It uses a libre currency (Ğ1) instead of a private one
|
||||||
|
|
||||||
![SSB/Ğ1 like logo](https://git.p2p.legal/axiom-team/ssb-g1like/raw/dev-boris/doc/ssb-g1like-logo.png)
|
![SSB/Ğ1 tip logo](https://git.p2p.legal/axiom-team/ssb-g1-tip/raw/dev-boris/doc/ssb-g1-tip-logo.png)
|
||||||
|
|
||||||
## Authors
|
|
||||||
|
|
||||||
- **cel** from the SSB community (`@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519`)
|
|
||||||
- **Fred** from the Ğ1 community (`@9BbJwPDjcyIqrOUPNn0nJZBduWdIrpMk3Cjz5MP361s=.ed25519`)
|
|
||||||
- **Boris** from the Ğ1 community (`@l5nYExWYIgDLV6BYHOJPoI97jIUyTdSm8CTLpQ0XeOg=.ed25519`)
|
|
||||||
|
|
||||||
## What is a libre currency?
|
|
||||||
|
|
||||||
A [libre currency](https://libre-currency.org/) is a concept that originated from the [Relative Theory of Money](https://en.trm.creationmonetaire.info/).
|
|
||||||
|
|
||||||
It is a way to design a currency so that every human, whatever the generation they are part of, produces the same relative amount of money.
|
|
||||||
|
|
||||||
The Relative Theory of Money was written by a French mathematician in 2010, and the first libre currency (Ğ1) was born in 2017. Up to this day, Ğ1 is the only libre currency we know of.
|
|
||||||
|
|
||||||
### Ğ1, the first libre currency
|
|
||||||
|
|
||||||
Ğ1 the first libre currency we know of.
|
|
||||||
|
|
||||||
It runs on [the Duniter blockchain engine](https://duniter.org/).
|
|
||||||
|
|
||||||
The main clients for Duniter are [Cesium](https://cesium.app/) and [Silkaj](https://mystifying-nobel-66ae54.netlify.com/)
|
|
||||||
|
|
||||||
## How to spend your Ğ1
|
|
||||||
|
|
||||||
The Ğ1 currency originated in called France, so the main part of the fun happens there.
|
|
||||||
|
|
||||||
The economy is still in its infancy, but you can already [book a reservation in a B&B](https://www.gchange.fr/#/app/market/lg?last&category=cat67&type=offer).
|
|
||||||
|
|
||||||
An other way to spend your Ğ1 is use it with this micro-donation system:
|
|
||||||
|
|
||||||
![](https://git.p2p.legal/axiom-team/ssb-g1like/raw/dev-boris/doc/process-likes-g1tx.gif)
|
|
||||||
|
|
||||||
## An SSB user sent you Ğ1? Here is how to claim it:
|
## An SSB user sent you Ğ1? Here is how to claim it:
|
||||||
|
|
||||||
|
@ -52,11 +20,76 @@ Then, all you need to do is connect to a Duniter client, like [Cesium](https://c
|
||||||
|
|
||||||
On Cesium homescreen, click "**Other methods**" and choose "**Keychain file**" :
|
On Cesium homescreen, click "**Other methods**" and choose "**Keychain file**" :
|
||||||
|
|
||||||
![Cesium authentification](https://git.p2p.legal/axiom-team/ssb-g1like/raw/dev-boris/doc/cesium-other-methods-800.png)
|
![Cesium authentification](https://git.p2p.legal/axiom-team/ssb-g1-tip/raw/dev-boris/doc/cesium-other-methods-800.png)
|
||||||
|
|
||||||
Then, browse your filesystem to select your Duniter secret key stored in ~/.ssb/secret.dunikey :
|
Then, browse your filesystem to select your Duniter secret key stored in ~/.ssb/secret.dunikey :
|
||||||
|
|
||||||
![Cesium log with keychain file](https://git.p2p.legal/axiom-team/ssb-g1like/raw/dev-boris/doc/cesium-dunikey-800.png)
|
![Cesium log with keychain file](https://git.p2p.legal/axiom-team/ssb-g1-tip/raw/dev-boris/doc/cesium-dunikey-800.png)
|
||||||
|
|
||||||
|
|
||||||
|
## You too want to send tips?
|
||||||
|
|
||||||
|
An other way to spend your Ğ1 is use it with this micro-donation system.
|
||||||
|
|
||||||
|
First, you have to install the necessary tools, like Silkaj, the Duniter client:
|
||||||
|
```
|
||||||
|
chmod +x install.sh tip.sh
|
||||||
|
./install.sh
|
||||||
|
```
|
||||||
|
(you only have to do this once)
|
||||||
|
|
||||||
|
Then, once every other week, you can use the `tip.sh` script :
|
||||||
|
|
||||||
|
```
|
||||||
|
./tip.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
`tip.sh` will have a look at the posts you liked and will send from your Duniter account the corresponding amount (based on the number of times you liked a post) to the appropriate recipients.
|
||||||
|
|
||||||
|
It will also generate one or two markdown formatted files to help you thank publicly your fellow butts, and make them aware you sent them a tip 😉
|
||||||
|
|
||||||
|
![](https://git.p2p.legal/axiom-team/ssb-g1-tip/raw/dev-boris/doc/tip.gif)
|
||||||
|
|
||||||
|
|
||||||
|
## Other ways to spend your Ğ1
|
||||||
|
|
||||||
|
The Ğ1 currency originated in called France, so the main part of the fun happens there.
|
||||||
|
|
||||||
|
The economy is still in its infancy, but you can already:
|
||||||
|
|
||||||
|
- [book a reservation in a B&B](https://www.gchange.fr/#/app/market/lg?last&category=cat67&type=offer),
|
||||||
|
- [buy SEO services](https://www.gchange.fr/#/app/market/lg?type=offer&q=SEO),
|
||||||
|
- [buy web hosting services](https://www.gchange.fr/#/app/market/lg?type=offer&q=h%C3%A9bergement%20web)
|
||||||
|
- [buy foreign language courses](https://www.gchange.fr/#/app/market/lg?type=offer&q=langues) (for example: [french](https://www.gchange.fr/#/app/market/view/AWybPgso8tT4T_JOSi4w/francais-langue-trangre))
|
||||||
|
- etc. etc. ([see latest offers](https://www.gchange.fr/#/app/market/lg?last&type=offer))
|
||||||
|
|
||||||
|
## Curious about libre currencies?
|
||||||
|
|
||||||
|
[Libre currencies](https://libre-currency.org/) are a concept that originated from the [Relative Theory of Money](https://en.trm.creationmonetaire.info/).
|
||||||
|
|
||||||
|
It is a way to design a currency so that every human, whatever the generation they are part of, produces the same relative amount of money.
|
||||||
|
|
||||||
|
Unlinke the majority of currencies, where money creation is centralized (money is created by big private banks via credit), in a libre currency, money takes place everywhere.
|
||||||
|
|
||||||
|
!
|
||||||
|
|
||||||
|
The Relative Theory of Money was written by a French mathematician in 2010, and the first libre currency (Ğ1) was born in 2017. Up to this day, Ğ1 is the only libre currency we know of.
|
||||||
|
|
||||||
|
### Ğ1, the first libre currency
|
||||||
|
|
||||||
|
Ğ1 the first libre currency we know of.
|
||||||
|
|
||||||
|
It runs on [the Duniter blockchain engine](https://duniter.org/).
|
||||||
|
|
||||||
|
The main clients for Duniter are [Cesium](https://cesium.app/) and [Silkaj](https://mystifying-nobel-66ae54.netlify.com/)
|
||||||
|
|
||||||
|
![](https://git.p2p.legal/axiom-team/ssb-g1-tip/raw/dev-boris/doc/value-fields.png)
|
||||||
|
|
||||||
|
|
||||||
|
## Authors
|
||||||
|
|
||||||
|
- **cel** (`@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519`)
|
||||||
|
- **Fred** (`@9BbJwPDjcyIqrOUPNn0nJZBduWdIrpMk3Cjz5MP361s=.ed25519`)
|
||||||
|
- **Boris** (`@l5nYExWYIgDLV6BYHOJPoI97jIUyTdSm8CTLpQ0XeOg=.ed25519`)
|
||||||
|
- **poka** (`@vDQif9KU3T78XJx+NliK+wdo1vmehHZCWqD+3X700Uk=.ed25519`)
|
||||||
|
- **chamalow** (`@qio8/4L4vnzq3qRD0dqKI7sTpey54u8ZWbaICfpJOZw=.ed25519`)
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
{
|
||||||
|
"value": {
|
||||||
|
"previous": "%bcGFgwgdCjhGQjVYCNaUSKZq6xqMBpiB23U4q2lq2uE=.sha256",
|
||||||
|
"sequence": 392,
|
||||||
|
"author": "@l5nYExWYIgDLV6BYHOJPoI97jIUyTdSm8CTLpQ0XeOg=.ed25519",
|
||||||
|
"timestamp": 1584565226366,
|
||||||
|
"hash": "sha256",
|
||||||
|
"content": {
|
||||||
|
"type": "post",
|
||||||
|
"text": "",
|
||||||
|
"mentions": [
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"signature": "TZ8R5HlKvuPquS26CJkq2VhPdR+yA2LdnL0cVo1GD6jJioTufup1n6mSrQIc3jHyqy+wZ8ILJfsWnqt8WegQAg==.sig.ed25519"
|
||||||
|
},
|
||||||
|
"timestamp": 1584565226369,
|
||||||
|
"rts": 1584565226366
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
|
||||||
|
{
|
||||||
|
"link": "",
|
||||||
|
"name": ""
|
||||||
|
},
|
|
@ -0,0 +1,4 @@
|
||||||
|
|
||||||
|
{
|
||||||
|
"link": "#"
|
||||||
|
},
|
|
@ -0,0 +1,5 @@
|
||||||
|
|
||||||
|
{
|
||||||
|
"link": "",
|
||||||
|
"name": ""
|
||||||
|
},
|
|
@ -10,31 +10,49 @@
|
||||||
# PREVENT DOUBLE PAYEMENT
|
# PREVENT DOUBLE PAYEMENT
|
||||||
# ADD Ğ1 Layer 10 LOVE to message writer you like !
|
# ADD Ğ1 Layer 10 LOVE to message writer you like !
|
||||||
############################################################################################
|
############################################################################################
|
||||||
|
|
||||||
|
# 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"
|
||||||
|
|
||||||
|
############################################################################################
|
||||||
|
|
||||||
# Let's get Ğ1 public and private keys
|
# Let's get Ğ1 public and private keys
|
||||||
g1pub=$(cat ~/.ssb/secret.dunikey | grep "pub" | cut -d ' ' -f 2)
|
g1pub=$(cat ~/.ssb/secret.dunikey | grep "pub" | cut -d ' ' -f 2)
|
||||||
g1priv=$(cat ~/.ssb/secret.dunikey | grep "sec" | cut -d ' ' -f 2)
|
g1priv=$(cat ~/.ssb/secret.dunikey | grep "sec" | cut -d ' ' -f 2)
|
||||||
|
|
||||||
# SSB pubkey
|
# SSB pubkey
|
||||||
ssbpub=$(cat ~/.ssb/secret | grep public\" | cut -d ' ' -f 4 | cut -d '.' -f 1 | sed s/\"//g)
|
ssbpub=$(cat ~/.ssb/secret | grep public\" | cut -d ' ' -f 4 | cut -d '.' -f 1 | sed s/\"//g)
|
||||||
|
|
||||||
defaultAmountPerLikeInUD="0.05"
|
|
||||||
bold=$(tput bold)
|
bold=$(tput bold)
|
||||||
normal=$(tput sgr0)
|
normal=$(tput sgr0)
|
||||||
ssbMaxSize=8192
|
ssbMaxSize=8192
|
||||||
ssbMsgHeadersSize=5810 # Here is a wild guess!
|
|
||||||
|
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}')
|
||||||
|
|
||||||
|
|
||||||
############################################################################################
|
############################################################################################
|
||||||
#### CHECK LIKE AND SEND LOVE
|
#### CHECK LIKE AND SEND LOVE
|
||||||
# Let's get Ğ1 account balance
|
# Let's get Ğ1 account balance
|
||||||
echo ""
|
echo ""
|
||||||
echo -e "${bold}Welcome${normal} to the Ğ1/SSB-like microdonation system!\n"
|
echo -e "${bold}Welcome${normal} to the Ğ1/SSB-like microdonation system!\n"
|
||||||
sleep 1
|
if [[ $readable -eq 1 ]]; then sleep 1; fi
|
||||||
echo "MMMMMMMMMMMMMNk;'cdxxd:,c0WMMMMMMMMMMMMM
|
echo "MMMMMMMMMMMMMNk;'cdxxd:,c0WMMMMMMMMMMMMM
|
||||||
MMMMMMMMMMMMMNx,. .;kWMMMMMMMMMMMMM
|
MMMMMMMMMMMMMNx,. .;kWMMMMMMMMMMMMM
|
||||||
MMMMMMMMMMMMMMMNOdlccld0NMMMMMMMMMMMMMMM
|
MMMMMMMMMMMMMMMNOdlccld0NMMMMMMMMMMMMMMM
|
||||||
MMMMMMMMMMMWXko:,'....',:okXWMMMMMMMMMMM
|
MMMMMMMMMMMWXko:,'....',:okXWMMMMMMMMMMM
|
||||||
MMMMMMMMMNk:. .cOWMMMMMMMMM
|
MMMMMMMMMNk:. .cOWMMMMMMMMM
|
||||||
MMMMMMMW0: .c0MMMMMMMM"
|
MMMMMMMW0: .c0MMMMMMMM"
|
||||||
sleep 1
|
if [[ $readable -eq 1 ]]; then sleep 1; fi
|
||||||
echo "MMMMMMWk. 'lxkOOkdc' .cOWMMMMMMM
|
echo "MMMMMMWk. 'lxkOOkdc' .cOWMMMMMMM
|
||||||
MMMMMMO' 'kNMMMMMMMMNxcoOXWMMMMMMMMM
|
MMMMMMO' 'kNMMMMMMMMNxcoOXWMMMMMMMMM
|
||||||
MMMMMNl '0MMMMMMMMMMMMMMMMMMMMMMMMMM
|
MMMMMNl '0MMMMMMMMMMMMMMMMMMMMMMMMMM
|
||||||
|
@ -42,7 +60,7 @@ MMMMMX; cNMMMMMMMNOkkkkkkkkkkONMMMMM
|
||||||
MMMMMNc ;XMMMMMMMNd' .OMMMMM
|
MMMMMNc ;XMMMMMMMNd' .OMMMMM
|
||||||
MMMMMWx. cKMMMMMMMWKc. .OMMMMM
|
MMMMMWx. cKMMMMMMMWKc. .OMMMMM
|
||||||
MMMMMMNo. .lkKXNNXKkc. .OMMMMM"
|
MMMMMMNo. .lkKXNNXKkc. .OMMMMM"
|
||||||
sleep 1
|
if [[ $readable -eq 1 ]]; then sleep 1; fi
|
||||||
echo "MMMMMMMNd. ...... .OMMMMM
|
echo "MMMMMMMNd. ...... .OMMMMM
|
||||||
MMMMMMMMWKl. 'c:. .OMMMMM
|
MMMMMMMMWKl. 'c:. .OMMMMM
|
||||||
MMMMMMMMMMWXkc,.. ..,lkXWWO:;OMMMMM
|
MMMMMMMMMMWXkc,.. ..,lkXWWO:;OMMMMM
|
||||||
|
@ -51,17 +69,17 @@ MMMMMMMMMMMMMMMMNx;'',dNMMMMMMMMMMMMMMMM
|
||||||
MMMMMMMMMMMMMMMMK, '0MMMMMMMMMMMMMMMM
|
MMMMMMMMMMMMMMMMK, '0MMMMMMMMMMMMMMMM
|
||||||
MMMMMMMMMMMMMMMMNd. .oNMMMMMMMMMMMMMMMM
|
MMMMMMMMMMMMMMMMNd. .oNMMMMMMMMMMMMMMMM
|
||||||
"
|
"
|
||||||
sleep 1
|
if [[ $readable -eq 1 ]]; then sleep 1; fi
|
||||||
printf "You know your SSB pubkey:\n%s\n\n" $ssbpub
|
printf "You know your SSB pubkey:\n%s\n\n" $ssbpub
|
||||||
sleep 2
|
if [[ $readable -eq 1 ]]; then sleep 2; fi
|
||||||
printf "...but did you know it is also a valid Ğ1 wallet?\n%s\n\n" $g1pub
|
printf "...but did you know it is also a valid Ğ1 wallet?\n%s\n\n" $g1pub
|
||||||
sleep 2
|
if [[ $readable -eq 1 ]]; then sleep 2; fi
|
||||||
printf "Let's check the current balance of your wallet!\n\n"
|
printf "Let's check the current balance of your wallet!\n\n"
|
||||||
sleep 1
|
if [[ $readable -eq 1 ]]; then sleep 1; fi
|
||||||
printf "I am interrogating the Ğ1 blockchain to check if anyone has already sent you Ğ1...\n\n"
|
printf "I am interrogating the Ğ1 blockchain to check if anyone has already sent you Ğ1...\n\n"
|
||||||
sleep 2
|
if [[ $readable -eq 1 ]]; then sleep 2; fi
|
||||||
printf "A moment please...\n\n"
|
printf "A moment please...\n\n"
|
||||||
sleep 1
|
if [[ $readable -eq 1 ]]; then sleep 1; fi
|
||||||
|
|
||||||
silkajRelativeAmountPattern='Total\sRelative\s+=\s+(.*)\s+UD'
|
silkajRelativeAmountPattern='Total\sRelative\s+=\s+(.*)\s+UD'
|
||||||
|
|
||||||
|
@ -104,9 +122,9 @@ else
|
||||||
fi
|
fi
|
||||||
|
|
||||||
printf "You have ${bold}%s UDĞ1${normal} on your Duniter Ğ1 wallet.\n\n" "$balance"
|
printf "You have ${bold}%s UDĞ1${normal} on your Duniter Ğ1 wallet.\n\n" "$balance"
|
||||||
sleep 2
|
if [[ $readable -eq 1 ]]; then sleep 2; fi
|
||||||
printf "Want to show your appreciation of your fellow butts' posts while helping spreading awareness about libre currencies?\n\n"
|
printf "Want to show your appreciation of your fellow butts' posts while helping spreading awareness about libre currencies?\n\n"
|
||||||
sleep 3
|
if [[ $readable -eq 1 ]]; then sleep 3; fi
|
||||||
|
|
||||||
|
|
||||||
# BEGIN timestamp computation
|
# BEGIN timestamp computation
|
||||||
|
@ -121,7 +139,8 @@ if [ -s "$state_file" ]
|
||||||
then
|
then
|
||||||
last_ts=$(cat "$state_file") || exit 1
|
last_ts=$(cat "$state_file") || exit 1
|
||||||
else
|
else
|
||||||
last_ts=$((current_ts - 3600000)) # timestamp from 1h ago
|
# timestamp from 24h ago
|
||||||
|
last_ts=$((current_ts - 24*3600*1000))
|
||||||
#else last_ts=null
|
#else last_ts=null
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -130,7 +149,7 @@ days_from_last_tx=$(( (current_ts - last_ts) / (24*60*60*1000) ))
|
||||||
|
|
||||||
|
|
||||||
printf "First, let's see how much ❤ you gave lately...\n\n"
|
printf "First, let's see how much ❤ you gave lately...\n\n"
|
||||||
sleep 1
|
if [[ $readable -eq 1 ]]; then sleep 1; fi
|
||||||
|
|
||||||
declare -A likesNbPerAuthor
|
declare -A likesNbPerAuthor
|
||||||
|
|
||||||
|
@ -165,6 +184,7 @@ process_author() {
|
||||||
author_id=$1
|
author_id=$1
|
||||||
g1_author=$(echo $author_id | cut -d '.' -f 1 | cut -d '@' -f2 | base64 -d | base58)
|
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)
|
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)
|
||||||
|
author_name=${author_name:1:-1}
|
||||||
}
|
}
|
||||||
|
|
||||||
authorsNb=0
|
authorsNb=0
|
||||||
|
@ -219,11 +239,14 @@ do
|
||||||
|
|
||||||
excerpts[$target_id]=$msg_excerpt
|
excerpts[$target_id]=$msg_excerpt
|
||||||
|
|
||||||
if ! postsTimestamps[$target_id]=$(printf %s "$msg" | jq -r .value.timestamp)
|
# We cannot use this anymore
|
||||||
then
|
# (now saving current_ts once all tx have been sent)
|
||||||
printf 'Unable to get message timestamp\n' >&2
|
#
|
||||||
exit 1
|
# if ! postsTimestamps[$target_id]=$(printf %s "$msg" | jq -r .value.timestamp)
|
||||||
fi
|
#then
|
||||||
|
# printf 'Unable to get message timestamp\n' >&2
|
||||||
|
# exit 1
|
||||||
|
#fi
|
||||||
|
|
||||||
((i++))
|
((i++))
|
||||||
fi
|
fi
|
||||||
|
@ -236,70 +259,102 @@ then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
printf "You gave ${bold}%s❤${normal} during the past %s days.\n\n" "$totalLikesGiven" "$days_from_last_tx"
|
printf "You gave ${bold}%s❤${normal} during the past %s days.\n\n" "$totalLikesGiven" "$days_from_last_tx"
|
||||||
sleep 2
|
if [[ $readable -eq 1 ]]; then sleep 2; fi
|
||||||
|
|
||||||
tx_are_possible=0
|
tx_are_possible=0
|
||||||
|
|
||||||
while [[ $tx_are_possible -eq 0 ]]
|
while [[ $tx_are_possible -eq 0 ]]
|
||||||
do
|
do
|
||||||
|
|
||||||
printf "How many UDĞ1 do you want to send per each like you gave? (default is ${bold}%s UDĞ1${normal}) " "$defaultAmountPerLikeInUD"
|
printf "How many UDĞ1 do you want to send per each like you gave? (minimum is ${bold}%s UDĞ1${normal}) " "$minimumAmountPerLikeInUD"
|
||||||
read a
|
read a
|
||||||
printf "\n"
|
printf "\n"
|
||||||
|
|
||||||
if [[ -z $a ]]
|
if [[ -z $a ]]
|
||||||
then
|
then
|
||||||
amountPerLikeInUD=$defaultAmountPerLikeInUD
|
amountPerLikeInUD=$minimumAmountPerLikeInUD
|
||||||
else
|
else
|
||||||
amountPerLikeInUD=$a
|
amountPerLikeInUD=$a
|
||||||
fi
|
fi
|
||||||
|
|
||||||
amountGiven=$(echo "$totalLikesGiven * $amountPerLikeInUD" | bc -l)
|
amountGiven=$(echo "$totalLikesGiven * $amountPerLikeInUD" | bc -l)
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
tx_are_possible=$(( $(echo "$amountGiven <= $balance" | bc -l) ))
|
printf "You don't have enough UDĞ1 to send all transactions.\n\n"
|
||||||
|
if [[ $readable -eq 1 ]]; then sleep 1; fi
|
||||||
sleep 1
|
printf "${bold}%s UDĞ1${normal} are needed.\n\n" "$amountGiven"
|
||||||
|
if [[ $readable -eq 1 ]]; then sleep 1; fi
|
||||||
if [[ $tx_are_possible -ne 0 ]] ; then
|
elif [[ $amountPerLike_is_enough -eq 0 ]] ; then
|
||||||
newBalance=$(echo "$balance - $amountGiven" | bc -l)
|
|
||||||
printf "${bold}%s UDĞ1${normal} will be given.\n\n" "$amountGiven"
|
printf "Minimum amount per like is %s UDĞ1.\n\n" $minimumAmountPerLikeInUD
|
||||||
sleep 1
|
if [[ $readable -eq 1 ]]; then sleep 1; fi
|
||||||
printf "After sending transactions, your new balance will be ${bold}%s UDĞ1${normal}\n\n" "$newBalance"
|
|
||||||
sleep 1
|
fi
|
||||||
printf "Press ENTER to continue: " && read
|
|
||||||
printf "\n"
|
|
||||||
else
|
|
||||||
printf "You don't have enough UDĞ1 to send all transactions.\n\n"
|
|
||||||
sleep 1
|
|
||||||
printf "${bold}%s UDĞ1${normal} are needed.\n\n" "$amountGiven"
|
|
||||||
sleep 1
|
|
||||||
printf "Try again with a different amount per like.\n\n"
|
printf "Try again with a different amount per like.\n\n"
|
||||||
maxAmountPerLike=$(awk -vp=$balance -vq=$totalLikesGiven 'BEGIN{printf "%.2f" ,p / q}')
|
maxAmountPerLike=$(awk -vp=$balance -vq=$totalLikesGiven 'BEGIN{printf "%.2f" ,p / q}')
|
||||||
sleep 1
|
if [[ $readable -eq 1 ]]; then sleep 1; fi
|
||||||
printf "Maximum amount per like possible: ${bold}%s UDĞ1${normal}\n\n" "$maxAmountPerLike"
|
printf "Maximum amount per like possible: ${bold}%s UDĞ1${normal}\n\n" "$maxAmountPerLike"
|
||||||
sleep 1
|
if [[ $readable -eq 1 ]]; then sleep 1; fi
|
||||||
|
else
|
||||||
|
newBalance=$(echo "$balance - $amountGiven" | bc -l)
|
||||||
|
printf "${bold}%s UDĞ1${normal} will be given.\n\n" "$amountGiven"
|
||||||
|
if [[ $readable -eq 1 ]]; then sleep 1; fi
|
||||||
|
printf "After sending transactions, your new balance will be ${bold}%s UDĞ1${normal}\n\n" "$newBalance"
|
||||||
|
if [[ $readable -eq 1 ]]; then sleep 1; fi
|
||||||
|
printf "Press ENTER to continue: " && read
|
||||||
|
printf "\n"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# Let's construct thank you message and send transactions!
|
# Let's construct thank you posts (tyPosts) and send transactions!
|
||||||
|
|
||||||
n=0
|
tyPostIndex=0
|
||||||
outputs[$n]=""
|
tyPosts[0]=""
|
||||||
outputs[$n]+=$(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]+="# I tipped you for your posts!\n\n"
|
||||||
outputs[$n]+="\n\nAs a means to thank you further, I have just sent you #Ğ1 libre money.\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")
|
||||||
outputs[$n]+="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"
|
tyPosts[0]+="\n\nAs a means to thank you further, I have just sent you #Ğ1 libre money.\n\n"
|
||||||
outputs[$n]+="You can learn how to spend your freshly earned money at [https://git.p2p.legal/Axiom-Team/ssb-g1like](https://git.p2p.legal/Axiom-Team/ssb-g1like)\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"
|
||||||
outputs[$n]+="Below is the list of SSB users whose content I liked recently, and the amount each one was given:\n\n"
|
tyPosts[0]+="You can learn how to spend your freshly earned money at [https://git.p2p.legal/Axiom-Team/ssb-g1like](https://git.p2p.legal/Axiom-Team/ssb-g1like)\n\n"
|
||||||
|
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 | given |\n'
|
tableHeaders='| thanks to | for their posts | tip |\n'
|
||||||
tableHeaders+='| --- | --- | ---- |\n'
|
tableHeaders+='| --- | --- | ---- |\n'
|
||||||
|
sizeOfTableHeaders=$(printf "%s" "$tableHeaders" | wc -c)
|
||||||
|
tyPosts[0]+=$tableHeaders
|
||||||
|
|
||||||
outputs[$n]+=$tableHeaders
|
# for message size calculation
|
||||||
|
# update following if you add tags in the message :
|
||||||
|
tags[0]="Ğ1"
|
||||||
|
tags[1]="resilience"
|
||||||
|
|
||||||
|
sizeOfTags=0
|
||||||
|
for t in ${!tags[@]}
|
||||||
|
do
|
||||||
|
tagSize=$(printf "%s" "${tags[t]}" | wc -c)
|
||||||
|
|
||||||
|
(( sizeOfTags+=sizeOfATagMention + tagSize ))
|
||||||
|
done
|
||||||
|
|
||||||
|
firstPostContentSize=$(printf "%s" "${tyPosts[0]}" | wc -c)
|
||||||
|
tyPostsSizes[0]=$((baseSizeOfAMessageFile + firstPostContentSize + sizeOfTags))
|
||||||
|
|
||||||
|
nbOfAuthors=${#likesNbPerAuthor[@]}
|
||||||
|
authorNum=1
|
||||||
|
|
||||||
for author_id in ${!likesNbPerAuthor[@]}
|
for author_id in ${!likesNbPerAuthor[@]}
|
||||||
do
|
do
|
||||||
process_author $author_id
|
process_author $author_id
|
||||||
|
|
||||||
# (Legacy) saving authors we have already mentionned in a message
|
# (Legacy) saving authors we have already mentionned in a message
|
||||||
likedAuthorsFile=$ssb_dir/db/g1likes
|
likedAuthorsFile=$ssb_dir/db/g1likes
|
||||||
if [ ! -f $likedAuthorsFile ]; then
|
if [ ! -f $likedAuthorsFile ]; then
|
||||||
|
@ -311,125 +366,160 @@ do
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
author_amount=$(bc <<< "${likesNbPerAuthor[$author_id]} * $amountPerLikeInUD")
|
tipAmount=$(bc <<< "${likesNbPerAuthor[$author_id]} * $amountPerLikeInUD")
|
||||||
newLine=''
|
newLine=''
|
||||||
newLine+=$(printf "| [@%s](%s) " "${author_name:1:-1}" "$author_id")
|
newLine+=$(printf "| [@%s](%s) " "$author_name" "$author_id")
|
||||||
newLine+="| "
|
newLine+="| "
|
||||||
|
|
||||||
posts=${likedPosts[$author_id]}
|
sizeOfAuthorName=$(printf "%s" "$author_name" | wc -c)
|
||||||
thisAuthorLikedPosts=( ${posts//\\n/ } )
|
sizeOfAuthorId=$(printf "%s" "$author_id" | wc -c)
|
||||||
|
newLineSize=0
|
||||||
|
(( newLineSize+=sizeOfAUserMention + sizeOfAuthorName + sizeOfAuthorId))
|
||||||
|
|
||||||
firstPost=1
|
|
||||||
|
|
||||||
for post_id in ${thisAuthorLikedPosts[@]}
|
p=${likedPosts[$author_id]}
|
||||||
|
thisAuthorLikedPosts=( ${p//\\n/ } )
|
||||||
|
|
||||||
|
isFirstPostOfThisAuthor=1
|
||||||
|
|
||||||
|
for likedPostId in ${thisAuthorLikedPosts[@]}
|
||||||
do
|
do
|
||||||
if [[ $firstPost ]]
|
if [[ $isFirstPostOfThisAuthor -eq 1 ]]
|
||||||
then
|
then
|
||||||
firstPost=0
|
isFirstPostOfThisAuthor=0
|
||||||
else
|
else
|
||||||
newLine+=", "
|
newLine+=", "
|
||||||
|
(( newLineSize+=2 ))
|
||||||
fi
|
fi
|
||||||
|
|
||||||
newLine+=$(printf " %s❤" "${likesNbPerPost[$post_id]}")
|
newLine+=$(printf " %s❤" "${likesNbPerPost[$likedPostId]}")
|
||||||
newLine+=$(printf "[\`%s\`](%s)" "${excerpts[$post_id]}" "$post_id")
|
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 ))
|
||||||
|
|
||||||
done
|
done
|
||||||
|
|
||||||
newLine+=$(printf "| %s UDĞ1 " $author_amount)
|
newLine+=$(printf "| %s UDĞ1 " "$tipAmount")
|
||||||
|
|
||||||
newLine+="|\n"
|
newLine+="|\n"
|
||||||
|
|
||||||
messageSize=$(printf "%s%s" "${outputs[$n]}" "$newLine" | wc -c)
|
|
||||||
totalSize=$((messageSize + ssbMsgHeadersSize))
|
|
||||||
|
|
||||||
if [[ $totalSize -gt $ssbMaxSize ]]
|
(( 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 ]]
|
||||||
then
|
then
|
||||||
outputs[$n]+="For message size reasons, the rest of the list had to be displayed below, in the following answer:"
|
printf "size before split: %s\n\n" "${tyPostsSizes[$tyPostIndex]}"
|
||||||
((n++))
|
printf "size with new line: %s\n\n" "$sizeWithNewLine"
|
||||||
outputs[$n]+=$tableHeaders
|
printf "size of new line: %s\n\n" "$newLineSize"
|
||||||
|
|
||||||
|
(( tyPostIndex++ ))
|
||||||
|
tyPosts[$tyPostIndex]+=$tableHeaders
|
||||||
|
(( tyPostsSizes[$tyPostIndex]=baseSizeOfAMessageFile + sizeOfTableHeaders ))
|
||||||
fi
|
fi
|
||||||
|
|
||||||
outputs[$n]+=$newLine
|
tyPosts[$tyPostIndex]+=$newLine
|
||||||
|
(( tyPostsSizes[$tyPostIndex]+=newLineSize ))
|
||||||
|
|
||||||
|
|
||||||
|
if [[ $debugMsgMode -eq 0 ]]
|
||||||
|
then
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
#printf '%s\n' "silkaj -af --file ~/.ssb/secret.dunikey tx --outputs[$n] $g1_author --amountUD $author_amount --comment "Thx for your cool posts on ScuttleButt"
|
(( authorNum++ ))
|
||||||
silkaj -p "$duniter_server" -af --file ~/.ssb/secret.dunikey tx --outputs[$n] $g1_author --amountUD $author_amount --comment "Thx for your cool posts on ScuttleButt" -y 2>/dev/null
|
done
|
||||||
|
|
||||||
printf "\n${bold}%s UDĞ1${normal} sent to %s!\n\n" "$author_amount" "${author_name:1:-1}"
|
# Let's save the current timestamp
|
||||||
|
if [[ $debugMsgMode -eq 0 ]]
|
||||||
# Let's save the timestamp of the last processed message
|
then
|
||||||
if ! echo "${postsTimestamps[$target_id]}" > "$state_file"~
|
if ! echo "$current_ts" > "$state_file"~
|
||||||
then
|
then
|
||||||
printf 'Unable to write to backup state file.\n' >&2
|
printf 'Unable to write to backup state file.\n' >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! mv "$state_file"~ "$state_file"
|
if ! mv "$state_file"~ "$state_file"
|
||||||
then
|
then
|
||||||
msg_id=$(printf %s "$msg" | jq -r .key)
|
printf 'Unable to write to state file. Update state file manually to prevent tips to %s from being processed twice.\n' "$author_name" >&2
|
||||||
printf 'Unable to write to state file. Update state file manually to prevent %s from being processed twice.\n' "$msg_id" >&2
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
sleep 20 # DO NOT OVER CHARGE DUNITER
|
|
||||||
done
|
|
||||||
|
|
||||||
printf "\n%s UDĞ1 sent to %s butts!\n\n" "$amountGiven" "${#likesNbPerAuthor[@]}"
|
printf "\n%s UDĞ1 sent to %s butts!\n\n" "$amountGiven" "${#likesNbPerAuthor[@]}"
|
||||||
|
|
||||||
# Let's publicly thank everyone!
|
# Let's publicly thank everyone!
|
||||||
#echo -e "${outputs[$n]}"
|
#echo -e "${tyPosts[$n]}"
|
||||||
|
|
||||||
# the following produces error:
|
# the following produces error:
|
||||||
# "sbotc: unexpected end of parent stream"
|
# "sbotc: unexpected end of parent stream"
|
||||||
# must be a non-escaped quote problem...
|
# must be a non-escaped quote problem...
|
||||||
#thank_you_msg=$(printf "%q" "${outputs[$n]}")
|
#thank_you_msg=$(printf "%q" "${tyPosts[$n]}")
|
||||||
#sbotc publish '{"type":"post","text":"'"$thank_you_msg"'"}' 2>&1>/dev/null
|
#sbotc publish '{"type":"post","text":"'"$thank_you_msg"'"}' 2>&1>/dev/null
|
||||||
|
|
||||||
printf "What now ?\n\n"
|
printf "What now ?\n\n"
|
||||||
|
|
||||||
sleep 1
|
if [[ $readable -eq 1 ]]; then sleep 1; fi
|
||||||
|
|
||||||
date=$(date -u +%Y-week-%W)
|
date=$(date -u +%Y-week-%W)
|
||||||
|
|
||||||
if [[ ${#outputs[@]} -eq 1 ]]
|
if [[ ${#tyPosts[@]} -eq 1 ]]
|
||||||
then
|
then
|
||||||
msg_filename=thank-your-butts-$date
|
msg_filename=thank-your-butts-$date
|
||||||
echo -e ${outputs[$n]} > ~/$msg_filename.md
|
echo -e ${tyPosts[$n]} > ~/$msg_filename.md
|
||||||
else
|
else
|
||||||
for i in ${!outputs[@]}
|
for i in ${!tyPosts[@]}
|
||||||
do
|
do
|
||||||
part=$((i + 1))
|
part=$((i + 1))
|
||||||
msg_filename=thank-your-butts-$date
|
msg_filename=thank-your-butts-$date
|
||||||
echo -e ${outputs[$i]} > ~/$msg_filename-part-$part.md
|
echo -e ${tyPosts[$i]} > ~/$msg_filename-part-$part.md
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
printf "A surprise is awaiting in your home dir (~).\n\n"
|
printf "A surprise is awaiting in your home dir (~).\n\n"
|
||||||
|
|
||||||
sleep 2
|
if [[ $readable -eq 1 ]]; then sleep 2; fi
|
||||||
|
|
||||||
if [[ ${#outputs[@]} -eq 1 ]]
|
if [[ ${#tyPosts[@]} -eq 1 ]]
|
||||||
then
|
then
|
||||||
printf "It's a file.\n\n"
|
printf "It's a file.\n\n"
|
||||||
sleep 2
|
if [[ $readable -eq 1 ]]; then sleep 2; fi
|
||||||
printf "It's called $msg_filename.md\n\n"
|
printf "It's called $msg_filename.md\n\n"
|
||||||
else
|
else
|
||||||
printf "It's %s files.\n\n" "${#outputs[@]}"
|
printf "It's %s files.\n\n" "${#tyPosts[@]}"
|
||||||
sleep 2
|
if [[ $readable -eq 1 ]]; then sleep 2; fi
|
||||||
printf "The first one is called $msg_filename-part-1.md.\n\n"
|
printf "The first one is called $msg_filename-part-1.md.\n\n"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
sleep 2
|
if [[ $readable -eq 1 ]]; then sleep 2; fi
|
||||||
|
|
||||||
printf "Customize it to your needs to thank your fellow butts publicly and help spread awareness about libre currencies :-)\n\n"
|
printf "Customize it to your needs to thank your fellow butts publicly and help spread awareness about libre currencies :-)\n\n"
|
||||||
|
|
||||||
sleep 3
|
if [[ $readable -eq 1 ]]; then sleep 3; fi
|
||||||
|
|
||||||
printf "Then delete it.\n\n"
|
printf "Then delete it.\n\n"
|
||||||
|
|
||||||
sleep 2
|
if [[ $readable -eq 1 ]]; then sleep 2; fi
|
||||||
|
|
||||||
printf "...because it won't self-destruct, haha :D \n\n"
|
printf "...because it won't self-destruct, haha :D \n\n"
|
||||||
|
|
Loading…
Reference in New Issue