tooltip factor messages (#59)

* tooltip factor messages
* init user if not inited
This commit is contained in:
LightningTipBot 2021-09-10 10:16:49 +02:00 committed by GitHub
parent a19fa50bb8
commit 8af08357d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 10 deletions

View file

@ -27,7 +27,7 @@ const (
lnurlInvalidAmountMessage = "🚫 Invalid amount."
lnurlInvalidAmountRangeMessage = "🚫 Amount must be between %d and %d sat."
lnurlNoUsernameMessage = "🚫 You need to set a Telegram username to receive via LNURL."
lnurlEnterAmountMessage = "Please enter an amount."
lnurlEnterAmountMessage = "⌨️ Please enter an amount."
lnurlHelpText = "📖 Oops, that didn't work. %s\n\n" +
"*Usage:* `/lnurl [amount] <lnurl>`\n" +
"*Example:* `/lnurl LNURL1DP68GUR...`"

View file

@ -22,7 +22,7 @@ func (bot TipBot) anyTextHandler(m *tb.Message) {
// check if user is in database, if not, initialize wallet
user, exists := bot.UserExists(m.Sender)
if !exists {
if !exists || !user.Initialized {
bot.startHandler(m)
return
}

View file

@ -17,6 +17,14 @@ import (
tb "gopkg.in/tucnak/telebot.v2"
)
const (
tooltipChatWithBotMessage = "🗑 Chat with %s 👈 to manage your wallet."
tooltipAndOthersMessage = " ... and others"
tooltipMultipleTipsMessage = "%s (%d tips by %s)"
tooltipSingleTipMessage = "%s (by %s)"
tooltipTipAmountMessage = "🏅 %d sat"
)
type TipTooltip struct {
Message
TipAmount int `json:"tip_amount"`
@ -57,15 +65,15 @@ func NewTipTooltip(m *tb.Message, opts ...TipTooltipOption) *TipTooltip {
// getUpdatedTipTooltipMessage will return the full tip tool tip
func (ttt TipTooltip) getUpdatedTipTooltipMessage(botUserName string, notInitializedWallet bool) string {
tippersStr := getTippersString(ttt.Tippers)
tipToolTipMessage := fmt.Sprintf("🏅 %d sat", ttt.TipAmount)
tipToolTipMessage := fmt.Sprintf(tooltipTipAmountMessage, ttt.TipAmount)
if len(ttt.Tippers) > 1 {
tipToolTipMessage = fmt.Sprintf("%s (%d tips by %s)", tipToolTipMessage, ttt.Ntips, tippersStr)
tipToolTipMessage = fmt.Sprintf(tooltipMultipleTipsMessage, tipToolTipMessage, ttt.Ntips, tippersStr)
} else {
tipToolTipMessage = fmt.Sprintf("%s (by %s)", tipToolTipMessage, tippersStr)
tipToolTipMessage = fmt.Sprintf(tooltipSingleTipMessage, tipToolTipMessage, tippersStr)
}
if notInitializedWallet {
tipToolTipMessage = tipToolTipMessage + fmt.Sprintf("\n🗑 Chat with %s to manage your wallet.", botUserName)
tipToolTipMessage = tipToolTipMessage + fmt.Sprintf("\n%s", fmt.Sprintf(tooltipChatWithBotMessage, botUserName))
}
return tipToolTipMessage
}
@ -86,7 +94,7 @@ func getTippersString(tippers []*tb.User) string {
if len(tippersSlice) > maxNamesInTipperMessage {
// tippersStr = tippersStr[:50]
tippersStr = strings.Join(tippersSlice[:maxNamesInTipperMessage], " ")
tippersStr = tippersStr + " ... and others"
tippersStr = tippersStr + tooltipAndOthersMessage
}
return tippersStr
}
@ -115,12 +123,12 @@ func tipTooltipHandler(m *tb.Message, bot *TipBot, amount int, initializedWallet
return false
}
} else {
tipmsg := fmt.Sprintf("🏅 %d sat", amount)
tipmsg := fmt.Sprintf(tooltipTipAmountMessage, amount)
userStr := GetUserStrMd(m.Sender)
tipmsg = fmt.Sprintf("%s (by %s)", tipmsg, userStr)
tipmsg = fmt.Sprintf(tooltipSingleTipMessage, tipmsg, userStr)
if !initializedWallet {
tipmsg = tipmsg + fmt.Sprintf("\n🗑 Chat with %s to manage your wallet.", GetUserStrMd(bot.telegram.Me))
tipmsg = tipmsg + fmt.Sprintf("\n%s", fmt.Sprintf(tooltipChatWithBotMessage, GetUserStrMd(bot.telegram.Me)))
}
msg, err := bot.telegram.Reply(m.ReplyTo, tipmsg, tb.Silent)
if err != nil {