Skip to content

Commit

Permalink
Merge pull request #12 from massmux/dev
Browse files Browse the repository at this point in the history
enforced max balance
  • Loading branch information
massmux committed Jan 30, 2024
2 parents 0a16c49 + b5ca048 commit 29e23c9
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion config.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ nostr:
private_key: "hex private key here"
pos:
currency: "EUR"

max_balance: 1000000
3 changes: 2 additions & 1 deletion internal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ var Configuration = struct {
}{}

type PosConfiguration struct {
Currency string `yaml:"currency"`
Currency string `yaml:"currency"`
Max_balance int64 `yaml:"max_balance"`
}

type NostrConfiguration struct {
Expand Down
10 changes: 10 additions & 0 deletions internal/telegram/balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package telegram

import (
"fmt"
"github.com/LightningTipBot/LightningTipBot/internal"
"strconv"

"github.com/LightningTipBot/LightningTipBot/internal/errors"
"github.com/LightningTipBot/LightningTipBot/internal/telegram/intercept"
Expand Down Expand Up @@ -43,5 +45,13 @@ func (bot *TipBot) balanceHandler(ctx intercept.Context) (intercept.Context, err

log.Infof("[/balance] %s's balance: %d sat\n", usrStr, balance)
bot.trySendMessage(ctx.Sender(), fmt.Sprintf(Translate(ctx, "balanceMessage"), balance))

// check user balance. if more than Maximum allowed (in config) then send a warning message
if balance >= internal.Configuration.Pos.Max_balance {
balanceWarningMessage := fmt.Sprintf(Translate(ctx, "balanceOverMax"), strconv.FormatInt(internal.Configuration.Pos.Max_balance, 10))
bot.trySendMessage(ctx.Sender(), balanceWarningMessage)
log.Infof("[/balance] User %s over max balance: %d Sats\n", usrStr, balance)
}

return ctx, nil
}
6 changes: 6 additions & 0 deletions translations/en.toml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ startNoUsernameMessage = """☝️ It looks like you don't have a Telegram @u

balanceMessage = """👑 *Your balance:* %d sat"""
balanceErrorMessage = """🚫 Could not fetch your balance. Please try again later."""
balanceOverMax = """❗️ You are over max balance allowed. Please move funds out from your Wallet until reaching the maximum allowed balance. Maximum allowed balance is
*%s Sats*
You are required to keep your balance always below this threshold. Thank you for understanding.
"""

# TIP

Expand Down
7 changes: 7 additions & 0 deletions translations/fr.toml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ startNoUsernameMessage = """☝️ Vous n'avez pas encore de nom d'utilisateu

balanceMessage = """👑 *Votre solde:* %d sat"""
balanceErrorMessage = """🚫 Impossible de récupérer votre solde. Essayez à nouveau."""
balanceOverMax = """❗️ Vous avez dépassé le solde maximum autorisé. Veuillez retirer des fonds de votre Portefeuille jusqu'à ce que vous atteigniez le solde maximum autorisé. Le solde maximum autorisé est de
*%s Sats*
Vous êtes tenu de maintenir votre solde en permanence en dessous de ce seuil. Merci de votre compréhension.
"""


# TIP

Expand Down
7 changes: 7 additions & 0 deletions translations/it.toml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ startNoUsernameMessage = """☝️ Sembra che tu non abbia un nome utente Tel

balanceMessage = """👑 *Il tuo saldo è:* %d sat"""
balanceErrorMessage = """🚫 Non riesco a recupare il tuo saldo. Per favore riprova più tardi."""
balanceOverMax = """❗️ Il saldo massimo consentito è stato superato. Si prega di spostare i fondi dal portafoglio fino a raggiungere il saldo massimo consentito. Il saldo massimo consentito è
*%s Sats*
L'utente è tenuto a mantenere il saldo sempre al di sotto di questa soglia. Grazie per la comprensione.
"""


# TIP

Expand Down

0 comments on commit 29e23c9

Please sign in to comment.