Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
794c2503e4 | ||
|
|
839b535b73 | ||
|
|
cb36e84216 |
@@ -80,6 +80,10 @@ The bot replies to a tipped message to indicate to all participants how many and
|
||||
<img alt="How to set up a lnbits wallet and the User Manager extension." src="resources/tooltips.png" >
|
||||
</p>
|
||||
|
||||
### Lightning Address
|
||||
|
||||
Every user has a [Lightning Address](https://lightningaddress.com/) a la `username@host.com` with which they can receive funds from other wallets. For this to work, you need to set the `lnurl_public_server` in `config.yaml`. The bot will then host a LNURL endpoint at `.well-known/lnurlp/username` which handles the data exchange with other wallets.
|
||||
|
||||
### Link to BlueWallet or Zap
|
||||
|
||||
Every user can link their wallet to an external app like [Bluewallet](https://bluewallet.io/) or [Zeus](https://zeusln.app/) by using the command `/link`. If you host the bot, you will have to enable the LndHub extension in LNbits. You also need to edit the `lnbits_public_url` entry in `config.yaml` accordingly to an address that can be reached by the user's wallet (Tor should be fine as well).
|
||||
|
||||
+4
-2
@@ -49,9 +49,10 @@ func GetUser(u *tb.User, bot TipBot) (*lnbits.User, error) {
|
||||
}()
|
||||
var err error
|
||||
go func() {
|
||||
if !reflect.DeepEqual(u, user.Telegram) {
|
||||
u_cp := bot.copyLowercaseUser(u)
|
||||
if !reflect.DeepEqual(u_cp, user.Telegram) {
|
||||
// update possibly changed user details in database
|
||||
user.Telegram = u
|
||||
user.Telegram = u_cp
|
||||
err = UpdateUserRecord(user, bot)
|
||||
if err != nil {
|
||||
log.Warnln(fmt.Sprintf("[UpdateUserRecord] %s", err.Error()))
|
||||
@@ -62,6 +63,7 @@ func GetUser(u *tb.User, bot TipBot) (*lnbits.User, error) {
|
||||
}
|
||||
|
||||
func UpdateUserRecord(user *lnbits.User, bot TipBot) error {
|
||||
user.Telegram = bot.copyLowercaseUser(user.Telegram)
|
||||
tx := bot.database.Save(user)
|
||||
if tx.Error != nil {
|
||||
errmsg := fmt.Sprintf("[UpdateUserRecord] Error: Couldn't update %s's info in database.", GetUserStr(user.Telegram))
|
||||
|
||||
@@ -1,13 +1,19 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
tb "gopkg.in/tucnak/telebot.v2"
|
||||
)
|
||||
|
||||
const (
|
||||
helpMessage = "ℹ️ *Info*\n_This bot is a Bitcoin Lightning ⚡️ wallet that can sends tips on Telegram. To tip, add the bot to a group chat. The basic unit of tips are Satoshis (sat). 100,000,000 sat = 1 Bitcoin. There will only ever be 21 Million Bitcoin. Type /info for more._\n\n" +
|
||||
helpMessage = "⚡️ *Wallet*\n_This bot is a Bitcoin Lightning wallet that can sends tips on Telegram. To tip, add the bot to a group chat. The basic unit of tips are Satoshis (sat). 100,000,000 sat = 1 Bitcoin. There will only ever be 21 Million Bitcoin. Type /info for more._\n\n" +
|
||||
"❤️ *Donate*\n" +
|
||||
"_This bot charges no fees but costs satoshis to operate. If you like the bot, please consider supporting this project with a donation. To donate, use_ `/donate 1000`\n\n" +
|
||||
"%s" +
|
||||
"⚙️ *Commands*\n" +
|
||||
"*/tip* 🏅 Reply to a message to tip: `/tip <amount> [<memo>]`\n" +
|
||||
"*/balance* 👑 Check balance: `/balance`\n" +
|
||||
@@ -35,10 +41,24 @@ const (
|
||||
"❤️ *Donate*\n" +
|
||||
"_This bot charges no fees but costs satoshis to operate. If you like the bot, please consider supporting this project with a donation. To donate, use_ `/donate 1000`"
|
||||
|
||||
helpNoUsernameMessage = "ℹ️ You don't have a Telegram username yet."
|
||||
|
||||
advancedMessage = "🤖 *Advanced commands*\n\n" +
|
||||
"*/link* 🔗 Link your wallet to [BlueWallet](https://bluewallet.io/) or [Zeus](https://zeusln.app/)\n"
|
||||
)
|
||||
|
||||
func (bot TipBot) makeHelpMessage(m *tb.Message) string {
|
||||
host, _, err := net.SplitHostPort(strings.Split(Configuration.LNURLServer, "//")[1])
|
||||
if err != nil {
|
||||
log.Errorf("[makeHelpMessage] Error: %s", err)
|
||||
return fmt.Sprintf(helpMessage, "")
|
||||
}
|
||||
if err != nil || len(m.Sender.Username) == 0 {
|
||||
return fmt.Sprintf(helpMessage, fmt.Sprintf("%s\n\n", helpNoUsernameMessage))
|
||||
}
|
||||
return fmt.Sprintf(helpMessage, fmt.Sprintf("ℹ️ *Info*\nYour Lightning Address is `%s@%s`\n\n", strings.ToLower(m.Sender.Username), host))
|
||||
}
|
||||
|
||||
func (bot TipBot) helpHandler(m *tb.Message) {
|
||||
// check and print all commands
|
||||
bot.anyTextHandler(m)
|
||||
@@ -46,7 +66,7 @@ func (bot TipBot) helpHandler(m *tb.Message) {
|
||||
// delete message
|
||||
NewMessage(m).Dispose(0, bot.telegram)
|
||||
}
|
||||
bot.telegram.Send(m.Sender, helpMessage, tb.NoPreview)
|
||||
bot.telegram.Send(m.Sender, bot.makeHelpMessage(m), tb.NoPreview)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -144,7 +144,7 @@ func (w Server) serveLNURLpFirst(writer http.ResponseWriter, request *http.Reque
|
||||
func (w Server) serveLNURLpSecond(writer http.ResponseWriter, request *http.Request) {
|
||||
vars := mux.Vars(request)
|
||||
user := &lnbits.User{}
|
||||
tx := w.database.Where("telegram_username = ?", vars["username"]).First(user)
|
||||
tx := w.database.Where("telegram_username = ?", strings.ToLower(vars["username"])).First(user)
|
||||
if tx.Error != nil || user.Wallet == nil || user.Initialized == false {
|
||||
errmsg := fmt.Sprintf("[GetUser] Couldn't fetch user info from database.")
|
||||
log.Warnln(errmsg)
|
||||
|
||||
@@ -127,7 +127,7 @@ func (bot *TipBot) confirmSendHandler(m *tb.Message) {
|
||||
}
|
||||
|
||||
toUserDb := &lnbits.User{}
|
||||
tx := bot.database.Where("telegram_username = ?", toUserStrWithoutAt).First(toUserDb)
|
||||
tx := bot.database.Where("telegram_username = ?", strings.ToLower(toUserStrWithoutAt)).First(toUserDb)
|
||||
if tx.Error != nil || toUserDb.Wallet == nil || toUserDb.Initialized == false {
|
||||
NewMessage(m).Dispose(0, bot.telegram)
|
||||
errmsg := fmt.Sprintf(sendUserHasNoWalletMessage, MarkdownEscape(toUserStrMention))
|
||||
|
||||
@@ -14,9 +14,10 @@ import (
|
||||
|
||||
const (
|
||||
startSettingWalletMessage = "🧮 Setting up your wallet..."
|
||||
startWalletCreatedMessage = "🧮 Wallet created."
|
||||
startWalletReadyMessage = "✅ *Your wallet is ready.*"
|
||||
startWalletErrorMessage = "🚫 Error initializing your wallet. Try again later."
|
||||
startNoUsernameMessage = "☝️ It looks like you don't have a Telegram @username yet. That's ok, you don't need one to use this bot. However, to make better use of your wallet, set up a username in the [Telegram settings](https://telegram.org/faq#q-what-are-usernames-how-do-i-get-one). Then, enter /balance so the bot can update its record of you."
|
||||
startNoUsernameMessage = "☝️ It looks like you don't have a Telegram @username yet. That's ok, you don't need one to use this bot. However, to make better use of your wallet, set up a username in the Telegram settings. Then, enter /balance so the bot can update its record of you."
|
||||
)
|
||||
|
||||
func (bot TipBot) startHandler(m *tb.Message) {
|
||||
@@ -26,7 +27,6 @@ func (bot TipBot) startHandler(m *tb.Message) {
|
||||
// ATTENTION: DO NOT CALL ANY HANDLER BEFORE THE WALLET IS CREATED
|
||||
// WILL RESULT IN AN ENDLESS LOOP OTHERWISE
|
||||
// bot.helpHandler(m)
|
||||
bot.telegram.Send(m.Sender, helpMessage, tb.NoPreview)
|
||||
log.Printf("[/start] User: %s (%d)\n", m.Sender.Username, m.Sender.ID)
|
||||
walletCreationMsg, err := bot.telegram.Send(m.Sender, startSettingWalletMessage)
|
||||
err = bot.initWallet(m.Sender)
|
||||
@@ -35,7 +35,10 @@ func (bot TipBot) startHandler(m *tb.Message) {
|
||||
bot.telegram.Edit(walletCreationMsg, startWalletErrorMessage)
|
||||
return
|
||||
}
|
||||
bot.telegram.Edit(walletCreationMsg, startWalletReadyMessage)
|
||||
bot.telegram.Delete(walletCreationMsg)
|
||||
|
||||
bot.helpHandler(m)
|
||||
bot.telegram.Send(m.Sender, startWalletReadyMessage)
|
||||
bot.balanceHandler(m)
|
||||
|
||||
// send the user a warning about the fact that they need to set a username
|
||||
|
||||
@@ -95,8 +95,15 @@ func (bot *TipBot) GetUserBalance(user *tb.User) (amount int, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (bot *TipBot) copyLowercaseUser(u *tb.User) *tb.User {
|
||||
u_cp := *u
|
||||
u_cp.Username = strings.ToLower(u.Username)
|
||||
return &u_cp
|
||||
}
|
||||
|
||||
func (bot *TipBot) CreateWalletForTelegramUser(tbUser *tb.User) error {
|
||||
user := &lnbits.User{Telegram: tbUser}
|
||||
u_cp := bot.copyLowercaseUser(tbUser)
|
||||
user := &lnbits.User{Telegram: u_cp}
|
||||
userStr := GetUserStr(tbUser)
|
||||
log.Printf("[CreateWalletForTelegramUser] Creating wallet for user %s ... ", userStr)
|
||||
err := bot.createWallet(user)
|
||||
|
||||
Reference in New Issue
Block a user