Astroport.ONE/tools/Connect_PLAYER_To_Gchange.sh

205 lines
11 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
myIP=$(hostname -I | awk '{print $1}' | head -n 1)
isLAN=$(echo $myIP | grep -E "/(^127\.)|(^192\.168\.)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^::1$)|(^[fF][cCdD])/")
[[ ! $myIP || $isLAN ]] && myIP="ipfs.localhost"
2022-11-05 22:32:28 +01:00
IPFSNODEID=$(ipfs id -f='<id>\n')
2022-08-23 16:31:40 +02:00
ME="${0##*/}"
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-11-05 22:32:28 +01:00
ASTRONAUTENS=$(ipfs key list -l | grep ${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-11-05 22:32:28 +01:00
$MY_PATH/jaklis/jaklis.py -k ~/.zen/game/players/${PLAYER}/secret.dunikey -n "https://data.gchange.fr" get > ~/.zen/game/players/${PLAYER}/ipfs/gchange.json
2022-11-16 18:53:07 +01:00
## KEEPING ALREADY EXISTING PROFILE DATA
2022-11-15 18:57:16 +01:00
NAME=$(cat ~/.zen/game/players/${PLAYER}/ipfs/gchange.json | jq -r '.title')
2022-11-16 18:53:07 +01:00
[[ ! $NAME || $NAME == "null" ]] && NAME="Astronaute ${PSEUDO}"
2022-11-15 18:57:16 +01:00
DESCR=$(cat ~/.zen/game/players/${PLAYER}/ipfs/gchange.json | jq -r '.description')
[[ ! $DESCR || $DESCR == "null" ]] && DESCR="ASTROPORT Ŋ1 https://g1jeu.ml"
2022-11-16 18:53:07 +01:00
2022-11-15 18:57:16 +01:00
VILLE=$(cat ~/.zen/game/players/${PLAYER}/ipfs/gchange.json | jq -r '.city')
2022-11-16 18:53:07 +01:00
[[ ! $VILLE || $VILLE == "null" ]] && VILLE="Paris, 75012"
2022-11-16 06:17:54 +01:00
ADRESSE=$(cat ~/.zen/game/players/${PLAYER}/ipfs/gchange.json | jq -r '.address')
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-11-15 18:57:16 +01:00
SITE=$(cat ~/.zen/game/players/${PLAYER}/ipfs/gchange.json | jq -r '.socials')
2022-10-07 00:32:33 +02:00
########################################################################
2022-11-18 02:43:10 +01:00
echo "${PLAYER} GCHANGE+ PROFILE https://gchange.fr"
2022-11-17 16:24:45 +01:00
echo "set -n "${NAME}" -d "${DESCR}" -v "${VILLE}" -a "${ADRESSE}""
2022-10-07 00:32:33 +02:00
########################################################################
$MY_PATH/jaklis/jaklis.py -k ~/.zen/game/players/${PLAYER}/secret.dunikey -n "https://data.gchange.fr" set -n "${NAME}" -d "${DESCR}" -v "${VILLE}" -a "${ADRESSE}" -s "https://ipfs.copylaradio.com/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
## SET CESIUM WALLET
2022-10-07 00:32:33 +02:00
########################################################################
2022-11-18 02:43:10 +01:00
echo "${PLAYER} CESIUM+ PROFILE https://demo.cesium.app/#/app/wot/lg?q=$G1PUB"
2022-10-07 00:32:33 +02:00
########################################################################
$MY_PATH/jaklis/jaklis.py -k ~/.zen/game/players/${PLAYER}/secret.dunikey -n "https://g1.data.presles.fr" set -n "${NAME}" -d "${DESCR}" -v "${VILLE}" -a "${ADRESSE}" --s "http://ipfs.localhost:8080/ipns/$ASTRONAUTENS" #CESIUM+
2022-10-27 13:27:17 +02:00
[[ ! $? == 0 ]] && echo "CESIUM PROFILE CREATION FAILED"
## GET IT BACK
$MY_PATH/jaklis/jaklis.py -k ~/.zen/game/players/${PLAYER}/secret.dunikey -n "https://g1.data.presles.fr" get > ~/.zen/game/players/${PLAYER}/ipfs/cesium.json
2022-10-07 00:32:33 +02:00
fi
2022-08-28 19:09:06 +02:00
2022-06-01 16:17:20 +02:00
########################################################################
2022-11-02 18:51:55 +01:00
echo "########################################################################"
2022-11-05 22:32:28 +01:00
echo "SCANNING ${PLAYER} - $G1PUB - Gchange 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
echo "Getting 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 \
-n "https://data.gchange.fr" stars > ~/.zen/tmp/${IPFSNODEID}/${PLAYER}/received_stars.json
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-11-05 22:32:28 +01:00
echo "cat ~/.zen/tmp/${IPFSNODEID}/${PLAYER}/received_stars.json | jq -r"
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 "........................."
ASTRONAUTENS=$(~/.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-11-14 20:45:06 +01:00
echo "TW ? http://tube.copylaradio.com:8080/ipns/$ASTRONAUTENS "
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 \
-n "https://data.gchange.fr" \
2022-11-05 22:32:28 +01:00
stars -p ${liking_me} > ~/.zen/tmp/${IPFSNODEID}/${PLAYER}/${liking_me}.Gstars.json
2022-09-27 00:09:24 +02:00
## ZOMBIE PROTECTION
2022-11-05 22:32:28 +01:00
[[ "$?" == "0" && ! -s ~/.zen/tmp/${IPFSNODEID}/${PLAYER}/${liking_me}.Gstars.json ]] && rm -Rf ~/.zen/game/players/${PLAYER}/FRIENDS/${liking_me} && echo "${liking_me} is a ZOMBIE..." && 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-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/$ASTRONAUTENS"
echo "http://$myIP:8080/ipns/$ASTRONAUTENS ($YOU)"
2022-11-05 22:32:28 +01:00
[[ $YOU ]] && ipfs --timeout 12s cat /ipns/$ASTRONAUTENS > ~/.zen/game/players/${PLAYER}/FRIENDS/${liking_me}/index.html
[[ ! -s ~/.zen/game/players/${PLAYER}/FRIENDS/${liking_me}/index.html ]] && curl -m 12 -so ~/.zen/game/players/${PLAYER}/FRIENDS/${liking_me}/index.html "$LIBRA/ipns/$ASTRONAUTENS"
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
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 "BRO !" -m ">>> (◕‿‿◕) <<< https://astroport.copylaradio.com >>> (◕‿‿◕) <<<"
2022-11-02 18:51:55 +01:00
else
2022-11-02 18:51:55 +01:00
2022-11-27 13:59:03 +01:00
echo "COOL MON AMI EST SUR IPFS"
FTW="~/.zen/game/players/${PLAYER}/FRIENDS/${liking_me}/index.html"
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 (☓‿‿☓) ~~~" && 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]]'
[[ ! -s ~/.zen/game/players/${PLAYER}/ipfs/${FPLAYER}.rss.json ]] && echo "NO ${FPLAYER} RSS - CONTINUE -" && continue
## ADD THIS FPLAYER RSS FEED INTO PLAYER TW
## PUSH DATA TO 12345 SWARM KEY
mkdir -p ~/.zen/tmp/${IPFSNODEID}/rss/${FPLAYER}/
cp -f ~/.zen/game/players/${PLAYER}/ipfs/${FPLAYER}.rss.json ~/.zen/tmp/${IPFSNODEID}/rss/${FPLAYER}/rss.json
fi
2022-11-02 18:51:55 +01:00
## ACTIVER RECUP ANNONCES...
# SCRAPING DONNE LE BON COIN
# 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-11-02 18:51:55 +01:00
echo "ARE WE BRO?"
2022-11-27 02:20:47 +01:00
$MY_PATH/jaklis/jaklis.py -k ~/.zen/game/players/${PLAYER}/secret.dunikey -n "https://data.gchange.fr" send -d "${G1PUB}" -t "Bro ?" -m "https://www.gchange.fr/#/app/user/${liking_me}/"
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