Compare commits

...
11 Commits
Author SHA1 Message Date
LightningTipBotandGitHub 3fe903bc51 Force start2 (#21)
* force-init only on / commands

* return statemet

* anytext handler in all commands

* comment

* warning

* get rid of init bot wallet error
2021-08-25 02:13:42 +02:00
LightningTipBotandGitHub 4bf0e05d6c force-init only on / commands (#20)
* force-init only on / commands

* return statemet
2021-08-25 01:24:31 +02:00
LightningTipBotandGitHub 3317cf09e1 force initialize user on PM (#19) 2021-08-24 23:54:24 +02:00
LightningTipBotandGitHub 13759ff048 Improve help (#15)
* help text

* log command

* comment

* improve help

* improved feedback

* hotfix new user creation (#17)

* improved feedback

* better help

* better help

* botfather commands
2021-08-24 01:41:10 +02:00
LightningTipBotandGitHub 827bfb108d hotfix new user creation (#17) 2021-08-23 20:46:57 +02:00
LightningTipBotandGitHub e2017ecfe9 Improve help (#14)
* improve help
2021-08-23 13:09:39 +02:00
LightningTipBot 059cb5cdd8 resize image 2021-08-23 00:46:49 +02:00
LightningTipBot 80d0ec57b1 Better readme 2021-08-23 00:32:57 +02:00
LightningTipBot 790f0943cc smaller image 2021-08-23 00:29:22 +02:00
LightningTipBot 4af2ca8799 qr code example 2021-08-23 00:22:04 +02:00
LightningTipBot 323fd14c9e Better readme 2021-08-23 00:15:22 +02:00
12 changed files with 105 additions and 48 deletions
+11 -5
View File
@@ -4,9 +4,9 @@
# @LightningTipBot 🏅
A tip bot and Lightning ⚡️ Bitcoin Wallet for Telegram group chats. It can also be used as a personal Lightning wallet by anyone who has a Telegram account.
A Telegram Lightning ⚡️ Bitcoin wallet and tip bot for group chats.
This repository contains everything you need to set up and run your own tip bot. If you simply want to use this bot in your group chat without having to install anything just start a conversation with [@LightningTipBot](https://t.me/LightningTipBot) and invite it into your chat.
This repository contains everything you need to set up and run your own tip bot. If you simply want to use this bot in your group chat without having to install anything just start a conversation with [@LightningTipBot](https://t.me/LightningTipBot) and invite it into your group chat.
## Setting up the bot
@@ -21,9 +21,7 @@ go build .
cp config.yaml-example config.yaml
```
Alternatively, you can download binary releases [here](https://github.com/LightningTipBot/LightningTipBot/releases) **(note: no realses yet)**.
After you have configured the bot, start it using the command
After the configuration (see below), start it using the command
```
./LightningTipBot
@@ -81,6 +79,14 @@ 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>
### Pay invoices by sending QR codes
To pay a Lightning invoice, you can snap a photo of a QR code and send it directly to the bot. Note that you might need to zoom in, center the QR code, or crop the image if the bot fails to decode the QR code from the photo. By the way, you can also just send an the invoice as a string, the bot will automatically detect it and initiate a payment.
<p align="center">
<img alt="QR code payment example." src="resources/qr_code_example.jpg" >
</p>
### Auto-delete commands
To minimize the clutter all the heavy tipping can cause in a group chat, the bot will remove all failed commands (for example due to a syntax error) from the chat immediately. All successful commands will stay visible for `message_dispose_duration` seconds (default 10s) and then be removed. The tips will sill be visible for everyone in the Live tooltip. This feature only works, if the bot is made admin of the group.
+2 -1
View File
@@ -9,7 +9,8 @@ import (
)
func (bot TipBot) balanceHandler(m *tb.Message) {
log.Infof("[%s:%d %s:%d] %s", m.Chat.Title, m.Chat.ID, GetUserStr(m.Sender), m.Sender.ID, m.Text)
// check and print all commands
bot.anyTextHandler(m)
// reply only in private message
if m.Chat.Type != tb.ChatPrivate {
// delete message
+4 -4
View File
@@ -7,7 +7,7 @@
help - Read the help.
balance - Check your balance.
tip - Reply to a message to tip it.
send - Send funds to a user.
invoice - Create a Lightning invoice to receive payments.
pay - Pay a Lightning invoice.
tip - Reply to a message to tip. Example: /tip 50
send - Send funds to a Telegram user. Example: /send 100 @LightningTipBot
invoice - Create a Lightning invoice to receive payments. Example: /invoice 1000
pay - Pay a Lightning invoice. Example: /pay lnbc10n1ps...
+15 -12
View File
@@ -1,21 +1,20 @@
package main
import (
log "github.com/sirupsen/logrus"
tb "gopkg.in/tucnak/telebot.v2"
)
const (
helpMessage = "ℹ️ *Info*\n_This bot sends Bitcoin tips on the Lightning Network⚡️. The basic unit of tips are Satoshis (sat). 100,000,000 sat = 1 Bitcoin. There will only ever be 21 Million Bitcoin._\n\n" +
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" +
"❤️ *Donate*\n" +
"_This bot charges no fees but generates costs. If you like to support this bot, please consider a donation. To donate, just tip @LightningTipBot or try_ `/send 1000 @LightningTipBot`\n\n" +
"_This bot charges no fees but costs satoshis to operate. If you like the bot, please consider supporting it with a donation. To donate, just tip @LightningTipBot or try_ `/send 1000 @LightningTipBot`\n\n" +
"⚙️ *Commands*\n" +
"*/tip* 🏅 Reply to a message to tip it: `/tip <amount> [<memo>]`\n" +
"*/balance* 👑 Check your balance: `/balance`\n" +
"*/send* 💸 Send funds to a user: `/send <amount> <@username> [<memo>]`\n" +
"*/tip* 🏅 Reply to a message to tip: `/tip <amount> [<memo>]`\n" +
"*/balance* 👑 Check balance: `/balance`\n" +
"*/send* 💸 Send funds to a Telegram user: `/send <amount> <@user> [<memo>]`\n" +
"*/invoice* ⚡️ Receive over Lightning: `/invoice <amount> [<memo>]`\n" +
"*/pay* ⚡️ Pay over Lightning: `/pay <invoice>`\n" +
"*/help* 📖 Read this help (more: */info*).\n"
"*/help* 📖 Read this help.\n"
infoMessage = "🧡 *Bitcoin*\n" +
"_Bitcoin is the currency of the internet. It is permissionless and decentralized and has no masters and no controling authority. Bitcoin is sound money that is faster, more secure, and more inclusive than the legacy financial system._\n\n" +
@@ -24,17 +23,20 @@ const (
"⚡️ *The Lightning Network*\n" +
"_The Lightning Network is a payment protocol that enables fast and cheap Bitcoin payments that require almost no energy. It is what scales Bitcoin to the billions of people around the world._\n\n" +
"📲 *Lightning Wallets*\n" +
"_Your funds on this bot can be sent to any other Lightning wallet and vice versa. If you don't have a Lightning wallet yet, check out_ [Phoenix](https://phoenix.acinq.co/)_,_ [Breez](https://breez.technology/)_,_ [Muun](https://muun.com/)_ (non-custodial), or_ [Wallet of Satoshi](https://www.walletofsatoshi.com/) _(easy)_.\n\n" +
"_Your funds on this bot can be sent to any other Lightning wallet and vice versa. Recommended Lightning wallets for your phone are_ [Phoenix](https://phoenix.acinq.co/)_,_ [Breez](https://breez.technology/)_,_ [Muun](https://muun.com/)_ (non-custodial), or_ [Wallet of Satoshi](https://www.walletofsatoshi.com/) _(easy)_.\n\n" +
"📄 *Open Source*\n" +
"_This bot is free and_ [open source](https://github.com/LightningTipBot/LightningTipBot) _software. You can run it on your own computer and use it in your own community. You don't have to trust anyone to keep your funds safe._\n\n" +
"_This bot is free and_ [open source](https://github.com/LightningTipBot/LightningTipBot) _software. You can run it on your own computer and use it in your own community._\n\n" +
"✈️ *Telegram*\n" +
"_Add this bot to your Telegram group chat to /tip posts. If you make the bot admin of the group it will also clean up commands to keep the chat tidy._\n\n" +
// "🏛 *Terms*\n" +
// "_We are not custodian of your funds. Any amount you load onto your wallet will be legally considered a donation that belongs to us. We will act in your best interest but we're also aware that the situation without KYC is tricky until we figure something out. Do not give us all your money. Be aware that this bot is in beta development. Use at your own risk._\n\n" +
"❤️ *Donate*\n" +
"_This bot charges no fees but generates costs. If you like to support this bot, please consider a donation. To donate, just tip @LightningTipBot or try_ `/send 1000 @LightningTipBot`"
"_This bot charges no fees but costs satoshis to operate. If you like the bot, please consider supporting it with a donation. To donate, just tip @LightningTipBot or try_ `/send 1000 @LightningTipBot`"
)
func (bot TipBot) helpHandler(m *tb.Message) {
log.Infof("[%s:%d %s:%d] %s", m.Chat.Title, m.Chat.ID, GetUserStr(m.Sender), m.Sender.ID, m.Text)
// check and print all commands
bot.anyTextHandler(m)
if !m.Private() {
// delete message
NewMessage(m).Dispose(0, bot.telegram)
@@ -44,7 +46,8 @@ func (bot TipBot) helpHandler(m *tb.Message) {
}
func (bot TipBot) infoHandler(m *tb.Message) {
log.Infof("[%s:%d %s:%d] %s", m.Chat.Title, m.Chat.ID, GetUserStr(m.Sender), m.Sender.ID, m.Text)
// check and print all commands
bot.anyTextHandler(m)
if !m.Private() {
// delete message
NewMessage(m).Dispose(0, bot.telegram)
+25 -7
View File
@@ -12,26 +12,44 @@ import (
tb "gopkg.in/tucnak/telebot.v2"
)
func helpInvoiceUsage(errormsg string) string {
helpstr := "📖 Oops, that didn't work. %s\n\n" +
const (
invoiceEnterAmountMessage = "Did you enter an amount?"
invoiceValidAmountMessage = "Did you enter a valid amount?"
invoiceHelpText = "📖 Oops, that didn't work. %s\n\n" +
"*Usage:* `/invoice <amount> [<memo>]`\n" +
"*Example:* `/invoice 1000 Take this! 💸`"
)
func helpInvoiceUsage(errormsg string) string {
if len(errormsg) > 0 {
helpstr = fmt.Sprintf(helpstr, fmt.Sprintf("_%s_", errormsg))
return fmt.Sprintf(invoiceHelpText, fmt.Sprintf("%s", errormsg))
} else {
helpstr = fmt.Sprintf(helpstr, "")
return fmt.Sprintf(invoiceHelpText, "")
}
return helpstr
}
// func helpInvoiceUsage(errormsg string) string {
// helpstr := "📖 Oops, that didn't work. %s\n\n" +
// "*Usage:* `/invoice <amount> [<memo>]`\n" +
// "*Example:* `/invoice 1000 Take this! 💸`"
// if len(errormsg) > 0 {
// helpstr = fmt.Sprintf(helpstr, fmt.Sprintf("%s", errormsg))
// } else {
// helpstr = fmt.Sprintf(helpstr, "")
// }
// return helpstr
// }
func (bot TipBot) invoiceHandler(m *tb.Message) {
// check and print all commands
bot.anyTextHandler(m)
if m.Chat.Type != tb.ChatPrivate {
// delete message
NewMessage(m).Dispose(0, bot.telegram)
return
}
if len(strings.Split(m.Text, " ")) < 2 {
bot.telegram.Send(m.Sender, helpInvoiceUsage(""))
bot.telegram.Send(m.Sender, helpInvoiceUsage(invoiceEnterAmountMessage))
return
}
@@ -43,7 +61,7 @@ func (bot TipBot) invoiceHandler(m *tb.Message) {
}
if amount > 0 {
} else {
bot.telegram.Send(m.Sender, helpInvoiceUsage("Did you use a valid amount?"))
bot.telegram.Send(m.Sender, helpInvoiceUsage(invoiceValidAmountMessage))
return
}
+2 -1
View File
@@ -37,7 +37,8 @@ func helpPayInvoiceUsage(errormsg string) string {
// confirmPaymentHandler invoked on "/pay lnbc..." command
func (bot TipBot) confirmPaymentHandler(m *tb.Message) {
log.Infof("[%s:%d %s:%d] %s", m.Chat.Title, m.Chat.ID, GetUserStr(m.Sender), m.Sender.ID, m.Text)
// check and print all commands
bot.anyTextHandler(m)
if m.Chat.Type != tb.ChatPrivate {
// delete message
NewMessage(m).Dispose(0, bot.telegram)
Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

+4 -3
View File
@@ -12,7 +12,7 @@ import (
)
const (
sendValidAmountMessage = "Did you use a valid amount?"
sendValidAmountMessage = "Did you enter a valid amount?"
sendUserNotFoundMessage = "User %s could not be found. You can /send only to Telegram tags like @%s."
sendIsNotAUsser = "🚫 %s is not a username. You can /send only to Telegram tags like @%s."
sendUserHasNoWalletMessage = "🚫 User %s hasn't created a wallet yet."
@@ -21,7 +21,7 @@ const (
sendErrorMessage = "🚫 Transaction failed: %s"
confirmSendInvoiceMessage = "Do you want to pay to %s?\n\n💸 Amount: %d sat"
confirmSendAppendMemo = "\n✉️ %s"
sendCancelledMessage = "🚫 Sending cancelled."
sendCancelledMessage = "🚫 Send cancelled."
errorTryLaterMessage = "🚫 Internal error. Please try again later.."
sendHelpText = "📖 Oops, that didn't work. %s\n\n" +
"*Usage:* `/send <amount> <user> [<memo>]`\n" +
@@ -52,7 +52,8 @@ func SendCheckSyntax(m *tb.Message) (bool, string) {
// confirmPaymentHandler invoked on "/send 123 @user" command
func (bot *TipBot) confirmSendHandler(m *tb.Message) {
log.Infof("[%s:%d %s:%d] %s", m.Chat.Title, m.Chat.ID, GetUserStr(m.Sender), m.Sender.ID, m.Text)
// check and print all commands
bot.anyTextHandler(m)
// If the send is a reply, then trigger /tip handler
if m.IsReply() {
bot.tipHandler(m)
+14 -2
View File
@@ -15,6 +15,7 @@ import (
const (
startSettingWalletMessage = "🧮 Setting up your wallet..."
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."
)
@@ -22,18 +23,22 @@ func (bot TipBot) startHandler(m *tb.Message) {
if !m.Private() {
return
}
bot.helpHandler(m)
// 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)
if err != nil {
log.Errorln(fmt.Sprintf("[startHandler] Error with initWallet: %s", err.Error()))
bot.telegram.Edit(walletCreationMsg, startWalletErrorMessage)
return
}
bot.telegram.Edit(walletCreationMsg, startWalletReadyMessage)
bot.balanceHandler(m)
// send the user a warning about the fact that they need to set a username
if len(m.Sender.Username) == 0 {
bot.telegram.Send(m.Sender, startNoUsernameMessage, tb.NoPreview)
}
@@ -55,6 +60,7 @@ func (bot TipBot) initWallet(tguser *tb.User) error {
return err
}
} else if !user.Initialized {
// update all tip tooltips (with the "initialize me" message) that this user might have received before
tipTooltipInitializedHandler(user.Telegram, bot)
user.Initialized = true
err = UpdateUserRecord(user, bot)
@@ -62,6 +68,12 @@ func (bot TipBot) initWallet(tguser *tb.User) error {
log.Errorln(fmt.Sprintf("[initWallet] error updating user: %s", err.Error()))
return err
}
} else if user.Initialized {
// wallet is already initialized
return nil
} else {
err = fmt.Errorf("could not initialize wallet")
return err
}
return nil
}
+14 -1
View File
@@ -1,22 +1,35 @@
package main
import (
log "github.com/sirupsen/logrus"
"strings"
log "github.com/sirupsen/logrus"
"github.com/LightningTipBot/LightningTipBot/pkg/lightning"
tb "gopkg.in/tucnak/telebot.v2"
)
const (
initWalletMessage = "You don't have a wallet yet. Enter */start*"
)
func (bot TipBot) anyTextHandler(m *tb.Message) {
log.Infof("[%s:%d %s:%d] %s", m.Chat.Title, m.Chat.ID, GetUserStr(m.Sender), m.Sender.ID, m.Text)
if m.Chat.Type != tb.ChatPrivate {
return
}
// check if user is in database, if not, initialize wallet
if !bot.UserHasWallet(m.Sender) {
bot.startHandler(m)
return
}
// could be an invoice
invoiceString := strings.ToLower(m.Text)
if lightning.IsInvoice(invoiceString) {
m.Text = "/pay " + invoiceString
bot.confirmPaymentHandler(m)
return
}
}
+7 -6
View File
@@ -11,12 +11,12 @@ import (
)
const (
tipDidYouReplyMessage = "Did you reply to a message to tip? To reply to a message, right-click -> Reply on your computer or swipe the message on your phone."
tipDidYouReplyMessage = "Did you reply to a message to tip? To reply to any message, right-click -> Reply on your computer or swipe the message on your phone. If you want to send directly to another Telegram user's wallet, use the /send command."
tipEnterAmountMessage = "Did you enter an amount?"
tipValidAmountMessage = "Did you use a valid amount?"
tipValidAmountMessage = "Did you enter a valid amount?"
tipYourselfMessage = "📖 You can't tip yourself."
tipSentMessage = "💸 %d sat sent to %s."
tipReceivedMessage = "🏅 You've received a %d sat tip from %s."
tipReceivedMessage = "🏅 %s has tipped you %d sat."
tipErrorMessage = "🚫 Transaction failed: %s"
tipHelpText = "📖 Oops, that didn't work. %s\n\n" +
"*Usage:* `/tip <amount> [<memo>]`\n" +
@@ -40,7 +40,8 @@ func TipCheckSyntax(m *tb.Message) (bool, string) {
}
func (bot *TipBot) tipHandler(m *tb.Message) {
log.Infof("[%s:%d %s:%d] %s", m.Chat.Title, m.Chat.ID, GetUserStr(m.Sender), m.Sender.ID, m.Text)
// check and print all commands
bot.anyTextHandler(m)
// only if message is a reply
if !m.IsReply() {
NewMessage(m).Dispose(0, bot.telegram)
@@ -83,7 +84,7 @@ func (bot *TipBot) tipHandler(m *tb.Message) {
if !bot.UserHasWallet(to) {
log.Infof("[/tip] User %s has no wallet.", toUserStr)
err = bot.CreateWalletForUser(to)
err = bot.CreateWalletForTelegramUser(to)
if err != nil {
errmsg := fmt.Errorf("[/tip] Error: Could not create wallet for %s", toUserStr)
log.Errorln(errmsg)
@@ -138,7 +139,7 @@ func (bot *TipBot) tipHandler(m *tb.Message) {
if !messageHasTip {
bot.telegram.Forward(to, m.ReplyTo, tb.Silent)
}
bot.telegram.Send(to, fmt.Sprintf(tipReceivedMessage, amount, fromUserStrMd))
bot.telegram.Send(to, fmt.Sprintf(tipReceivedMessage, fromUserStrMd, amount))
if len(tipMemo) > 0 {
bot.telegram.Send(to, fmt.Sprintf("✉️ %s", MarkdownEscape(tipMemo)))
+7 -6
View File
@@ -5,6 +5,7 @@ import (
"fmt"
"strings"
"github.com/LightningTipBot/LightningTipBot/internal/lnbits"
log "github.com/sirupsen/logrus"
tb "gopkg.in/tucnak/telebot.v2"
@@ -94,13 +95,13 @@ func (bot *TipBot) GetUserBalance(user *tb.User) (amount int, err error) {
return
}
func (bot *TipBot) CreateWalletForUser(tbUser *tb.User) error {
user, err := GetUser(tbUser, *bot)
func (bot *TipBot) CreateWalletForTelegramUser(tbUser *tb.User) error {
user := &lnbits.User{Telegram: tbUser}
userStr := GetUserStr(tbUser)
log.Printf("[CreateWalletForUser] Creating wallet for user %s ... ", userStr)
err = bot.createWallet(user)
log.Printf("[CreateWalletForTelegramUser] Creating wallet for user %s ... ", userStr)
err := bot.createWallet(user)
if err != nil {
errmsg := fmt.Sprintf("[CreateWalletForUser] Error: Could not create wallet for user %s", userStr)
errmsg := fmt.Sprintf("[CreateWalletForTelegramUser] Error: Could not create wallet for user %s", userStr)
log.Errorln(errmsg)
return err
}
@@ -108,7 +109,7 @@ func (bot *TipBot) CreateWalletForUser(tbUser *tb.User) error {
if tx.Error != nil {
return tx.Error
}
log.Printf("[CreateWalletForUser] Wallet created for user %s. ", userStr)
log.Printf("[CreateWalletForTelegramUser] Wallet created for user %s. ", userStr)
return nil
}