diff --git a/main.go b/main.go index 2503548..10f4769 100644 --- a/main.go +++ b/main.go @@ -162,7 +162,7 @@ func main() { // init handlers groupId := cfg.Api.GroupId - menuKbd := service.MakeReplyKeyboard() // main menu keyboard + menuKbd := service.MakeMainMenu() supportHandler := support.Handler{ SupportChatId: cfg.Api.Telegram.SupportChatId, RestoreKbd: menuKbd, @@ -248,23 +248,15 @@ func main() { sources.CmdDelete: srcDeleteHandler.RequestConfirmation, } webappHandlers := map[string]service.ArgHandlerFunc{ - service.LabelPubMsgCustom: messages.PublishCustomHandlerFunc(clientAwk, groupId, svcMsgs, cfg.Payment), - service.LabelPub: messages.PublishCustomHandlerFunc(clientAwk, groupId, svcMsgs, cfg.Payment), - service.LabelSubCreateCustom: subscriptions.CreateCustomHandlerFunc(clientAwk, groupId), - service.LabelSub: subscriptions.CreateCustomHandlerFunc(clientAwk, groupId), - usage.LabelExtend: limitsHandler.HandleExtension, - messages.LabelPubAddSource: srcAddHandler.HandleFormData, - subscriptions.LabelCond: subCondHandler.Update, + service.LabelPub: messages.PublishCustomHandlerFunc(clientAwk, groupId, svcMsgs, cfg.Payment), + service.LabelSub: subscriptions.CreateCustomHandlerFunc(clientAwk, groupId), + usage.LabelExtend: limitsHandler.HandleExtension, + messages.LabelPubAddSource: srcAddHandler.HandleFormData, + subscriptions.LabelCond: subCondHandler.Update, } txtHandlers := map[string]telebot.HandlerFunc{ - service.LabelSubList: subscriptions.ListHandlerFunc(clientAwk, chatStor, groupId), - service.LabelSubCreateBasic: subscriptions.CreateBasicRequest, - service.LabelUsageSub: subscriptions.Usage(clientAwk, groupId), - service.LabelPublishing: messages.Details, - service.LabelPubMsgBasic: messages.PublishBasicRequest, - service.LabelPubs: pubUsageHandler.Show, - service.LabelSubs: subscriptions.Usage(clientAwk, groupId), - service.LabelUsagePub: pubUsageHandler.Show, + service.LabelPubs: pubUsageHandler.Show, + service.LabelSubs: subscriptions.Usage(clientAwk, groupId), service.LabelMainMenu: func(tgCtx telebot.Context) error { return tgCtx.Send("Main menu reply keyboard", menuKbd) }, diff --git a/service/menu.go b/service/menu.go index 4e6cfb6..aa8b99a 100644 --- a/service/menu.go +++ b/service/menu.go @@ -4,59 +4,12 @@ import ( "gopkg.in/telebot.v3" ) -const LabelSubList = "Subscriptions" -const LabelSubCreateBasic = "+ Basic" -const LabelSubCreateCustom = "+ Custom" -const LabelUsageSub = "Usage ˢ" -const LabelPublishing = "Publishing" -const LabelPubMsgBasic = "▷ Basic" -const LabelPubMsgCustom = "▷ Custom" -const LabelUsagePub = "Usage ᵖ" const LabelMainMenu = "< Main Menu" - const LabelPub = "📢 Publish" const LabelPubs = "Publishing >" const LabelSub = "🔍 Subscribe" const LabelSubs = "Subscriptions >" -var btnSubList = telebot.Btn{ - Text: LabelSubList, -} - -var btnSubNewBasic = telebot.Btn{ - Text: LabelSubCreateBasic, -} - -var btnSubNewCustom = telebot.Btn{ - Text: LabelSubCreateCustom, - WebApp: &telebot.WebApp{ - URL: "https://awakari.app/sub-new.html", - }, -} - -var btnUsageSub = telebot.Btn{ - Text: LabelUsageSub, -} - -var btnMsgs = telebot.Btn{ - Text: LabelPublishing, -} - -var btnMsgNewBasic = telebot.Btn{ - Text: LabelPubMsgBasic, -} - -var btnMsgNewCustom = telebot.Btn{ - Text: LabelPubMsgCustom, - WebApp: &telebot.WebApp{ - URL: "https://awakari.app/msg-new.html", - }, -} - -var btnUsagePub = telebot.Btn{ - Text: LabelUsagePub, -} - var btnPub = telebot.Btn{ Text: LabelPub, WebApp: &telebot.WebApp{ @@ -83,19 +36,6 @@ var BtnMainMenu = telebot.Btn{ Text: LabelMainMenu, } -func MakeReplyKeyboard() (kbd *telebot.ReplyMarkup) { - kbd = &telebot.ReplyMarkup{ - ResizeKeyboard: true, - } - kbd.Reply( - kbd.Row(btnSubList), - kbd.Row(btnSubNewBasic, btnSubNewCustom, btnUsageSub), - kbd.Row(btnMsgs), - kbd.Row(btnMsgNewBasic, btnMsgNewCustom, btnUsagePub), - ) - return -} - func MakeMainMenu() (kbd *telebot.ReplyMarkup) { kbd = &telebot.ReplyMarkup{ ResizeKeyboard: true, diff --git a/service/messages/details.go b/service/messages/details.go deleted file mode 100644 index e47ed9c..0000000 --- a/service/messages/details.go +++ /dev/null @@ -1,63 +0,0 @@ -package messages - -import ( - "github.com/awakari/bot-telegram/service" - "github.com/awakari/bot-telegram/service/sources" - "gopkg.in/telebot.v3" -) - -const LabelPubAddSource = "+ Own Source" - -var btnPubAddSource = telebot.Btn{ - Text: LabelPubAddSource, - WebApp: &telebot.WebApp{ - URL: "https://awakari.app/source-add.html", - }, -} - -func Details(tgCtx telebot.Context) (err error) { - if err == nil { - m := &telebot.ReplyMarkup{} - m.Inline( - m.Row( - telebot.Btn{ - Text: "Telegram - All", - Data: sources.CmdTgChListAll, - }, - telebot.Btn{ - Text: "Telegram - Own", - Data: sources.CmdTgChListOwn, - }, - ), - m.Row( - telebot.Btn{ - Text: "Feeds - All", - Data: sources.CmdFeedListAll, - }, - telebot.Btn{ - Text: "Feeds - Own", - Data: sources.CmdFeedListOwn, - }, - ), - m.Row( - telebot.Btn{ - Text: "Sites - All", - Data: sources.CmdSitesListAll, - }, - telebot.Btn{ - Text: "Sites - Own", - Data: sources.CmdSitesListOwn, - }, - ), - ) - err = tgCtx.Send("Sources:", m) - } - if err == nil { - m := &telebot.ReplyMarkup{ - ResizeKeyboard: true, - } - m.Reply(m.Row(service.BtnMainMenu, btnPubAddSource)) - err = tgCtx.Send("To add own source, use the corresponding reply keyboard button.", m) - } - return -} diff --git a/service/messages/publish.go b/service/messages/publish.go index d5e4c59..8a1cd1e 100644 --- a/service/messages/publish.go +++ b/service/messages/publish.go @@ -233,7 +233,7 @@ func publish( switch { case ackCount == 0 && errors.Is(err, limits.ErrReached): // ackCount, err = publishInvoice(tgCtx, evt, svcMsgs, cfgPayment, kbd) - err = errors.New(fmt.Sprintf("Message daily publishing limit reached. Consider to donate and increase your limit using the \"%s\" button in the main menu.", service.LabelUsagePub)) + err = errors.New(fmt.Sprintf("Message daily publishing limit reached. Consider to donate and increase your limit using the \"%s\" button in the main menu.", service.LabelPubs)) case ackCount == 1: if kbd == nil { err = tgCtx.Send(fmt.Sprintf(msgFmtPublished, evt.Id), telebot.ModeHTML) diff --git a/service/messages/usage.go b/service/messages/usage.go index 406aecb..9afd640 100644 --- a/service/messages/usage.go +++ b/service/messages/usage.go @@ -19,6 +19,15 @@ type UsageHandler struct { GroupId string } +const LabelPubAddSource = "+ Own Source" + +var btnPubAddSource = telebot.Btn{ + Text: LabelPubAddSource, + WebApp: &telebot.WebApp{ + URL: "https://awakari.app/source-add.html", + }, +} + func (uh UsageHandler) Show(tgCtx telebot.Context) (err error) { groupIdCtx := metadata.AppendToOutgoingContext(context.TODO(), "x-awakari-group-id", uh.GroupId) userId := strconv.FormatInt(tgCtx.Sender().ID, 10) diff --git a/service/subscriptions/create.go b/service/subscriptions/create.go index c416631..c90e96f 100644 --- a/service/subscriptions/create.go +++ b/service/subscriptions/create.go @@ -132,7 +132,7 @@ func create(tgCtx telebot.Context, clientAwk api.Client, groupId string, sd subs err = fmt.Errorf( "%w, consider to donate and increase limit using the button \"%s\" in the main keyboard", errLimitReached, - service.LabelUsageSub, + service.LabelSubs, ) } } diff --git a/service/subscriptions/list.go b/service/subscriptions/list.go index 43546c7..2d6ff5e 100644 --- a/service/subscriptions/list.go +++ b/service/subscriptions/list.go @@ -14,21 +14,6 @@ import ( const CmdPageNext = "subs_next" -const msgList = `Own subscriptions list. Select any to see the details and available actions:` - -func ListHandlerFunc(clientAwk api.Client, chatStor chats.Storage, groupId string) telebot.HandlerFunc { - return func(tgCtx telebot.Context) (err error) { - groupIdCtx := metadata.AppendToOutgoingContext(context.TODO(), "x-awakari-group-id", groupId) - userId := strconv.FormatInt(tgCtx.Sender().ID, 10) - var m *telebot.ReplyMarkup - m, err = listButtons(groupIdCtx, userId, clientAwk, chatStor, tgCtx.Chat().ID, CmdDetails, "") - if err == nil { - err = tgCtx.Send(msgList, m, telebot.ModeHTML) - } - return - } -} - func ListOnGroupStartHandlerFunc(clientAwk api.Client, chatStor chats.Storage, groupId string) telebot.HandlerFunc { return func(tgCtx telebot.Context) (err error) { groupIdCtx := metadata.AppendToOutgoingContext(context.TODO(), "x-awakari-group-id", groupId)