gbanque work on multicanal
This commit is contained in:
parent
ca3a901105
commit
b4c023fa80
|
@ -6,14 +6,19 @@ const util = require('util')
|
|||
bot.global.text({
|
||||
starts: ['./gbanque', 'biz ./gbanque', 'biz gb', 'gb']
|
||||
}, (b) => {
|
||||
username = b.message.user.name
|
||||
process.env.hb_username = username
|
||||
tool="axiomchat"
|
||||
room = b.message.user.room.name
|
||||
process.env.hb_room = room
|
||||
cmd = b.message.text
|
||||
process.env.hb_cmd = cmd
|
||||
process.env.hb_cmd = b.message.text
|
||||
|
||||
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) {
|
||||
b.respond("Une erreur est survenu: " + stderr)
|
||||
} else {
|
||||
|
|
|
@ -7,21 +7,34 @@ MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
|
|||
|
||||
# Globals variables
|
||||
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
|
||||
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
|
||||
}
|
||||
|
||||
# Send a message
|
||||
sendmsg() {
|
||||
chanDB $1
|
||||
chanDB "$1"
|
||||
[[ ! "$chan" == '#|@'* ]] && chan="@$chan"
|
||||
local msg="${@:2}"
|
||||
|
||||
[[ ! $chan || ! $msg ]] && echo "Please select user and message." && exit 0
|
||||
|
||||
curl -s -H "X-Auth-Token: $API_TOKEN" \
|
||||
-H "X-User-Id: $API_ID" \
|
||||
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
|
||||
|
@ -46,7 +59,7 @@ getPseudo() {
|
|||
}
|
||||
|
||||
getPassword() {
|
||||
chanDB $1
|
||||
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 \
|
||||
|
@ -57,7 +70,7 @@ Calcul du solde de votre compte en cours ..."
|
|||
}
|
||||
|
||||
info_account() {
|
||||
chanDB $1
|
||||
chanDB "$1"
|
||||
if [[ -d $homedir ]]; then
|
||||
sendmsg $chan "Récupération de votre solde en cours sur **$pubkey** ..."
|
||||
|
||||
|
@ -69,7 +82,7 @@ info_account() {
|
|||
}
|
||||
|
||||
init_account() {
|
||||
chanDB $1
|
||||
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**"
|
||||
|
@ -96,7 +109,7 @@ init_account() {
|
|||
}
|
||||
|
||||
rm_account() {
|
||||
chanDB $1
|
||||
chanDB "$1"
|
||||
if [[ -d $homedir ]]; then
|
||||
echo "Suppression des données de votre portefeuille de votre ḠBanque."
|
||||
echo -e "Login: **$salt**\nMot de passe: **$pepper**\nClé publique: **$pubkey**"
|
||||
|
@ -108,7 +121,7 @@ rm_account() {
|
|||
}
|
||||
|
||||
tx() {
|
||||
chanDB $1
|
||||
chanDB "$1"
|
||||
local dest="$2"
|
||||
local amount=$(echo "$3" | tr ',' '.')
|
||||
local comment="${@:4}"
|
||||
|
@ -122,12 +135,12 @@ tx() {
|
|||
[[ $(echo $dest | wc -c) -le 43 ]] && local dest=$(getPubkey $dest)
|
||||
[[ $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
|
||||
}
|
||||
|
||||
history_account() {
|
||||
chanDB $1
|
||||
chanDB "$1"
|
||||
sendmsg $chan "Récupération de l'historique de votre compte **$pubkey** ..."
|
||||
local result=$($silkaj history $pubkey)
|
||||
echo "\`\`\`$result\`\`\`"
|
||||
|
|
|
@ -5,30 +5,19 @@ MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
|
|||
|
||||
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 }')
|
||||
args=$(echo "$args" | awk '{$1=""; print $0}')
|
||||
user=$(echo "$@" | awk -F '~~~' '{ print $3 }')
|
||||
room=$(echo "$@" | awk -F '~~~' '{ print $4 }')
|
||||
user=$(echo "$@" | awk -F '~~~' '{ print $2 }')
|
||||
room=$(echo "$@" | awk -F '~~~' '{ print $3 }')
|
||||
|
||||
[[ $room == "undefined" ]] && dest="@$user" || dest="#$room"
|
||||
[[ $room == "undefined" ]] && dest="$user" || dest="#$room"
|
||||
|
||||
init() {
|
||||
## Récupération depuis Ḡ1SMS
|
||||
## ./shell/sms_NEW.sh "$PHONE" "$MEMBERUID" &
|
||||
## ./silkaj/silkaj generate_auth_file --auth-scrypt -salt="$PHONE" -password="$PIN"
|
||||
|
||||
# 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; }
|
||||
init() { 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"
|
||||
|
||||
|
|
Reference in New Issue