go_telegram/pkg/service/telegram/sonarr.go

73 lines
1.9 KiB
Go
Raw Normal View History

2020-05-17 06:25:29 +00:00
package telegram
import (
"fmt"
"strings"
2020-05-17 06:25:29 +00:00
"github.com/mattburchett/go_telegram/pkg/service/sonarr"
"github.com/yanzay/tbot/v2"
)
// Sonarr Search
func (tb *Bot) sonarrSearch(m *tbot.Message) {
text := strings.TrimPrefix(strings.TrimPrefix(m.Text, "/s"), " ")
if len(text) == 0 {
tb.Client.SendMessage(m.Chat.ID, "You must specify a show. Type /help for help.")
return
}
request, err := sonarr.Search(m, tb.Config)
if err != nil {
tb.Client.SendMessage(m.Chat.ID, err.Error())
return
}
inlineResponse := make([][]tbot.InlineKeyboardButton, 0)
for _, i := range request {
inlineResponse = append(inlineResponse, []tbot.InlineKeyboardButton{{
Text: i.Button,
CallbackData: "tv_" + i.Callback,
}})
}
response, _ := tb.Client.SendMessage(m.Chat.ID, "Please select the show you would like to download.", tbot.OptInlineKeyboardMarkup(&tbot.InlineKeyboardMarkup{InlineKeyboard: inlineResponse}))
tb.CallbackMessageID = response.MessageID
tb.CallbackChatID = m.Chat.ID
}
// sonarrAdd will perform the add requests to Sonarr.
func (tb *Bot) sonarrAdd(cq *tbot.CallbackQuery) {
if strings.Contains(cq.Data, "+") {
if tb.adminCheck(cq.From.ID, true) {
tb.Client.SendMessage(tb.CallbackChatID, sonarr.Add(cq.Data, tb.Config))
} else {
tb.Client.AnswerCallbackQuery(cq.ID, tbot.OptText("This request is over the season limit."))
}
return
}
tb.Client.SendMessage(tb.CallbackChatID, sonarr.Add(cq.Data, tb.Config))
}
// Admin Functions
// sonarrStatus queries Sonarr for it's system status information.
2020-05-17 06:25:29 +00:00
func (tb *Bot) sonarrStatus(m *tbot.Message) {
if tb.adminCheck(m.From.ID, false) {
request, err := sonarr.Status(m, tb.Config)
2020-05-17 06:25:29 +00:00
if err != nil {
tb.Client.SendMessage(m.Chat.ID, fmt.Sprintf("%v: \n %v", request, err))
return
2020-05-17 06:25:29 +00:00
}
tb.Client.SendMessage(m.Chat.ID, "Sonarr Status:")
tb.Client.SendMessage(m.Chat.ID, request)
2020-05-17 06:25:29 +00:00
}
}