From 9a679b03e57d565748c33a9037114eb567981956 Mon Sep 17 00:00:00 2001 From: Andrei Kurilov <18027129+akurilov@users.noreply.github.com> Date: Mon, 27 May 2024 11:40:00 +0300 Subject: [PATCH] feat: rework donations [skip ci] --- main.go | 2 ++ service/donation.go | 19 ++++++++++++++++++- service/support/support.go | 4 ++++ service/usage/limits.go | 2 +- 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index d400cfa..3a3b3bd 100644 --- a/main.go +++ b/main.go @@ -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) @@ -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) }) // diff --git a/service/donation.go b/service/donation.go index bcf2bda..a0a0343 100644 --- a/service/donation.go +++ b/service/donation.go @@ -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{ @@ -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 } diff --git a/service/support/support.go b/service/support/support.go index dac3ab7..32a86bb 100644 --- a/service/support/support.go +++ b/service/support/support.go @@ -2,6 +2,7 @@ package support import ( "fmt" + "github.com/awakari/bot-telegram/service" "gopkg.in/telebot.v3" ) @@ -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 } diff --git a/service/usage/limits.go b/service/usage/limits.go index d51067b..ab8f9f2 100644 --- a/service/usage/limits.go +++ b/service/usage/limits.go @@ -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