Astroport.ONE/tools/Connect_PLAYER_To_Gchange.sh

136 lines
7.6 KiB
Bash
Raw Normal View History

2022-06-01 16:17:20 +02:00
#!/bin/bash
2022-08-15 19:07:39 +02:00
# Run After PLAYER.entrance.sh
2022-08-23 16:31:40 +02:00
################################################################################
MY_PATH="`dirname \"$0\"`" # relative
MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
ME="${0##*/}"
2022-06-01 16:17:20 +02:00
######################################################################### CONNECT PLAYER WITH GCHANGE
# Check who is .current PLAYER
PLAYER=$(cat ~/.zen/game/players/.current/.player 2>/dev/null) || ( echo "noplayer" && exit 1 )
PSEUDO=$(cat ~/.zen/game/players/.current/.pseudo 2>/dev/null) || ( echo "nopseudo" && exit 1 )
G1PUB=$(cat ~/.zen/game/players/.current/.g1pub 2>/dev/null) || ( echo "nog1pub" && exit 1 )
2022-08-15 19:07:39 +02:00
ASTRONAUTENS=$(ipfs key list -l | grep -w "$PLAYER" | cut -d ' ' -f 1)
2022-10-07 00:32:33 +02:00
if [[ ! -d ~/.zen/game/players/$PLAYER/FRIENDS/ ]]; then
########################################################################
echo "CREATING $PLAYER GCHANGE+ PROFILE"
########################################################################
$MY_PATH/jaklis/jaklis.py -k ~/.zen/game/players/$PLAYER/secret.dunikey -n "https://data.gchange.fr" set --name "Astronaute $PSEUDO" --avatar "/home/$USER/.zen/Astroport.ONE/images/logo.png" --site "https://astroport.com/ipns/$ASTRONAUTENS" #GCHANGE+
[[ ! $? == 0 ]] && echo "GCHANGE PROFILE CREATION FAILED" && echo "Action Manuelle " $MY_PATH/jaklis/jaklis.py -k ~/.zen/game/players/$PLAYER/secret.dunikey -n "https://data.gchange.fr" set --name "Astronaute $PSEUDO" --avatar "/home/$USER/.zen/Astroport.ONE/images/logo.png" --site "https://tube.copylaradio.com/ipns/$ASTRONAUTENS" #GCHANGE+
2022-08-28 19:09:06 +02:00
2022-10-07 00:32:33 +02:00
########################################################################
#echo "CREATING $PLAYER CESIUM+ PROFILE"
########################################################################
$MY_PATH/jaklis/jaklis.py -k ~/.zen/game/players/$PLAYER/secret.dunikey -n "https://g1.data.presles.fr" set --name "Astronaute $PSEUDO" --avatar "/home/$USER/.zen/Astroport.ONE/images/logo.png" --site "http://127.0.0.1:8080/ipns/$ASTRONAUTENS" #CESIUM+
[[ ! $? == 0 ]] && echo "CESIUM PROFILE CREATION FAILED" && echo "Action Manuelle " $ $MY_PATH/jaklis/jaklis.py -k ~/.zen/game/players/$PLAYER/secret.dunikey -n "https://g1.data.presles.fr" set --name "Astronaute $PLAYER" --avatar "/home/$USER/.zen/Astroport.ONE/images/logo.png" --site "http://127.0.0.1:8080/ipns/$ASTRONAUTENS" #CESIUM+
fi
2022-08-28 19:09:06 +02:00
2022-06-01 16:17:20 +02:00
########################################################################
########################################################################
2022-10-07 00:32:33 +02:00
echo "SCANNING $PLAYER Gchange FRIENDS"
2022-06-01 16:17:20 +02:00
########################################################################
2022-09-27 00:09:24 +02:00
################## CHECKING WHO GAVE ME STARS
################## BOOTSTRAP LIKES THEM BACK
################## SEND ipfstryme MESSAGES to FRIENDS
2022-10-07 00:59:15 +02:00
rm -f ~/.zen/tmp/my_star_level
2022-09-27 00:09:24 +02:00
## Getting Gchange liking_me list
2022-10-07 00:32:33 +02:00
echo "Reading received stars"
################################## JAKLIS PLAYER stars
~/.zen/Astroport.ONE/tools/timeout.sh -t 20 \
~/.zen/Astroport.ONE/tools/jaklis/jaklis.py \
-k ~/.zen/game/players/$PLAYER/secret.dunikey \
-n "https://data.gchange.fr" stars | jq -r '.likes[].issuer' | uniq > ~/.zen/tmp/liking_me
2022-09-27 00:09:24 +02:00
for liking_me in $(cat ~/.zen/tmp/liking_me | sort | uniq);
do
[[ "$liking_me" == "" ]] && continue ## Protect from empty line !!
ipfsnodeid=$(~/.zen/Astroport.ONE/tools/g1_to_ipfs.py $liking_me)
2022-10-07 00:32:33 +02:00
echo "$liking_me is Astronaut ?"
echo "Check TW Capsule https://tube.copylaradio.com/ipns/$ipfsnodeid "
2022-09-27 00:09:24 +02:00
2022-10-07 00:32:33 +02:00
##### CHECKING IF WE LIKE EACH OTHER Ŋ1 LEVEL
################################## JAKLIS LIKING_ME stars
~/.zen/Astroport.ONE/tools/timeout.sh -t 20 \
~/.zen/Astroport.ONE/tools/jaklis/jaklis.py \
-k ~/.zen/game/players/$PLAYER/secret.dunikey \
-n "https://data.gchange.fr" \
stars -p $liking_me > ~/.zen/tmp/Gstars.json
2022-09-27 00:09:24 +02:00
## ZOMBIE PROTECTION
[[ "$?" == "0" && ! -s ~/.zen/tmp/Gstars.json ]] && rm -Rf ~/.zen/game/players/$PLAYER/FRIENDS/$liking_me && echo "$liking_me is a ZOMBIE..." && continue
2022-10-06 21:18:54 +02:00
#### RECUP ANNONCES Gchange
## https://www.gchange.fr/#/app/records/wallet?q=2geH4d2sndR47XWtfDWsfLLDVyNNnRsnUD3b1sk9zYc4&old
2022-10-07 17:09:07 +02:00
## https://www.gchange.fr/#/app/market/records/42LqLa7ARTZqUKGz2Msmk79gwsY8ZSoFyMyPyEnoaDXR
2022-10-06 21:18:54 +02:00
## DATA EXTRACTION FROM ~/.zen/tmp/Gstars.json
2022-10-07 00:59:15 +02:00
my_star_level=$(cat ~/.zen/tmp/Gstars.json | jq -r '.yours.level');
f_score=$(cat ~/.zen/tmp/Gstars.json | jq -r '.score');
2022-10-07 00:32:33 +02:00
myfriendship=$(cat ~/.zen/tmp/Gstars.json | jq -r '.likes[] | select(.issuer | strings | test("'$G1PUB'"))')
## OH MY FRIEND !
2022-10-07 00:59:15 +02:00
if [[ "$my_star_level" != "null" && "$liking_me" != "$G1PUB" ]]
2022-09-27 00:09:24 +02:00
then
# ADD $liking_me TO MY ipfs FRIENDS list
echo "$liking_me ($my_star_level stars) : Ŋ1 SCORE $f_score "
mkdir -p ~/.zen/game/players/$PLAYER/FRsIENDS/$liking_me
2022-09-27 00:09:24 +02:00
# REFRESH & PUBLISH stars friends map
2022-10-07 00:59:15 +02:00
if [[ "$my_star_level" == "null" || "$my_star_level" == "" ]]; then
2022-09-27 00:09:24 +02:00
rm -Rf ~/.zen/game/players/$PLAYER/FRIENDS/$liking_me
2022-10-07 00:59:15 +02:00
echo "$my_star_level NO STAR !! Removing $liking_me"
2022-09-27 00:09:24 +02:00
## TODO : remove "ipfs pin" in "~/.zen/PIN/"
continue ## REMOVE NO GOOD FRIENDS (no star)
fi
cp ~/.zen/tmp/Gstars.json ~/.zen/game/players/$PLAYER/FRIENDS/$liking_me/ && rm -f ~/.zen/tmp/Gstars.json
2022-10-07 00:59:15 +02:00
echo "$my_star_level" > ~/.zen/game/players/$PLAYER/FRIENDS/$liking_me/stars.level && echo "***** $my_star_level STARS *****"
2022-09-27 00:09:24 +02:00
## GET FRIEND TW !!
echo "Getting latest online TW..."
YOU=$(ps auxf --sort=+utime | grep -w ipfs | grep -v -E 'color=auto|grep' | tail -n 1 | cut -d " " -f 1);
LIBRA=$(head -n 2 ~/.zen/Astroport.ONE/A_boostrap_nodes.txt | tail -n 1 | cut -d ' ' -f 2)
echo "$LIBRA/ipns/$ipfsnodeid"
echo "http://$myIP:8080/ipns/$ipfsnodeid ($YOU)"
[[ $YOU ]] && ipfs --timeout 12s cat /ipns/$ipfsnodeid > ~/.zen/game/players/$PLAYER/FRIENDS/$liking_me/index.html \
|| curl -m 12 -so ~/.zen/game/players/$PLAYER/FRIENDS/$liking_me/index.html "$LIBRA/ipns/$ipfsnodeid"
## PLAYER TW IS ONLINE ?
if [ ! -s ~/.zen/game/players/$PLAYER/FRIENDS/$liking_me/index.html ]; then
# # # # # # # # # # # # # # #
## AUCUN VISA ASTRONAUTE
echo "AUCUN TW ACTIF. ENVOYONS LUI UN MESSAGE..."
$MY_PATH/jaklis/jaklis.py -k ~/.zen/game/players/$PLAYER/secret.dunikey -n "https://data.gchange.fr" send -d "$liking_me" -t "SALUT. Je suis sur 'Astroport' Et toi ?" -m "Active ta 'Capsule Interplanétaire' et raccordons nos TW : https://qo-op.com"
else
echo "COOL MON AMI EST SUR IPFS"
ls -al ~/.zen/game/players/$PLAYER/FRIENDS/$liking_me/index.html
# # # # # # # # # # # # # # # TODO
# CHECK Dessin de Moa
# # # # # # # # # # # # # # #
# # # # # # # # # # # # # # #
## ASTROBOT POST TREATMENT
fi
## APPLIQUER FILTRAGE TAG
2022-10-07 00:32:33 +02:00
## Get Ŋ2 LEVEL
for nid in $(cat ~/.zen/game/players/$PLAYER/FRIENDS/$liking_me/Gstars.json | jq -r '.likes[].issuer');
do
echo "Ami(s) de cet Ami $linking_me : $nid"
friend_of_friend=$(~/.zen/game/players/$PLAYER/FRIENDS/$liking_me/Gstars.json | jq -r '.likes[] | select(.issuer | strings | test("'$nid'"))')
echo "$friend_of_friend" | jq -r > ~/.zen/game/players/$PLAYER/FRIENDS/$liking_me/fof.json
done
echo "***** Keep G1/IPNS conversion *****"
2022-09-27 00:09:24 +02:00
echo ${ipfsnodeid} > ~/.zen/game/players/$PLAYER/FRIENDS/$liking_me/ipfsnodeid
fi
sleep $((1 + RANDOM % 2)) # SLOW DOWN
done
2022-06-01 16:17:20 +02:00
2022-08-18 03:47:49 +02:00
exit 0