Skip to content

Commit

Permalink
feat: rework donations [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
akurilov committed May 27, 2024
1 parent 0e61782 commit 9a679b0
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ func main() {
case telebot.ChatSuperGroup:
err = subListHandlerFunc(tgCtx)
case telebot.ChatPrivate:
err = service.DonationMessagePin(tgCtx)
err = subListHandlerFunc(tgCtx)
default:
err = fmt.Errorf("unsupported chat type (supported options: \"private\", \"group\", \"supergroup\"): %s", chat.Type)
Expand Down Expand Up @@ -323,6 +324,7 @@ func main() {
return chanPostHandler.Publish(tgCtx)
})
b.Handle(telebot.OnAddedToGroup, func(tgCtx telebot.Context) error {
err = service.DonationMessagePin(tgCtx)
return service.ErrorHandlerFunc(subListHandlerFunc)(tgCtx)
})
//
Expand Down
19 changes: 18 additions & 1 deletion service/donation.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@ import (
"strconv"
)

const donationDefaultMsgTxt = "Help Awakari to be free"

func DonationHandler(ctx telebot.Context) (err error) {
_, err = DonationMessage(ctx, donationDefaultMsgTxt)
return
}

func DonationMessage(ctx telebot.Context, msgTxt string) (msg *telebot.Message, err error) {
customerId := "tg___user_id=" + strconv.FormatInt(ctx.Sender().ID, 10) + "%40awakari.com"
link := "https://donate.stripe.com/14k7uCaYq5befN65kk?prefilled_email=" + customerId
return ctx.Send("Donate", telebot.ReplyMarkup{
msg, err = ctx.Bot().Send(ctx.Chat(), msgTxt, &telebot.ReplyMarkup{
InlineKeyboard: [][]telebot.InlineButton{
{
telebot.InlineButton{
Expand All @@ -18,4 +25,14 @@ func DonationHandler(ctx telebot.Context) (err error) {
},
},
})
return
}

func DonationMessagePin(ctx telebot.Context) (err error) {
var msg *telebot.Message
msg, err = DonationMessage(ctx, donationDefaultMsgTxt)
if err == nil {
err = ctx.Bot().Pin(msg)
}
return
}
4 changes: 4 additions & 0 deletions service/support/support.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package support

import (
"fmt"
"github.com/awakari/bot-telegram/service"
"gopkg.in/telebot.v3"
)

Expand All @@ -18,5 +19,8 @@ func (sh Handler) Request(tgCtx telebot.Context, args ...string) (err error) {
},
})
err = tgCtxSupport.Send(fmt.Sprintf("Support request from @%s:\n%s", tgCtx.Sender().Username, args[len(args)-1]))
if err == nil {
_, err = service.DonationMessage(tgCtx, "Request support submitted and will be processed as soon as possible.")
}
return
}
2 changes: 1 addition & 1 deletion service/usage/limits.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func (lh LimitsHandler) HandleExtension(tgCtx telebot.Context, args ...string) (
err = lh.SupportHandler.Request(tgCtx, fmt.Sprintf("%s: uid: %s, %+v", PurposeLimitSet, userId, ol))
}
if err == nil {
_ = tgCtx.Send("Request submitted and will be processed it as soon as possible.")
_, _ = service.DonationMessage(tgCtx, "Request submitted and will be processed it as soon as possible.")
}
// TODO: uncomment the code below only when payments are in use
//var orderPayloadData []byte
Expand Down

0 comments on commit 9a679b0

Please sign in to comment.