Astroport.ONE/tools/Connect_PLAYER_To_Gchange.sh

248 lines
13 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
2022-12-29 14:51:05 +01:00
. "$MY_PATH/my.sh"
2022-12-10 20:07:32 +01:00
export PLAYERFEEDS=""
2022-11-05 22:32:28 +01:00
2022-06-01 16:17:20 +02:00
######################################################################### CONNECT PLAYER WITH GCHANGE
# Check who is .current PLAYER
PLAYER="$1"
2022-11-05 22:32:28 +01:00
[[ ${PLAYER} == "" ]] && PLAYER=$(cat ~/.zen/game/players/.current/.player 2>/dev/null)
[[ ${PLAYER} == "" ]] && echo "ERROR PLAYER - EXIT" && exit 1
PSEUDO=$(cat ~/.zen/game/players/${PLAYER}/.pseudo 2>/dev/null)
[[ $G1PUB == "" ]] && G1PUB=$(cat ~/.zen/game/players/${PLAYER}/.g1pub 2>/dev/null)
[[ $G1PUB == "" ]] && echo "ERROR G1PUB - EXIT" && exit 1
2022-06-01 16:17:20 +02:00
2022-11-05 22:32:28 +01:00
PSEUDO=$(cat ~/.zen/game/players/${PLAYER}/.pseudo 2>/dev/null)
G1PUB=$(cat ~/.zen/game/players/${PLAYER}/.g1pub 2>/dev/null)
ASTRONS=$(cat ~/.zen/game/players/${PLAYER}/.playerns 2>/dev/null)
## REFRESH ASTRONAUTE TW
2022-12-25 22:26:34 +01:00
ASTRONAUTENS=$(ipfs key list -l | grep -w ${PLAYER} | cut -d ' ' -f1)
[[ ! $ASTRONAUTENS ]] && echo "WARNING No ${PLAYER} in keystore -- EXIT" && exit 1
2022-11-11 18:22:35 +01:00
[[ ! -f ~/.zen/game/players/${PLAYER}/QR.png ]] && echo "NOT MY ${PLAYER} -- EXIT" && exit 1
2022-11-05 22:32:28 +01:00
mkdir -p ~/.zen/tmp/${IPFSNODEID}/${PLAYER}/
2022-08-15 19:07:39 +02:00
## VERIFY IT HAS ALREADY RUN
if [[ ! -s ~/.zen/game/players/${PLAYER}/ipfs/cesium.json ]]; then
2022-11-16 18:53:07 +01:00
## GET GCHANGE PROFIL
2022-12-29 14:51:05 +01:00
$MY_PATH/jaklis/jaklis.py -k ~/.zen/game/players/${PLAYER}/secret.dunikey -n "$myDATA" get > ~/.zen/game/players/${PLAYER}/ipfs/gchange.json
2022-11-16 18:53:07 +01:00
## KEEPING ALREADY EXISTING PROFILE DATA
2022-12-09 01:39:47 +01:00
NAME=$(cat ~/.zen/game/players/${PLAYER}/ipfs/gchange.json | jq -r '.title' 2>/dev/null)
2022-11-16 18:53:07 +01:00
[[ ! $NAME || $NAME == "null" ]] && NAME="Astronaute ${PSEUDO}"
2022-12-09 01:39:47 +01:00
DESCR=$(cat ~/.zen/game/players/${PLAYER}/ipfs/gchange.json | jq -r '.description' 2>/dev/null)
[[ ! $DESCR || $DESCR == "null" ]] && DESCR="ASTROPORT Ŋ1 https://g1jeu.ml"
2022-11-16 18:53:07 +01:00
2022-12-09 01:39:47 +01:00
VILLE=$(cat ~/.zen/game/players/${PLAYER}/ipfs/gchange.json | jq -r '.city' 2>/dev/null)
2022-11-16 18:53:07 +01:00
[[ ! $VILLE || $VILLE == "null" ]] && VILLE="Paris, 75012"
2022-12-09 01:39:47 +01:00
ADRESSE=$(cat ~/.zen/game/players/${PLAYER}/ipfs/gchange.json | jq -r '.address' 2>/dev/null)
2022-11-16 18:53:07 +01:00
[[ ! $ADRESSE || $ADRESSE == "null" ]] && ADRESSE="Elysée"
2022-11-16 06:17:54 +01:00
# POSITION=$(cat ~/.zen/game/players/${PLAYER}/ipfs/gchange.json | jq -r '.geoPoint')
2022-12-09 01:39:47 +01:00
# SITE=$(cat ~/.zen/game/players/${PLAYER}/ipfs/gchange.json | jq -r '.socials' 2>/dev/null)
2022-11-15 18:57:16 +01:00
2022-10-07 00:32:33 +02:00
########################################################################
2022-12-11 18:51:48 +01:00
echo "GCHANGE+ PROFILE https://gchange.fr"
2022-12-08 23:19:09 +01:00
# echo "set -n "${NAME}" -d "${DESCR}" -v "${VILLE}" -a "${ADRESSE}""
2022-10-07 00:32:33 +02:00
########################################################################
2022-12-29 14:51:05 +01:00
$MY_PATH/jaklis/jaklis.py -k ~/.zen/game/players/${PLAYER}/secret.dunikey -n "$myDATA" set -n "${NAME}" -d "${DESCR}" -v "${VILLE}" -a "${ADRESSE}" -s "$LIBRA/ipns/$ASTRONAUTENS" #GCHANGE+
2022-10-27 13:27:17 +02:00
[[ ! $? == 0 ]] && echo "GCHANGE PROFILE CREATION FAILED"
2022-08-28 19:09:06 +02:00
2022-12-11 18:51:48 +01:00
echo
## TODO : GET THE MEMBER KEY TO SEND MESSAGE THROUGH CESIUM+
2022-12-11 18:51:48 +01:00
#~ ## SET CESIUM WALLET
#~ ########################################################################
#~ echo "CESIUM+ https://demo.cesium.app/#/app/wot/lg?q=$G1PUB"
#~ ########################################################################
#~ $MY_PATH/jaklis/jaklis.py -k ~/.zen/game/players/${PLAYER}/secret.dunikey -n "https://g1.data.e-is.pro" set -n "${NAME}" -d "${DESCR}" -v "${VILLE}" -a "${ADRESSE}" --s "http://ipfs.localhost:8080/ipns/$ASTRONAUTENS" #CESIUM+
#~ [[ ! $? == 0 ]] && echo "CESIUM PROFILE CREATION FAILED"
2022-10-07 00:32:33 +02:00
fi
2022-08-28 19:09:06 +02:00
2022-12-08 23:19:09 +01:00
## GET PROFILE BACK
2022-12-29 14:51:05 +01:00
$MY_PATH/jaklis/jaklis.py -k ~/.zen/game/players/${PLAYER}/secret.dunikey -n "$myDATA" get > ~/.zen/game/players/${PLAYER}/ipfs/gchange.json
#~ $MY_PATH/jaklis/jaklis.py -k ~/.zen/game/players/${PLAYER}/secret.dunikey -n "https://g1.data.e-is.pro" get > ~/.zen/game/players/${PLAYER}/ipfs/cesium.json
2022-12-08 23:19:09 +01:00
2022-06-01 16:17:20 +02:00
########################################################################
2022-12-11 18:51:48 +01:00
echo "### ${PLAYER} #################"
echo "SCANNING - $G1PUB STAR FRIENDS"
2022-11-02 18:51:55 +01:00
echo "########################################################################"
2022-09-27 00:09:24 +02:00
################## CHECKING WHO GAVE ME STARS
################## BOOTSTRAP LIKES THEM BACK
################## SEND ipfstryme MESSAGES to FRIENDS
2022-11-05 22:32:28 +01:00
rm -f ~/.zen/tmp/${IPFSNODEID}/${PLAYER}/my_star_level
2022-09-27 00:09:24 +02:00
## Getting Gchange liking_me list
2022-12-08 23:19:09 +01:00
echo "Checking received stars"
################################## JAKLIS PLAYER stars
~/.zen/Astroport.ONE/tools/timeout.sh -t 20 \
~/.zen/Astroport.ONE/tools/jaklis/jaklis.py \
2022-11-05 22:32:28 +01:00
-k ~/.zen/game/players/${PLAYER}/secret.dunikey \
2022-12-29 14:51:05 +01:00
-n "$myDATA" stars > ~/.zen/tmp/${IPFSNODEID}/${PLAYER}/received_stars.json
2022-12-11 18:51:48 +01:00
[[ ! $(cat ~/.zen/tmp/${IPFSNODEID}/${PLAYER}/received_stars.json | jq -r '.likes[].issuer') ]] && echo "Activez votre Toile de Confiance Ŋ1 sur GChange" && exit 0
2022-12-08 23:19:09 +01:00
2022-11-27 18:07:02 +01:00
cat ~/.zen/tmp/${IPFSNODEID}/${PLAYER}/received_stars.json | jq -r '.likes[].issuer' | sort | uniq > ~/.zen/tmp/${IPFSNODEID}/${PLAYER}/liking_me
2022-12-08 23:19:09 +01:00
# echo "cat ~/.zen/tmp/${IPFSNODEID}/${PLAYER}/received_stars.json | jq -r" # DEBUG
2022-09-27 00:09:24 +02:00
2022-11-05 22:32:28 +01:00
for liking_me in $(cat ~/.zen/tmp/${IPFSNODEID}/${PLAYER}/liking_me | sort | uniq);
2022-09-27 00:09:24 +02:00
do
[[ "${liking_me}" == "" ]] && continue ## Protect from empty line !!
2022-10-24 16:38:59 +02:00
echo "........................."
FRIENDNS=$(~/.zen/Astroport.ONE/tools/g1_to_ipfs.py ${liking_me})
2022-11-02 18:51:55 +01:00
echo "==========================="
echo "${liking_me} IS LIKING ME"
2022-12-29 14:51:05 +01:00
echo "TW ? $LIBRA/ipns/$FRIENDNS "
2022-09-27 00:09:24 +02:00
2022-10-07 00:32:33 +02:00
##### CHECKING IF WE LIKE EACH OTHER Ŋ1 LEVEL
2022-11-27 13:59:03 +01:00
echo "Receiving Stars : cat ~/.zen/tmp/${IPFSNODEID}/${PLAYER}/${liking_me}.Gstars.json | jq -r"
################################## JAKLIS LIKING_ME stars
~/.zen/Astroport.ONE/tools/timeout.sh -t 20 \
~/.zen/Astroport.ONE/tools/jaklis/jaklis.py \
2022-11-05 22:32:28 +01:00
-k ~/.zen/game/players/${PLAYER}/secret.dunikey \
2022-12-29 14:51:05 +01:00
-n "$myDATA" \
2022-11-05 22:32:28 +01:00
stars -p ${liking_me} > ~/.zen/tmp/${IPFSNODEID}/${PLAYER}/${liking_me}.Gstars.json
2022-12-15 21:06:01 +01:00
## ZOMBIE PROTECTION - PURGE AFTER 60 DAYS
find ~/.zen/game/players/${PLAYER}/FRIENDS/*.try -mtime +60 -type f -exec rm -f '{}' \;
try=$(cat ~/.zen/game/players/${PLAYER}/FRIENDS/${liking_me}.try 2>/dev/null)
[[ $try > 3 ]] && echo "${liking_me} TOO MANY TRY" && continue
2022-09-27 00:09:24 +02:00
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
2022-11-05 22:32:28 +01:00
## DATA EXTRACTION FROM ~/.zen/tmp/${IPFSNODEID}/${PLAYER}/${liking_me}.Gstars.json
my_star_level=$(cat ~/.zen/tmp/${IPFSNODEID}/${PLAYER}/${liking_me}.Gstars.json | jq -r '.yours.level');
gscore=$(cat ~/.zen/tmp/${IPFSNODEID}/${PLAYER}/${liking_me}.Gstars.json | jq -r '.score');
myfriendship=$(cat ~/.zen/tmp/${IPFSNODEID}/${PLAYER}/${liking_me}.Gstars.json | jq -r '.likes[] | select(.issuer | strings | test("'$G1PUB'"))')
## OH MY FRIEND !
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
2022-11-02 18:51:55 +01:00
echo "LIKING with $my_star_level stars : Friend Ŋ1 SCORE $gscore "
2022-11-05 22:32:28 +01:00
mkdir -p ~/.zen/game/players/${PLAYER}/FRIENDS/${liking_me}
2022-10-24 16:38:59 +02:00
2022-11-05 22:32:28 +01:00
cp ~/.zen/tmp/${IPFSNODEID}/${PLAYER}/${liking_me}.Gstars.json ~/.zen/game/players/${PLAYER}/FRIENDS/${liking_me}/ && rm -f ~/.zen/tmp/${IPFSNODEID}/${PLAYER}/${liking_me}.Gstars.json
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
2022-11-27 13:59:03 +01:00
## GET FRIEND GCHANGE PROFILE
${MY_PATH}/timeout.sh -t 20 \
2022-11-27 21:54:40 +01:00
${MY_PATH}/jaklis/jaklis.py get \
2022-12-29 14:51:05 +01:00
-n "$myDATA" \
2022-11-27 13:59:03 +01:00
-p ${liking_me} > ~/.zen/game/players/${PLAYER}/FRIENDS/${liking_me}/gchange.json
FRIENDTITLE=$(cat ~/.zen/game/players/${PLAYER}/FRIENDS/${liking_me}/gchange.json | jq -r '.title')
## GET FRIEND TW !!
2022-11-27 13:59:03 +01:00
echo "Getting $FRIENDTITLE latest online TW..."
2022-11-16 06:11:07 +01:00
YOU=$(ipfs swarm peers >/dev/null 2>&1 && echo "$USER" || 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/$FRIENDNS"
2022-12-29 14:51:05 +01:00
echo "$myIPFS/ipns/$FRIENDNS ($FRIENDTITLE)"
2022-12-14 17:34:55 +01:00
# DISPLAY TIMER
2022-12-15 21:06:01 +01:00
${MY_PATH}/displaytimer.sh 60 &
2022-12-14 17:34:55 +01:00
2022-12-15 21:06:01 +01:00
[[ $YOU ]] && ipfs --timeout 60s cat /ipns/$FRIENDNS > ~/.zen/game/players/${PLAYER}/FRIENDS/${liking_me}/index.html
[[ ! -s ~/.zen/game/players/${PLAYER}/FRIENDS/${liking_me}/index.html ]] && curl -m 60 -so ~/.zen/game/players/${PLAYER}/FRIENDS/${liking_me}/index.html "$LIBRA/ipns/$FRIENDNS"
2022-11-02 18:51:55 +01:00
## PLAYER TW EXISTING ?
2022-11-05 22:32:28 +01:00
if [ ! -s ~/.zen/game/players/${PLAYER}/FRIENDS/${liking_me}/index.html ]; then
2022-11-02 18:51:55 +01:00
## AUCUN VISA ASTRONAUTE ENVOYER UN MESSAGE PAR GCHANGE
2022-12-09 02:08:22 +01:00
echo "AUCUN TW ACTIF. PREVENONS LE"
2022-12-29 14:51:05 +01:00
$MY_PATH/jaklis/jaklis.py -k ~/.zen/game/players/${PLAYER}/secret.dunikey -n "$myDATA" send -d "${liking_me}" -t "HEY BRO !" -m "G1 TW BunkerBOX >>> (⌐■_■) <<< https://ipfs.copylaradio.com/ipns/$ASTRONAUTENS >>> (ᵔ◡◡ᵔ) <<< "
2022-11-02 18:51:55 +01:00
2022-12-15 21:06:01 +01:00
## I TRY
try=$((try+1)) && echo $try > ~/.zen/game/players/${PLAYER}/FRIENDS/${liking_me}.try
else
2022-11-02 18:51:55 +01:00
FTW="~/.zen/game/players/${PLAYER}/FRIENDS/${liking_me}/index.html"
2022-12-15 21:06:01 +01:00
echo "COOL MON AMI PUBLIE SUR IPFS : $FTW"
2022-12-15 21:06:01 +01:00
tiddlywiki --load ${FTW} --output ~/.zen/tmp --render '.' "${liking_me}.MadeInZion.json" 'text/plain' '$:/core/templates/exporters/JsonFile' 'exportFilter' 'MadeInZion'
[[ ! -s ~/.zen/tmp/${liking_me}.MadeInZion.json ]] && echo "~~~ BROKEN $FTW (☓‿‿☓) BAD ~/.zen/tmp/${liking_me}.MadeInZion.json ~~~" && continue
FPLAYER=$(cat ~/.zen/tmp/${liking_me}.MadeInZion.json | jq -r .[].player)
[[ ! $FPLAYER ]] && echo "NO PLAYER = BAD MadeInZion Tiddler" && continue
## CREATING 30 DAYS RSS STREAM
tiddlywiki --load ${FTW} \
2022-12-04 15:12:18 +01:00
--output ~/.zen/game/players/${PLAYER}/ipfs --render '.' "${FPLAYER}.rss.json" 'text/plain' '$:/core/templates/exporters/JsonFile' 'exportFilter' '[days:created[-30]]'
2022-12-15 21:06:01 +01:00
[[ ! -s ~/.zen/game/players/${PLAYER}/ipfs/${FPLAYER}.rss.json ]] && echo "NO ${FPLAYER} RSS - BAD ~/.zen/game/players/${PLAYER}/ipfs/${FPLAYER}.rss.json -" && continue
2022-12-15 21:06:01 +01:00
echo "DEBUG RSS : cat ~/.zen/game/players/${PLAYER}/ipfs/${FPLAYER}.rss.json | jq -r"
echo
2022-12-11 04:40:50 +01:00
tiddlywiki --load ${FTW} \
--output ~/.zen/game/players/${PLAYER}/ipfs --render '.' "${FPLAYER}.lightbeam-key.json" 'text/plain' '$:/core/templates/exporters/JsonFile' 'exportFilter' '$:/plugins/astroport/lightbeams/saver/ipns/lightbeam-key'
[[ ! -s ~/.zen/game/players/${PLAYER}/ipfs/${FPLAYER}.lightbeam-key.json ]] && echo "NO ${FPLAYER} lightbeam-key - CONTINUE -" && continue
ASTRONAUTEFEED=$(cat ~/.zen/game/players/${PLAYER}/ipfs/${FPLAYER}.lightbeam-key.json | jq -r .[].text)
2022-12-15 21:06:01 +01:00
echo "DEBUG LIGHTBEAM : cat ~/.zen/game/players/${PLAYER}/ipfs/${FPLAYER}.lightbeam-key.json | jq -r"
echo
## ADD THIS FPLAYER RSS FEED INTO PLAYER TW
## PUSH DATA TO 12345 SWARM KEY
mkdir -p ~/.zen/tmp/${IPFSNODEID}/rss/${PLAYER}
cp -f ~/.zen/game/players/${PLAYER}/ipfs/${FPLAYER}.rss.json ~/.zen/tmp/${IPFSNODEID}/rss/${PLAYER}/${FPLAYER}.rss.json
2022-12-14 00:24:14 +01:00
export FRIENDSFEEDS="$ASTRONAUTEFEED\n$FRIENDSFEEDS"
2022-12-14 17:34:55 +01:00
echo "$FRIENDSFEEDS" > ~/.zen/tmp/${IPFSNODEID}/rss/${PLAYER}/FRIENDSFEEDS
2022-12-14 00:24:14 +01:00
2022-12-15 21:06:01 +01:00
echo "(☉_☉ ) (☉_☉ ) (☉_☉ ) : FRIENDSFEEDS=" $FRIENDSFEEDS
2022-12-14 00:24:14 +01:00
export IFRIENDHEAD="<a target='you' href='/ipns/"$FRIENDNS"'>$$FRIENDTITLE</a>$IFRIENDHEAD"
2022-12-14 17:34:55 +01:00
echo "$IFRIENDHEAD" > ~/.zen/tmp/${IPFSNODEID}/rss/${PLAYER}/IFRIENDHEAD
2022-12-14 00:24:14 +01:00
2022-12-15 21:06:01 +01:00
echo "(☉_☉ ) (☉_☉ ) (☉_☉ ) : IFRIENDHEAD=" $IFRIENDHEAD
2022-12-14 00:24:14 +01:00
echo "APP=RSS : PLAYER FPLAYER RSS PUBLICATION READY"
echo "~/.zen/tmp/${IPFSNODEID}/rss/${PLAYER}/${FPLAYER}.rss.json"
fi
2022-11-02 18:51:55 +01:00
## ACTIVER RECUP ANNONCES...
2022-12-15 21:06:01 +01:00
# SCRAPING DONNE LE BON COIN - DIFFICILE - UTILISER COOKIE NAVIGATEUR
# https://www.leboncoin.fr/recherche?text=donne&locations=Toulouse__43.59743304757555_1.4471155185604894_10000_5000&owner_type=private&sort=time&donation=1
2022-10-07 00:32:33 +02:00
## Get Ŋ2 LEVEL
2022-11-05 22:32:28 +01:00
echo "(°▃▃°) (°▃▃°) (°▃▃°) Ŋ2 scraping ~/.zen/game/players/${PLAYER}/FRIENDS/${liking_me}/friend_of_friend.json"
for nid in $(cat ~/.zen/game/players/${PLAYER}/FRIENDS/${liking_me}/${liking_me}.Gstars.json | jq -r '.likes[].issuer');
2022-10-07 00:32:33 +02:00
do
2022-11-27 13:59:03 +01:00
2022-10-07 00:32:33 +02:00
echo "Ami(s) de cet Ami $linking_me : $nid"
2022-11-05 22:32:28 +01:00
friend_of_friend=$(cat ~/.zen/game/players/${PLAYER}/FRIENDS/${liking_me}/${liking_me}.Gstars.json | jq -r '.likes[] | select(.issuer | strings | test("'$nid'"))')
2022-11-27 13:59:03 +01:00
echo "$friend_of_friend" | jq -r > ~/.zen/game/players/${PLAYER}/FRIENDS/${liking_me}/FoF_$nid.json
2022-10-07 00:32:33 +02:00
done
else
2022-12-15 21:06:01 +01:00
#########################################
## COOL FEATURE FOR GCHANGE ACCOUNT CONFIDENCE
## IS IT REALLY A FRIEND I LIKE ?
2022-12-09 02:08:22 +01:00
echo "BRO?"
2022-12-29 14:51:05 +01:00
$MY_PATH/jaklis/jaklis.py -k ~/.zen/game/players/${PLAYER}/secret.dunikey -n "$myDATA" send -d "${G1PUB}" -t "Bro ?" -m "$myGCHANGE/#/app/user/${liking_me}/"
try=$((try+1)) && echo $try > ~/.zen/game/players/${PLAYER}/FRIENDS/${liking_me}.try
2022-09-27 00:09:24 +02:00
2022-11-02 18:51:55 +01:00
fi
2022-09-27 00:09:24 +02:00
sleep $((1 + RANDOM % 2)) # SLOW DOWN
2022-11-02 18:51:55 +01:00
2022-09-27 00:09:24 +02:00
done
2022-06-01 16:17:20 +02:00
2022-08-18 03:47:49 +02:00
exit 0