Transaction beetwin 2 tools OK
This commit is contained in:
parent
b4c023fa80
commit
d525ca046a
|
@ -8,7 +8,7 @@ bot.global.text({
|
|||
cmd = b.message.text
|
||||
process.env.hb_cmd = cmd
|
||||
process.env.hb_username = username
|
||||
pubkey = exec("src/shell/g1-infos.sh pubkey $hb_username $hb_cmd", function(err, stdout, stderr) {
|
||||
exec("src/shell/g1-infos.sh pubkey $hb_username $hb_cmd", function(err, stdout, stderr) {
|
||||
if (err) {
|
||||
b.respond("Une erreur est survenu ...")
|
||||
} else {
|
||||
|
@ -24,7 +24,7 @@ bot.global.text({
|
|||
}, (b) => {
|
||||
cmd = b.message.text
|
||||
process.env.hb_cmd = cmd
|
||||
pubkey = exec("src/shell/g1-infos.sh pseudo $hb_cmd", function(err, stdout, stderr) {
|
||||
exec("src/shell/g1-infos.sh pseudo $hb_cmd", function(err, stdout, stderr) {
|
||||
if (err) {
|
||||
b.respond("Une erreur est survenu ...")
|
||||
} else {
|
||||
|
@ -40,7 +40,7 @@ bot.global.text({
|
|||
}, (b) => {
|
||||
cmd = b.message.text
|
||||
process.env.hb_cmd = cmd
|
||||
pubkey = exec("src/shell/g1-infos.sh silkaj $hb_cmd", function(err, stdout, stderr) {
|
||||
exec("src/shell/g1-infos.sh silkaj $hb_cmd", function(err, stdout, stderr) {
|
||||
if (err) {
|
||||
b.respond("Une erreur est survenu :" + stderr)
|
||||
} else {
|
||||
|
@ -54,7 +54,7 @@ bot.global.text({
|
|||
bot.global.text({
|
||||
starts: ['membre','membres', 'biz membre','biz membres']
|
||||
}, (b) => {
|
||||
membres = exec("src/shell/g1-infos.sh membres", function(err, stdout, stderr) {
|
||||
exec("src/shell/g1-infos.sh membres", function(err, stdout, stderr) {
|
||||
if (err) {
|
||||
b.respond("Une erreur est survenu ...")
|
||||
} else {
|
||||
|
@ -64,3 +64,25 @@ bot.global.text({
|
|||
}, {
|
||||
id: 'g1-membres'
|
||||
});
|
||||
|
||||
bot.global.text({
|
||||
starts: ['deb','biz deb']
|
||||
}, (b) => {
|
||||
username = b.message.user.name
|
||||
cmd = b.message.text
|
||||
process.env.hb_cmd = cmd
|
||||
process.env.hb_username = username
|
||||
|
||||
setTimeout(() => { b.respond("coucou " + cmd); }, 2000);
|
||||
/* exec("src/shell/g1-infos.sh deb $hb_username $hb_cmd", function(err, stdout, stderr) {
|
||||
if (err) {
|
||||
b.respond("Une erreur est survenu ...")
|
||||
} else {
|
||||
b.respond(stdout)
|
||||
}
|
||||
});
|
||||
*/
|
||||
}, {
|
||||
id: 'debug-multi'
|
||||
});
|
||||
|
||||
|
|
|
@ -14,7 +14,8 @@ bot.global.text({
|
|||
process.env.hb_username = b.message.user.name + "@" + tool
|
||||
process.env.hb_room = room
|
||||
} else {
|
||||
process.env.hb_username = b.message.user.name
|
||||
process.env.hb_username = b.message.user.name + "@" + tool
|
||||
// process.env.hb_username = b.message.user.name
|
||||
process.env.hb_room = room + "@" + tool
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
#!/bin/bash
|
||||
#!/bin/bash -e
|
||||
|
||||
MY_PATH="`dirname \"$0\"`" # relative
|
||||
MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
|
||||
|
||||
[[ -n $MY_PATH/.env ]] && source $MY_PATH/.env || (echo "Please create $MY_PATH/.env as $MY_PATH/.env.example" && exit 1)
|
||||
|
||||
# Globals variables
|
||||
function DEBUG()
|
||||
{
|
||||
[ "$_DEBUG" == "on" ] && $@
|
||||
}
|
||||
|
||||
chanDB() {
|
||||
if [[ "$1" =~ '@' ]]; then
|
||||
chan=$(echo "$1" | awk -F '@' '{ print $1 }')
|
||||
|
@ -13,39 +17,56 @@ chanDB() {
|
|||
else
|
||||
chan="$1"
|
||||
fi
|
||||
[[ ! $chan ]] && echo "Please select user." && exit 0
|
||||
[[ ! $chan ]] && echo "Please select user." && return 2
|
||||
if [[ "$chan" =~ '#' ]]; then
|
||||
homedir="$HOME/.bog/ids/$tool/$chan"
|
||||
else
|
||||
homedir="$HOME/.bog/ids/$tool/@$chan"
|
||||
fi
|
||||
# echo "args: $1"
|
||||
# echo "tool: $tool"
|
||||
# echo "homedir: $homedir"
|
||||
DEBUG echo "_${FUNCNAME[0]}_: $chan"
|
||||
DEBUG echo "_${FUNCNAME[0]}_: $tool"
|
||||
DEBUG echo "_${FUNCNAME[0]}_: $homedir"
|
||||
[[ -f $homedir/db ]] && source $homedir/db
|
||||
}
|
||||
|
||||
# Send a message
|
||||
sendmsg() {
|
||||
chanDB "$1"
|
||||
[[ ! "$chan" == '#|@'* ]] && chan="@$chan"
|
||||
[[ ! "${chan::1}" =~ ^(#|@)$ ]] && chan="@$chan"
|
||||
local msg="${@:2}"
|
||||
|
||||
[[ ! $chan || ! $msg ]] && echo "Please select user and message." && exit 0
|
||||
[[ ! $chan || ! $msg ]] && echo "Please select user and message." && return 2
|
||||
|
||||
curl -s -H "X-Auth-Token: $AC_API_TOKEN" \
|
||||
-H "X-User-Id: $AC_API_ID" \
|
||||
-H "Content-type:application/json" \
|
||||
$API_URL/api/v1/chat.postMessage \
|
||||
-d "{ \"channel\": \"$chan\", \"text\": \"$msg\" }" > /dev/null 2>&1
|
||||
DEBUG echo "_${FUNCNAME[0]}_: $chan"
|
||||
DEBUG echo "_${FUNCNAME[0]}_: $tool"
|
||||
|
||||
if [[ $tool == "axiomchat" ]]; then
|
||||
curl -s -H "X-Auth-Token: $AC_API_TOKEN" \
|
||||
-H "X-User-Id: $AC_API_ID" \
|
||||
-H "Content-type:application/json" \
|
||||
$AC_API_URL/api/v1/chat.postMessage \
|
||||
-d "{ \"channel\": \"$chan\", \"text\": \"$msg\" }" > /dev/null 2>&1
|
||||
else
|
||||
echo -e "$msg"
|
||||
fi
|
||||
}
|
||||
|
||||
getPubkey() {
|
||||
url="$node/wot/members"
|
||||
[[ -z $username || $username == "bot" ]] && username=$(echo $1 | tr -d '@')
|
||||
# [[ -z $username || $username == "bot" ]] && username=$(echo $1 | tr -d '@')
|
||||
# old way: local pubkey=$(curl -m 5 -s $url | grep -wiB 1 $username | grep "pubkey" | awk -F '"' '{ print $4 }')
|
||||
local pubkey=$(curl -m 10 -s $url | jq -r --arg username "$username" '.results[] | select(.uid==$username) | .pubkey')
|
||||
[[ ! $usernameK ]] && usernameK="$1"
|
||||
[[ ${usernameK::1} == '@' ]] && usernameK=${usernameK#?}
|
||||
|
||||
if [[ "$usernameK" =~ '@' ]]; then
|
||||
chanDB "$usernameK"
|
||||
else
|
||||
local pubkey=$(curl -m 10 -s $url | jq -r --arg username "$usernameK" '.results[] | select(.uid==$username) | .pubkey')
|
||||
fi
|
||||
# DEBUG echo "_${FUNCNAME[0]}_: $pubkey"
|
||||
# DEBUG echo "_${FUNCNAME[0]}_: $usernameK"
|
||||
[[ $pubkey ]] && echo "$pubkey" || echo "none"
|
||||
exit 0
|
||||
}
|
||||
|
||||
getPseudo() {
|
||||
|
@ -62,7 +83,7 @@ getPassword() {
|
|||
chanDB "$1"
|
||||
if [[ -d $homedir ]]; then
|
||||
sendmsg $chan "Voici les identifiants de connexion de votre ḠCompte: \n \
|
||||
Login: **$salt**\nMot de passe: **$pepper**\nClé publique: **$pubkey** \n \
|
||||
Login: *$salt*\nMot de passe: *$pepper*\nClé publique: *$pubkey* \n \
|
||||
Calcul du solde de votre compte en cours ..."
|
||||
else
|
||||
echo "Vous n'avez pas de compte chez nous."
|
||||
|
@ -72,10 +93,10 @@ Calcul du solde de votre compte en cours ..."
|
|||
info_account() {
|
||||
chanDB "$1"
|
||||
if [[ -d $homedir ]]; then
|
||||
sendmsg $chan "Récupération de votre solde en cours sur **$pubkey** ..."
|
||||
sendmsg $chan "Récupération de votre solde en cours sur *$pubkey* ..."
|
||||
|
||||
local solde=$($silkaj balance $pubkey | grep "Total Quantitative" | awk -F= '{ print $2 }' | cut -c2-)
|
||||
echo "Votre solde est de **$solde**"
|
||||
echo "Votre solde est de *$solde*"
|
||||
else
|
||||
echo "Vous n'avez pas de compte chez nous."
|
||||
fi
|
||||
|
@ -85,8 +106,8 @@ init_account() {
|
|||
chanDB "$1"
|
||||
if [[ -f $homedir/secret.dunikey ]]; then
|
||||
pubkey=$(cat $homedir/secret.dunikey| grep "pub: " | awk '{ print $2 }')
|
||||
echo "Vous disposez déjà d'un portefeuille Ḡ1: **$pubkey**"
|
||||
exit 0
|
||||
echo "Vous disposez déjà d'un portefeuille Ḡ1: *$pubkey*"
|
||||
return 2
|
||||
else
|
||||
sendmsg $dest "Création de votre portefeuille..."
|
||||
fi
|
||||
|
@ -98,21 +119,23 @@ init_account() {
|
|||
# The pubkey for this salt/papper peer
|
||||
local pubkey=$(python3 $MY_PATH/../dunikey/key_create_dunikey.py "$salt" "$pepper")
|
||||
|
||||
[[ ! -f /tmp/secret.dunikey ]] && echo "Arf, problem happens making your secret.dunikey" && exit 0
|
||||
[[ ! -f /tmp/secret.dunikey ]] && echo "Arf, problem happens making your secret.dunikey" && return 2
|
||||
[[ ! -d $homedir ]] && mkdir -p $homedir
|
||||
[[ -f /tmp/secret.dunikey ]] && rm -f $homedir/secret.dunikey && mv /tmp/secret.dunikey $homedir/secret.dunikey
|
||||
|
||||
echo -e "salt=\"$salt\"\npepper=\"$pepper\"\npubkey=\"$pubkey\"" > $homedir/db
|
||||
|
||||
# info_account $chan
|
||||
echo -e "Votre ḠCompte a bien été créé.\nPubkey: **$pubkey**"
|
||||
echo -e "Votre ḠCompte a bien été créé.\nPubkey: *$pubkey*"
|
||||
}
|
||||
|
||||
rm_account() {
|
||||
chanDB "$1"
|
||||
if [[ -d $homedir ]]; then
|
||||
local solde=$($silkaj balance $pubkey | grep "Total Quantitative" | awk -F= '{ print $2 }' | cut -c2- | awk '{ print $1 }')
|
||||
[[ "$solde" != "0.0" ]] && echo "Votre solde n'est pas nulle: $solde Ḡ1. Veuillez vider votre compte avant de pouvoir le supprimer." && return 2
|
||||
echo "Suppression des données de votre portefeuille de votre ḠBanque."
|
||||
echo -e "Login: **$salt**\nMot de passe: **$pepper**\nClé publique: **$pubkey**"
|
||||
echo -e "Login: *$salt*\nMot de passe: *$pepper*\nClé publique: *$pubkey*"
|
||||
rm -r $homedir
|
||||
echo "Suppression terminé, nous ne disposons plus d'aucune donnée vous concernant."
|
||||
else
|
||||
|
@ -121,27 +144,33 @@ rm_account() {
|
|||
}
|
||||
|
||||
tx() {
|
||||
chanDB "$1"
|
||||
local dest="$2"
|
||||
local dest1="$dest"
|
||||
local amount=$(echo "$3" | tr ',' '.')
|
||||
local comment="${@:4}"
|
||||
|
||||
! [[ $dest && $amount ]] && echo "Des arguments sont manquants. Ex: pay Do99s6wQR2JLfhirPdpAERSjNbmjjECzGxHNJMiNKT3p 10 Merci pour la tarte" && exit 0
|
||||
! [[ $dest && $amount ]] && echo "Des arguments sont manquants. Ex: pay Do99s6wQR2JLfhirPdpAERSjNbmjjECzGxHNJMiNKT3p 10 Merci pour la tarte" && return 2
|
||||
|
||||
#This shoudl works, but accents are ok and should not... [[ ! "$comment" =~ [^a-zA-Z0-9\ ] ]] && echo OK
|
||||
[[ "$comment" =~ [^abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/-?:'('')'.+\ ] ]] && echo "Votre commentaire contient des charactères non autorisés." && exit 0
|
||||
[[ "$comment" =~ [^abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/-?:'('')'.+\ ] ]] && echo "Votre commentaire contient des charactères non autorisés." && return 2
|
||||
[[ -z "$comment" ]] && local comment="Transaction effectuee avec BoG."
|
||||
[[ $amount =~ '-' ]] && echo "La somme de votre transaction ne peut être négative: **$amount** Ḡ1" && exit 0
|
||||
[[ $(echo $dest | wc -c) -le 43 ]] && local dest=$(getPubkey $dest)
|
||||
[[ $dest == "none" ]] && echo "Ce pseudo ne correspond à aucun membre Ḡ1 connu." && exit 0
|
||||
[[ $amount =~ '-' ]] && echo "La somme de votre transaction ne peut être négative: *$amount* Ḡ1" && return 2
|
||||
|
||||
[[ $(echo $dest | wc -c) -le 43 ]] && local dest=$(getPubkey $dest)
|
||||
[[ $dest == "none" ]] && echo "Ce pseudo n'a pas de clé Ḡ1 associé." && return 2
|
||||
|
||||
toolDest=$(echo $dest1 | awk -F '@' '{ print $2 }')
|
||||
chanDB "$1"
|
||||
sender="$chan@$tool"
|
||||
local result=$($silkaj --auth-file --file $homedir/secret.dunikey tx --amount $amount --output $dest --comment "$comment" -y)
|
||||
[[ -n $result ]] && echo "\`\`\`$result\`\`\`" || echo "Une erreur est survenu, votre transaction n'a pas été effecutée." && exit 0
|
||||
resultCode=$?
|
||||
[[ -n $result ]] && echo "\`\`\`$result\`\`\`" || (echo "Une erreur est survenu, votre transaction n'a pas été effecutée." && return 2)
|
||||
[[ ${dest1#?} =~ '@' && $result && $resultCode == '0' && $toolDest != "telegram" ]] && sendmsg $dest1 "Vous avez reçus un paiement de *$amount Ḡ1* de la part de *$sender*\nCommentaire: *$comment*" || true
|
||||
}
|
||||
|
||||
history_account() {
|
||||
chanDB "$1"
|
||||
sendmsg $chan "Récupération de l'historique de votre compte **$pubkey** ..."
|
||||
sendmsg $chan "Récupération de l'historique de votre compte *$pubkey* ..."
|
||||
local result=$($silkaj history $pubkey)
|
||||
echo "\`\`\`$result\`\`\`"
|
||||
}
|
||||
|
|
|
@ -10,29 +10,37 @@ source $MY_PATH/functions.sh
|
|||
|
||||
pubkey() {
|
||||
local args=$(echo $@ | tr ' ' '\n' | grep -vEw 'biz|G1LibreBot' | tr '\n' ' ')
|
||||
[ $(echo $args | wc -w) -ge 3 ] && local username=$(echo $args | awk '{ print $3 }') || local username=$1
|
||||
local username=$(echo $username | tr -d '@')
|
||||
local pubkey=$(getPubkey $@)
|
||||
[[ $pubkey ]] && echo "@$username Ta clé publique Ğ1 est: $pubkey" || echo "@$username n'est pas un pseudo membre de la Ḡ1"
|
||||
[ $(echo $args | wc -w) -ge 3 ] && local usernameK=$(echo $args | awk '{ print $3 }') || local usernameK=$1
|
||||
# local usernameK=$(echo $usernameK | tr -d '@')
|
||||
[[ ${usernameK::1} == '@' ]] && usernameK=${usernameK#?}
|
||||
local pubkey=$(getPubkey $args)
|
||||
[[ ${usernameK::1} != '#' ]] && usernameK="@$usernameK"
|
||||
[[ $pubkey == "none" ]] && echo "$usernameK n'a pas de clé Ḡ1 associé" || echo "$usernameK Ta clé publique Ğ1 est: *$pubkey*"
|
||||
}
|
||||
|
||||
# Get Ḡ1 pseudo base on pubkey
|
||||
pseudo() { getPseudo $@; }
|
||||
|
||||
silkaj() {
|
||||
args=$(echo "$@" | tr ' ' '\n' | grep -vEw 'silkaj|biz|G1LibreBot' | tr '\n' ' ')
|
||||
cmd=$(echo $args | tr ' ' '\n' | grep -v '-' | head -n1)
|
||||
local args=$(echo "$@" | tr ' ' '\n' | grep -vEw 'silkaj|biz|G1LibreBot' | tr '\n' ' ')
|
||||
local cmd=$(echo $args | tr ' ' '\n' | grep -v '-' | head -n1)
|
||||
[[ $cmd =~ ^(tx|authfile|cert)$ ]] && echo "BoḠ refuse d'executer la commande \`$cmd\` ... :eyes:" && exit 0
|
||||
result=$($silkaj $args) || echo "Silkaj ne comprends cette commande."
|
||||
local result=$($silkaj $args) || echo "Silkaj ne comprends cette commande."
|
||||
echo "\`\`\`$result\`\`\`"
|
||||
}
|
||||
|
||||
membres() {
|
||||
url="$node/blockchain/current"
|
||||
local nbr_membres=$(curl -m 10 -s $url | jq '.membersCount')
|
||||
[[ $nbr_membres ]] && echo "Il y a actuellement $nbr_membres membres de la Ğ1 !" || echo "Service en maintenance, réessayez dans un instant :coffee:"
|
||||
local url="$node/blockchain/current"
|
||||
local nbr_membres=$(curl -m 10 -s $url | jq '.membersCount')
|
||||
[[ $nbr_membres ]] && echo "Il y a actuellement $nbr_membres membres de la Ğ1 !" || echo "Service en maintenance, réessayez dans un instant :coffee:"
|
||||
}
|
||||
|
||||
deb() {
|
||||
local usernameK=$1
|
||||
local cmd=$3
|
||||
sleep 2
|
||||
echo -e "coucou $usernameK\ncmd: *$cmd*"
|
||||
}
|
||||
|
||||
[[ $(type $@ | grep "est une fonction") ]] && $@ || echo "Veuillez préciser votre commande"
|
||||
|
||||
|
|
|
@ -18,7 +18,9 @@ remove() { rm_account "$dest"; }
|
|||
info() { info_account "$dest"; }
|
||||
pay() { tx "$dest" $args; }
|
||||
history() { history_account "$dest"; }
|
||||
mp() { sendmsg "$user" "$args"; }
|
||||
|
||||
[[ "$cmd" =~ ^(init|remove|info|pay|history)$ ]] && "$cmd" || echo "Veuillez indiquer une commande valide"
|
||||
[[ "$cmd" =~ ^(init|remove|info|pay|history|mp)$ ]] && "$cmd"
|
||||
[[ $? == 1 ]] && echo "Veuillez indiquer une commande valide"
|
||||
|
||||
exit 0
|
||||
|
|
Reference in New Issue