Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
akurilov committed Nov 16, 2023
1 parent 4b5943f commit a252fd9
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 156 deletions.
24 changes: 8 additions & 16 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
},
Expand Down
60 changes: 0 additions & 60 deletions service/menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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,
Expand Down
63 changes: 0 additions & 63 deletions service/messages/details.go

This file was deleted.

2 changes: 1 addition & 1 deletion service/messages/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions service/messages/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion service/subscriptions/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
}
}
Expand Down
15 changes: 0 additions & 15 deletions service/subscriptions/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a252fd9

Please sign in to comment.