diff --git a/internal/telegram/groups.go b/internal/telegram/groups.go index 370391a..4bed39c 100644 --- a/internal/telegram/groups.go +++ b/internal/telegram/groups.go @@ -84,18 +84,7 @@ var ( ) var ( - groupAddGroupHelpMessage = "📖 Oops, that didn't work. Please try again.\nUsage: `/group add []`\nExample: `/group add TheBestBitcoinGroup 1000`" - grouJoinGroupHelpMessage = "📖 Oops, that didn't work. Please try again.\nUsage: `/join `\nExample: `/join TheBestBitcoinGroup`" - groupClickToJoinMessage = "🎟 [Click here](%s) 👈 to join `%s`." - groupTicketIssuedGroupMessage = "🎟 User %s has received a ticket for this group." - groupInvoiceMemo = "Ticket for group %s" - groupPayInvoiceMessage = "🎟 To join the group %s, pay the invoice above." - groupBotIsNotAdminMessage = "🚫 Oops, that didn't work. You must make me admin and grant me rights to invite users." - groupNameExists = "🚫 A group with this name already exists. Please choose a different name." - groupAddedMessage = "🎟 Tickets for group `%s` added.\nAlias: `%s` Price: %d sat\n\nTo request a ticket for this group, start a private chat with %s and write `/join %s`." - groupNotFoundMessage = "🚫 Could not find a group with this name." - groupReceiveTicketInvoiceCommission = "🎟 You received *%d sat* (excl. %d sat commission) for a ticket for group `%s` paid by user %s." - groupReceiveTicketInvoice = "🎟 You received *%d sat* for a ticket for group `%s` paid by user %s." + groupInvoiceMemo = "Ticket for group %s" ) // groupHandler is called if the /group command is invoked. It then decides with other @@ -103,7 +92,15 @@ var ( func (bot TipBot) groupHandler(ctx intercept.Context) (intercept.Context, error) { m := ctx.Message() splits := strings.Split(m.Text, " ") + user := LoadUser(ctx) if len(splits) == 1 { + if ctx.Message().Private() { + bot.trySendMessage(ctx.Message().Chat, fmt.Sprintf(Translate(ctx, "groupHelpMessage"), GetUserStr(bot.Telegram.Me), GetUserStr(bot.Telegram.Me))) + } else { + if bot.isOwner(ctx.Message().Chat, user.Telegram) { + bot.trySendMessage(ctx.Message().Chat, fmt.Sprintf(Translate(ctx, "commandPrivateMessage"), GetUserStr(bot.Telegram.Me))) + } + } return ctx, nil } else if len(splits) > 1 { if splits[1] == "join" { @@ -136,7 +133,7 @@ func (bot TipBot) groupRequestJoinHandler(ctx intercept.Context) (intercept.Cont splitIdx = 0 } if len(splits) != splitIdx+2 || len(ctx.Message().Text) > 100 { - bot.trySendMessage(ctx.Message().Chat, grouJoinGroupHelpMessage) + bot.trySendMessage(ctx.Message().Chat, Translate(ctx, "groupJoinGroupHelpMessage")) return ctx, nil } groupName := strings.ToLower(splits[splitIdx+1]) @@ -144,7 +141,7 @@ func (bot TipBot) groupRequestJoinHandler(ctx intercept.Context) (intercept.Cont group := &Group{} tx := bot.GroupsDb.Where("name = ? COLLATE NOCASE", groupName).First(group) if tx.Error != nil { - bot.trySendMessage(ctx.Message().Chat, groupNotFoundMessage) + bot.trySendMessage(ctx.Message().Chat, Translate(ctx, "groupNotFoundMessage")) return ctx, fmt.Errorf("group not found") } @@ -209,7 +206,7 @@ func (bot TipBot) groupRequestJoinHandler(ctx intercept.Context) (intercept.Cont return ctx, err } ticketEvent.Message = bot.trySendMessage(ctx.Message().Sender, &tb.Photo{File: tb.File{FileReader: bytes.NewReader(qr)}, Caption: fmt.Sprintf("`%s`", invoiceEvent.PaymentRequest)}) - bot.trySendMessage(ctx.Message().Sender, fmt.Sprintf(groupPayInvoiceMessage, groupName)) + bot.trySendMessage(ctx.Message().Sender, fmt.Sprintf(Translate(ctx, "groupPayInvoiceMessage"), groupName)) return ctx, nil } @@ -324,10 +321,10 @@ func (bot *TipBot) groupGetInviteLinkHandler(event Event) { } // send confirmation text with the ticket to the user - bot.trySendMessage(ticketEvent.Payer.Telegram, fmt.Sprintf(groupClickToJoinMessage, resp.Result.InviteLink, ticketEvent.Group.Title)) + bot.trySendMessage(ticketEvent.Payer.Telegram, fmt.Sprintf(i18n.Translate(ticketEvent.LanguageCode, "groupClickToJoinMessage"), resp.Result.InviteLink, ticketEvent.Group.Title)) // send a notification to the group that sold the ticket - bot.trySendMessage(&tb.Chat{ID: ticketEvent.Group.ID}, fmt.Sprintf(groupTicketIssuedGroupMessage, GetUserStr(ticketEvent.Payer.Telegram))) + bot.trySendMessage(&tb.Chat{ID: ticketEvent.Group.ID}, fmt.Sprintf(i18n.Translate(ticketEvent.LanguageCode, "groupTicketIssuedGroupMessage"), GetUserStr(ticketEvent.Payer.Telegram))) // take a commission ticketSat := ticketEvent.Group.Ticket.Price @@ -360,7 +357,6 @@ func (bot *TipBot) groupGetInviteLinkHandler(event Event) { _, err = ticketEvent.User.Wallet.Pay(lnbits.PaymentParams{Out: true, Bolt11: invoice.PaymentRequest}, bot.Client) if err != nil { errmsg := fmt.Sprintf("[groupGetInviteLinkHandler] Could not pay commission of %s: %s", GetUserStr(ticketEvent.User.Telegram), err) - err = fmt.Errorf(i18n.Translate(ticketEvent.LanguageCode, "invoiceUndefinedErrorMessage")) log.Errorln(errmsg) return } @@ -370,23 +366,23 @@ func (bot *TipBot) groupGetInviteLinkHandler(event Event) { errmsg := fmt.Sprintf("could not get balance of user %s", GetUserStr(ticketEvent.Payer.Telegram)) log.Errorln(errmsg) } - bot.trySendMessage(ticketEvent.User.Telegram, fmt.Sprintf(groupReceiveTicketInvoiceCommission, ticketSat, commissionSat, ticketEvent.Group.Title, GetUserStr(ticketEvent.Payer.Telegram))) + bot.trySendMessage(ticketEvent.User.Telegram, fmt.Sprintf(i18n.Translate(ticketEvent.LanguageCode, "groupReceiveTicketInvoiceCommission"), ticketSat, commissionSat, ticketEvent.Group.Title, GetUserStr(ticketEvent.Payer.Telegram))) } else { - bot.trySendMessage(ticketEvent.User.Telegram, fmt.Sprintf(groupReceiveTicketInvoice, ticketSat, ticketEvent.Group.Title, GetUserStr(ticketEvent.Payer.Telegram))) + bot.trySendMessage(ticketEvent.User.Telegram, fmt.Sprintf(i18n.Translate(ticketEvent.LanguageCode, "groupReceiveTicketInvoice"), ticketSat, ticketEvent.Group.Title, GetUserStr(ticketEvent.Payer.Telegram))) } - return } // addGroupHandler is invoked if the user calls the "/group add" command func (bot TipBot) addGroupHandler(ctx intercept.Context) (intercept.Context, error) { m := ctx.Message() if m.Chat.Type == tb.ChatPrivate { + bot.trySendMessage(m.Chat, Translate(ctx, "groupAddGroupHelpMessage")) return ctx, fmt.Errorf("not in group") } // parse command "/group add []" splits := strings.Split(m.Text, " ") if len(splits) < 3 || len(m.Text) > 100 { - bot.trySendMessage(m.Chat, groupAddGroupHelpMessage) + bot.trySendMessage(m.Chat, Translate(ctx, "groupAddGroupHelpMessage")) return ctx, nil } groupName := strings.ToLower(splits[2]) @@ -398,7 +394,7 @@ func (bot TipBot) addGroupHandler(ctx intercept.Context) (intercept.Context, err } if !bot.isAdminAndCanInviteUsers(m.Chat, bot.Telegram.Me) { - bot.trySendMessage(m.Chat, groupBotIsNotAdminMessage) + bot.trySendMessage(m.Chat, Translate(ctx, "groupBotIsNotAdminMessage")) return ctx, fmt.Errorf("bot is not admin") } @@ -409,7 +405,7 @@ func (bot TipBot) addGroupHandler(ctx intercept.Context) (intercept.Context, err if tx.Error == nil { // if it is already added, check if this user is the admin if user.Telegram.ID != group.Owner.ID || group.ID != m.Chat.ID { - bot.trySendMessage(m.Chat, groupNameExists) + bot.trySendMessage(m.Chat, Translate(ctx, "groupNameExists")) return ctx, fmt.Errorf("not owner") } } @@ -443,7 +439,7 @@ func (bot TipBot) addGroupHandler(ctx intercept.Context) (intercept.Context, err bot.GroupsDb.Save(group) log.Infof("[group] Ticket of %d sat added to group %s.", group.Ticket.Price, group.Name) - bot.trySendMessage(m.Chat, fmt.Sprintf(groupAddedMessage, str.MarkdownEscape(m.Chat.Title), group.Name, group.Ticket.Price, GetUserStrMd(bot.Telegram.Me), group.Name)) + bot.trySendMessage(m.Chat, fmt.Sprintf(Translate(ctx, "groupAddedMessage"), str.MarkdownEscape(m.Chat.Title), group.Name, group.Ticket.Price, GetUserStrMd(bot.Telegram.Me), group.Name)) return ctx, nil } diff --git a/translations/de.toml b/translations/de.toml index 61c2b97..00582c0 100644 --- a/translations/de.toml +++ b/translations/de.toml @@ -121,7 +121,8 @@ advancedMessage = """%s */link* 🔗 Verbinde dein Wallet mit [BlueWallet](https://bluewallet.io/) oder [Zeus](https://zeusln.app/) */lnurl* ⚡️ Lnurl empfangen oder senden: `/lnurl` or `/lnurl ` */faucet* 🚰 Erzeuge einen Zapfhahn: `/faucet ` -*/tipjar* 🍯 Erzeuge eine Spendendose: `/tipjar `""" +*/tipjar* 🍯 Erzeuge eine Spendendose: `/tipjar ` +*/group* 🎟 Tickets für Gruppenchats: `/group add []`""" # GENERIC enterAmountRangeMessage = """⌨️ Gebe einen Betrag zwischen %d und %d sat ein.""" diff --git a/translations/en.toml b/translations/en.toml index 1580584..d75d956 100644 --- a/translations/en.toml +++ b/translations/en.toml @@ -124,7 +124,8 @@ advancedMessage = """%s */link* 🔗 Link your wallet to [BlueWallet](https://bluewallet.io/) or [Zeus](https://zeusln.app/) */lnurl* ⚡️ Lnurl receive or pay: `/lnurl` or `/lnurl ` */faucet* 🚰 Create a faucet: `/faucet ` -*/tipjar* 🍯 Create a tipjar: `/tipjar `""" +*/tipjar* 🍯 Create a tipjar: `/tipjar ` +*/group* 🎟 Create group tickets: `/group add []`""" # GENERIC enterAmountRangeMessage = """💯 Enter an amount between %d and %d sat.""" @@ -348,3 +349,36 @@ inlineTipjarHelpText = """📖 Oops, that didn't work. %s *Usage:* `/tipjar ` *Example:* `/tipjar 210 21`""" + +# GROUP TICKETS +groupAddGroupHelpMessage = """📖 Oops, that didn't work. This command only works in a group chat. Only group owners can use this command.\nUsage: `/group add []`\nExample: `/group add TheBestBitcoinGroup 1000`""" +groupJoinGroupHelpMessage = """📖 Oops, that didn't work. Please try again.\nUsage: `/join `\nExample: `/join TheBestBitcoinGroup`""" +groupClickToJoinMessage = """🎟 [Click here](%s) 👈 to join `%s`.""" +groupTicketIssuedGroupMessage = """🎟 User %s has received a ticket for this group.""" +groupPayInvoiceMessage = """🎟 To join the group %s, pay the invoice above.""" +groupBotIsNotAdminMessage = """🚫 Oops, that didn't work. You must make me admin and grant me rights to invite users.""" +groupNameExists = """🚫 A group with this name already exists. Please choose a different name.""" +groupAddedMessage = """🎟 Tickets for group `%s` added.\nAlias: `%s` Price: %d sat\n\nTo request a ticket for this group, start a private chat with %s and write `/join %s`.""" +groupNotFoundMessage = """🚫 Could not find a group with this name.""" +groupReceiveTicketInvoiceCommission = """🎟 You received *%d sat* (excl. %d sat commission) for a ticket for group `%s` paid by user %s.""" +groupReceiveTicketInvoice = """🎟 You received *%d sat* for a ticket for group `%s` paid by user %s.""" +commandPrivateMessage = """Please use this command in a private chat with %s.""" +groupHelpMessage = """🎟 Private group tickets 🎟 + +Sell tickets for your _private Group_ and get rid of spam bots. + +*Instructions for group admins:* + +1) Invite %s to your group and make it admin. +2) Make your group private. +3) In your group, you (the group owner) write `/group add []`. + +_Fees: The bot takes a 10%% +10 sat commission for cheap tickets. If the ticket is >= 1000 sat, the commission is 2%% + 100 sat._ + +*Instructions for group members:* + +To join a group, talk to %s and write in a private message `/join `. + +📖 *Usage:* +*For admins (in group chat):* `/group add []`\nExample: `/group add TheBestBitcoinGroup 1000` +*For users (in private chat):* `/join `\nExample: `/join TheBestBitcoinGroup`""" \ No newline at end of file diff --git a/translations/es.toml b/translations/es.toml index b7e8a50..4c901d6 100644 --- a/translations/es.toml +++ b/translations/es.toml @@ -120,7 +120,8 @@ advancedMessage = """%s */link* 🔗 Enlaza tu monedero a [ BlueWallet ](https://bluewallet.io/) o [ Zeus ](https://zeusln.app/) */lnurl* ⚡️ Lnurl recibir o pagar: `/lnurl` o `/lnurl ` */faucet* 🚰 Crear un grifo: `/faucet ` -*/tipjar* 🍯 Crear un tipjar: `/tipjar `""" +*/tipjar* 🍯 Crear un tipjar: `/tipjar ` +*/group* 🎟 Create group tickets: `/group add []`""" # GENERIC enterAmountRangeMessage = """💯 Introduce un monto entre %d y %d sat.""" diff --git a/translations/fr.toml b/translations/fr.toml index cffcbf8..af81265 100644 --- a/translations/fr.toml +++ b/translations/fr.toml @@ -120,7 +120,8 @@ advancedMessage = """%s */link* 🔗 Lier votre wallet à [BlueWallet](https://bluewallet.io/) ou [Zeus](https://zeusln.app/) */lnurl* ⚡️ Lnurl recevoir ou payer: `/lnurl` ou `/lnurl ` */faucet* 🚰 Créer un faucet: `/faucet ` -*/tipjar* 🍯 Créer un tipjar: `/tipjar `""" +*/tipjar* 🍯 Créer un tipjar: `/tipjar ` +*/group* 🎟 Create group tickets: `/group add []`""" # GENERIC enterAmountRangeMessage = """💯 Choisissez un montant entre %d et %d sat.""" diff --git a/translations/id.toml b/translations/id.toml index 1d40ae4..272cb28 100644 --- a/translations/id.toml +++ b/translations/id.toml @@ -120,7 +120,8 @@ advancedMessage = """%s */link* 🔗 Menghubungkan dompet mu ke [BlueWallet](https://bluewallet.io/) atau [Zeus](https://zeusln.app/) */lnurl* ⚡️ Lnurl menerima atau membayar: `/lnurl` atau `/lnurl ` */faucet* 🚰 Membuat sebuah keran `/faucet ` -*/tipjar* 🍯 Create a tipjar: `/tipjar `""" +*/tipjar* 🍯 Create a tipjar: `/tipjar ` +*/group* 🎟 Create group tickets: `/group add []`""" # GENERIC enterAmountRangeMessage = """💯 Masukkan jumlah diantara %d dan %d sat.""" diff --git a/translations/it.toml b/translations/it.toml index 72be578..b771f0a 100644 --- a/translations/it.toml +++ b/translations/it.toml @@ -120,7 +120,8 @@ advancedMessage = """%s */link* 🔗 Crea un collegamento al tuo wallet [BlueWallet](https://bluewallet.io/) o [Zeus](https://zeusln.app/) */lnurl* ⚡️ Ricevi o paga un Lnurl: `/lnurl` or `/lnurl ` */faucet* 🚰 Crea una distribuzione: `/faucet ` -*/tipjar* 🍯 Crea un tipjar: `/tipjar `""" +*/tipjar* 🍯 Crea un tipjar: `/tipjar ` +*/group* 🎟 Create group tickets: `/group add []`""" # GENERIC enterAmountRangeMessage = """💯 Imposta un ammontare tra %d e %d sat.""" diff --git a/translations/nl.toml b/translations/nl.toml index 3308561..12bd567 100644 --- a/translations/nl.toml +++ b/translations/nl.toml @@ -120,7 +120,8 @@ advancedMessage = """%s */link* 🔗 Koppel uw wallet aan [BlueWallet](https://bluewallet.io/) of [Zeus](https://zeusln.app/) */lnurl* ⚡️ Lnurl ontvangen of betalen: `/lnurl` of `/lnurl ` */faucet* 🚰 Maak een kraan: `/faucet ` -*/tipjar* 🍯 Maak een tipjar: `/tipjar `""" +*/tipjar* 🍯 Maak een tipjar: `/tipjar ` +*/group* 🎟 Create group tickets: `/group add []`""" # GENERIC enterAmountRangeMessage = """💯 Voer een bedrag in tussen %d en %d sat.""" diff --git a/translations/pt-br.toml b/translations/pt-br.toml index 8706659..51ad6fa 100644 --- a/translations/pt-br.toml +++ b/translations/pt-br.toml @@ -120,7 +120,8 @@ advancedMessage = """%s */link* 🔗 Vincule sua carteira a [ BlueWallet ](https://bluewallet.io/) ou [ Zeus ](https://zeusln.app/) */lnurl* ⚡️ Receber ou pagar com lnurl: `/lnurl` o `/lnurl ` */faucet* 🚰 Criar uma torneira: `/faucet ` -*/tipjar* 🍯 Criar uma tipjar: `/tipjar `""" +*/tipjar* 🍯 Criar uma tipjar: `/tipjar ` +*/group* 🎟 Create group tickets: `/group add []`""" # GENERIC enterAmountRangeMessage = """💯 Insira uma quantia entre %d e %d sat.""" diff --git a/translations/ru.toml b/translations/ru.toml index 50db436..1027133 100644 --- a/translations/ru.toml +++ b/translations/ru.toml @@ -124,7 +124,8 @@ advancedMessage = """%s */link* 🔗 Link your wallet to [BlueWallet](https://bluewallet.io/) or [Zeus](https://zeusln.app/) */lnurl* Получить или оплатить через ⚡️Lnurl: `/lnurl` or `/lnurl ` */faucet* 🚰 Создать криптораздачу: `/faucet <ёмкость> <на_пользователя>` -*/tipjar* 🍯 Создать копилку: `/tipjar <ёмкость> <на_пользователя>`""" +*/tipjar* 🍯 Создать копилку: `/tipjar <ёмкость> <на_пользователя>` +*/group* 🎟 Create group tickets: `/group add []`""" # GENERIC enterAmountRangeMessage = """💯 Введите количество между %d и %d sat.""" diff --git a/translations/tr.toml b/translations/tr.toml index 7e98456..92e06e0 100644 --- a/translations/tr.toml +++ b/translations/tr.toml @@ -120,7 +120,8 @@ advancedMessage = """%s */link* 🔗 Cüzdanını bağla: [BlueWallet](https://bluewallet.io/) veya [Zeus](https://zeusln.app/) */lnurl* ⚡️ Lnurl iste veya gönder: `/lnurl` veya `/lnurl ` */faucet* 🚰 Bir fıçı oluştur: `/faucet ` -*/tipjar* 🍯 Bir tipjar oluştur: `/tipjar `""" +*/tipjar* 🍯 Bir tipjar oluştur: `/tipjar ` +*/group* 🎟 Create group tickets: `/group add []`""" # GENERIC enterAmountRangeMessage = """💯 %d ve %d sat arasında bir miktar gir."""