gbanque work on multicanal
This commit is contained in:
parent
ca3a901105
commit
b4c023fa80
|
@ -6,14 +6,19 @@ const util = require('util')
|
||||||
bot.global.text({
|
bot.global.text({
|
||||||
starts: ['./gbanque', 'biz ./gbanque', 'biz gb', 'gb']
|
starts: ['./gbanque', 'biz ./gbanque', 'biz gb', 'gb']
|
||||||
}, (b) => {
|
}, (b) => {
|
||||||
username = b.message.user.name
|
tool="axiomchat"
|
||||||
process.env.hb_username = username
|
|
||||||
room = b.message.user.room.name
|
room = b.message.user.room.name
|
||||||
process.env.hb_room = room
|
process.env.hb_cmd = b.message.text
|
||||||
cmd = b.message.text
|
|
||||||
process.env.hb_cmd = cmd
|
|
||||||
|
|
||||||
gbanque = exec("src/shell/gbanque.sh ~~~$hb_cmd~~~$hb_username~~~$hb_room", function(err, stdout, stderr) {
|
if (typeof room === 'undefined' || room === null) {
|
||||||
|
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_room = room + "@" + tool
|
||||||
|
}
|
||||||
|
|
||||||
|
gbanque = exec("src/shell/gbanque.sh $hb_cmd~~~$hb_username~~~$hb_room", function(err, stdout, stderr) {
|
||||||
if (err) {
|
if (err) {
|
||||||
b.respond("Une erreur est survenu: " + stderr)
|
b.respond("Une erreur est survenu: " + stderr)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -7,21 +7,34 @@ MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
|
||||||
|
|
||||||
# Globals variables
|
# Globals variables
|
||||||
chanDB() {
|
chanDB() {
|
||||||
chan="$1"
|
if [[ "$1" =~ '@' ]]; then
|
||||||
|
chan=$(echo "$1" | awk -F '@' '{ print $1 }')
|
||||||
|
tool=$(echo "$1" | awk -F '@' '{ print $2 }')
|
||||||
|
else
|
||||||
|
chan="$1"
|
||||||
|
fi
|
||||||
[[ ! $chan ]] && echo "Please select user." && exit 0
|
[[ ! $chan ]] && echo "Please select user." && exit 0
|
||||||
homedir="$HOME/.bog/ids/axiomchat/$chan"
|
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"
|
||||||
[[ -f $homedir/db ]] && source $homedir/db
|
[[ -f $homedir/db ]] && source $homedir/db
|
||||||
}
|
}
|
||||||
|
|
||||||
# Send a message
|
# Send a message
|
||||||
sendmsg() {
|
sendmsg() {
|
||||||
chanDB $1
|
chanDB "$1"
|
||||||
|
[[ ! "$chan" == '#|@'* ]] && chan="@$chan"
|
||||||
local msg="${@:2}"
|
local msg="${@:2}"
|
||||||
|
|
||||||
[[ ! $chan || ! $msg ]] && echo "Please select user and message." && exit 0
|
[[ ! $chan || ! $msg ]] && echo "Please select user and message." && exit 0
|
||||||
|
|
||||||
curl -s -H "X-Auth-Token: $API_TOKEN" \
|
curl -s -H "X-Auth-Token: $AC_API_TOKEN" \
|
||||||
-H "X-User-Id: $API_ID" \
|
-H "X-User-Id: $AC_API_ID" \
|
||||||
-H "Content-type:application/json" \
|
-H "Content-type:application/json" \
|
||||||
$API_URL/api/v1/chat.postMessage \
|
$API_URL/api/v1/chat.postMessage \
|
||||||
-d "{ \"channel\": \"$chan\", \"text\": \"$msg\" }" > /dev/null 2>&1
|
-d "{ \"channel\": \"$chan\", \"text\": \"$msg\" }" > /dev/null 2>&1
|
||||||
|
@ -46,7 +59,7 @@ getPseudo() {
|
||||||
}
|
}
|
||||||
|
|
||||||
getPassword() {
|
getPassword() {
|
||||||
chanDB $1
|
chanDB "$1"
|
||||||
if [[ -d $homedir ]]; then
|
if [[ -d $homedir ]]; then
|
||||||
sendmsg $chan "Voici les identifiants de connexion de votre ḠCompte: \n \
|
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 \
|
||||||
|
@ -57,7 +70,7 @@ Calcul du solde de votre compte en cours ..."
|
||||||
}
|
}
|
||||||
|
|
||||||
info_account() {
|
info_account() {
|
||||||
chanDB $1
|
chanDB "$1"
|
||||||
if [[ -d $homedir ]]; then
|
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** ..."
|
||||||
|
|
||||||
|
@ -69,7 +82,7 @@ info_account() {
|
||||||
}
|
}
|
||||||
|
|
||||||
init_account() {
|
init_account() {
|
||||||
chanDB $1
|
chanDB "$1"
|
||||||
if [[ -f $homedir/secret.dunikey ]]; then
|
if [[ -f $homedir/secret.dunikey ]]; then
|
||||||
pubkey=$(cat $homedir/secret.dunikey| grep "pub: " | awk '{ print $2 }')
|
pubkey=$(cat $homedir/secret.dunikey| grep "pub: " | awk '{ print $2 }')
|
||||||
echo "Vous disposez déjà d'un portefeuille Ḡ1: **$pubkey**"
|
echo "Vous disposez déjà d'un portefeuille Ḡ1: **$pubkey**"
|
||||||
|
@ -96,7 +109,7 @@ init_account() {
|
||||||
}
|
}
|
||||||
|
|
||||||
rm_account() {
|
rm_account() {
|
||||||
chanDB $1
|
chanDB "$1"
|
||||||
if [[ -d $homedir ]]; then
|
if [[ -d $homedir ]]; then
|
||||||
echo "Suppression des données de votre portefeuille de votre ḠBanque."
|
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**"
|
||||||
|
@ -108,7 +121,7 @@ rm_account() {
|
||||||
}
|
}
|
||||||
|
|
||||||
tx() {
|
tx() {
|
||||||
chanDB $1
|
chanDB "$1"
|
||||||
local dest="$2"
|
local dest="$2"
|
||||||
local amount=$(echo "$3" | tr ',' '.')
|
local amount=$(echo "$3" | tr ',' '.')
|
||||||
local comment="${@:4}"
|
local comment="${@:4}"
|
||||||
|
@ -122,12 +135,12 @@ tx() {
|
||||||
[[ $(echo $dest | wc -c) -le 43 ]] && local dest=$(getPubkey $dest)
|
[[ $(echo $dest | wc -c) -le 43 ]] && local dest=$(getPubkey $dest)
|
||||||
[[ $dest == "none" ]] && echo "Ce pseudo ne correspond à aucun membre Ḡ1 connu." && exit 0
|
[[ $dest == "none" ]] && echo "Ce pseudo ne correspond à aucun membre Ḡ1 connu." && exit 0
|
||||||
|
|
||||||
local result=$($silkaj --auth-file --file ~/.bog/ids/axiomchat/$chan/secret.dunikey tx --amount $amount --output $dest --comment "$comment" -y)
|
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
|
[[ -n $result ]] && echo "\`\`\`$result\`\`\`" || echo "Une erreur est survenu, votre transaction n'a pas été effecutée." && exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
history_account() {
|
history_account() {
|
||||||
chanDB $1
|
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)
|
local result=$($silkaj history $pubkey)
|
||||||
echo "\`\`\`$result\`\`\`"
|
echo "\`\`\`$result\`\`\`"
|
||||||
|
|
|
@ -5,30 +5,19 @@ MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
|
||||||
|
|
||||||
source $MY_PATH/functions.sh
|
source $MY_PATH/functions.sh
|
||||||
|
|
||||||
args=$(echo "$@" | awk -F '~~~' '{ print $2 }' | tr ' ' '\n' | grep -vEwi 'gbanque|gb|biz|G1LibreBot' | tr '\n' ' ')
|
args=$(echo "$@" | awk -F '~~~' '{ print $1 }' | tr ' ' '\n' | grep -vEwi 'gbanque|gb|biz|G1LibreBot' | tr '\n' ' ')
|
||||||
cmd=$(echo "$args" | awk '{ print $1 }')
|
cmd=$(echo "$args" | awk '{ print $1 }')
|
||||||
args=$(echo "$args" | awk '{$1=""; print $0}')
|
args=$(echo "$args" | awk '{$1=""; print $0}')
|
||||||
user=$(echo "$@" | awk -F '~~~' '{ print $3 }')
|
user=$(echo "$@" | awk -F '~~~' '{ print $2 }')
|
||||||
room=$(echo "$@" | awk -F '~~~' '{ print $4 }')
|
room=$(echo "$@" | awk -F '~~~' '{ print $3 }')
|
||||||
|
|
||||||
[[ $room == "undefined" ]] && dest="@$user" || dest="#$room"
|
[[ $room == "undefined" ]] && dest="$user" || dest="#$room"
|
||||||
|
|
||||||
init() {
|
init() { init_account "$dest"; }
|
||||||
## Récupération depuis Ḡ1SMS
|
remove() { rm_account "$dest"; }
|
||||||
## ./shell/sms_NEW.sh "$PHONE" "$MEMBERUID" &
|
info() { info_account "$dest"; }
|
||||||
## ./silkaj/silkaj generate_auth_file --auth-scrypt -salt="$PHONE" -password="$PIN"
|
pay() { tx "$dest" $args; }
|
||||||
|
history() { history_account "$dest"; }
|
||||||
# echo "Cette conversation continue en privé @$user - @biz"
|
|
||||||
|
|
||||||
## TODO: Définir le workflow g1sms
|
|
||||||
init_account $dest
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
remove() { rm_account $dest; }
|
|
||||||
info() { info_account $dest; }
|
|
||||||
pay() { tx $dest $args; }
|
|
||||||
history() { history_account $dest; }
|
|
||||||
|
|
||||||
[[ "$cmd" =~ ^(init|remove|info|pay|history)$ ]] && "$cmd" || echo "Veuillez indiquer une commande valide"
|
[[ "$cmd" =~ ^(init|remove|info|pay|history)$ ]] && "$cmd" || echo "Veuillez indiquer une commande valide"
|
||||||
|
|
||||||
|
|
Reference in New Issue