/
active_all.go
63 lines (50 loc) 路 1.41 KB
/
active_all.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package handler
import (
"context"
"fmt"
tb "gopkg.in/telebot.v3"
"github.com/andatoshiki/toshiki-rssbot/internal/bot/session"
"github.com/andatoshiki/toshiki-rssbot/internal/core"
)
type ActiveAll struct {
core *core.Core
}
func NewActiveAll(core *core.Core) *ActiveAll {
return &ActiveAll{core: core}
}
func (a *ActiveAll) Command() string {
return "/activeall"
}
func (a *ActiveAll) Description() string {
return "Start fetching subscription updates"
}
func (a *ActiveAll) Handle(ctx tb.Context) error {
mentionChat, _ := session.GetMentionChatFromCtxStore(ctx)
subscribeUserID := ctx.Chat().ID
if mentionChat != nil {
subscribeUserID = mentionChat.ID
}
source, err := a.core.GetUserSubscribedSources(context.Background(), subscribeUserID)
if err != nil {
return ctx.Reply("Internal service error")
}
for _, s := range source {
err := a.core.EnableSourceUpdate(context.Background(), s.ID)
if err != nil {
return ctx.Reply("Activation failed")
}
}
reply := "All subscriptions has been enabled and activated"
if mentionChat != nil {
reply = fmt.Sprintf("Channel [%s](https://t.me/%s) has enabled and activated all feed subscription sources update", mentionChat.Title, mentionChat.Username)
}
return ctx.Reply(
reply, &tb.SendOptions{
DisableWebPagePreview: true,
ParseMode: tb.ModeMarkdown,
},
)
}
func (a *ActiveAll) Middlewares() []tb.MiddlewareFunc {
return nil
}