commit 1fe76a70a39b2bca97ef08f7f5ddc0f4cd5a4a3f Author: Boris Paing Date: Fri Mar 13 17:52:08 2020 +0100 first commit diff --git a/process-likes-g1-install.sh b/process-likes-g1-install.sh new file mode 100644 index 0000000..c43eac3 --- /dev/null +++ b/process-likes-g1-install.sh @@ -0,0 +1,125 @@ +#!/bin/bash +################################################################################ +# Authors: +# [@cel](@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519) +# [@Fred](@9BbJwPDjcyIqrOUPNn0nJZBduWdIrpMk3Cjz5MP361s=.ed25519) +# [@Boris](@l5nYExWYIgDLV6BYHOJPoI97jIUyTdSm8CTLpQ0XeOg=.ed25519) +# Version: 1.0 +# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/) +########################################################################################### +# ADD G1 Layer 10 LOVE to message writer you like ! +# INSTALL silkaj sbotc +# PREVENT DOUBLE PAYEMENT +############################################################################################ + +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' ] +} + + +# INSTALL build-essential + +if ! dpkg -s build-essential; then + sudo apt install build-essential -y +fi + +# INSTALL silkaj +if ! fn_exists silkaj; then +echo "INSTALL silkaj" +sudo apt-get update -y || true +sudo apt install python3-pip python3-setuptools python3-wheel -y && pip3 install silkaj --user +echo 'PATH=$PATH:.local/bin' >> ~/.bashrc && source ~/.bashrc +fi + +# INSTALL sbotc +if ! fn_exists sbotc; then +sudo apt install libsodium-dev jq -y +git clone https://git.scuttlebot.io/%25133ulDgs%2FoC1DXjoK04vDFy6DgVBB%2FZok15YJmuhD5Q%3D.sha256 sbotc +cd sbotc +make +sudo make install +fi + + +########################################################################################### +####################### G1 SSB ACCOUNT MANAGER ############################################ +########################################################################################### + +# Install DUP-Mnemonic + +if ! fn_exists dup-mnemonic; then + cd /tmp + git clone https://git.duniter.org/tools/dup-mnemonic-rs + cd dup-mnemonic-rs + cargo build --release + sudo cp target/release/dup-mnemonic /usr/local/bin +fi + +# CHECK SSB ~/.ssb/secret +if [[ ! -f ~/.ssb/secret ]]; then +mkdir -p ~/.ssb +echo "WELCOME CREATING YOUR G1 SSB ACCOUNT !!!" +echo "CHOOSE YOU LOGIN or LEAVE BLANK & HIT ENTER FOR AUTO GENERATION" +read salt +[[ $salt != "" ]] && echo "PASSWORD?" && read pepper && [[ $pepper == "" ]] && exit + + +# GENERATE MNEMONIC KEY: 9 MOTS +if [[ $salt == "" ]]; then + declare -a makeyarray + makeyarray=($(dup-mnemonic -l $lang)) + # LOGIN (=SALT) 6 MOTS + salt="${makeyarray[0]} ${makeyarray[1]} ${makeyarray[2]} ${makeyarray[3]} ${makeyarray[4]} ${makeyarray[5]}" + # PASS (=PEPPER) 3 MOTS + pepper="${makeyarray[6]} ${makeyarray[7]} ${makeyarray[8]}" +fi +echo "........." +echo "CREDENTIAL: $salt / $pepper" + +# CREATE ~/.ssb/secret.dunikey +python3 ./key_create_dunikey.py "$salt" "$pepper" +mv ./.secret.dunikey ~/.ssb/secret.dunikey + +# CREATE +pub=$(cat ~/.ssb/secret.dunikey | grep "pub" | cut -d ' ' -f 2) +priv=$(cat ~/.ssb/secret.dunikey | grep "sec" | cut -d ' ' -f 2) +ssbpub=$(echo $pub | base58 -d | base64) +ssbpriv=$(echo $priv | base58 -d | base64) +cat > ~/.ssb/secret < ~/.ssb/secret.dunikey </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" + + # 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 + + + #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!" + + sbotc publish '{"type":"post","text":"Thanks for this post ; I have just sent you G1 #libremoney. Claim it! ", "branch": "'"$target_id"'", "root": "'"$root_id"'"}' + + #sleep 60 # DO NOT OVER CHARGE DUNITER + 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 diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..0f4175a --- /dev/null +++ b/readme.md @@ -0,0 +1,3 @@ +SSB G1 like is a micro donation system, just like Flattr, except: +- It runs on SSB instead of centralized web +- It uses a libre currency instead of private currency