2020-05-17 06:25:29 +00:00
package telegram
import (
"fmt"
2020-05-18 02:06:52 +00:00
"strings"
2020-05-17 06:25:29 +00:00
"github.com/mattburchett/go_telegram/pkg/service/sonarr"
"github.com/yanzay/tbot/v2"
)
2020-05-18 02:06:52 +00:00
// Sonarr Search
func ( tb * Bot ) sonarrSearch ( m * tbot . Message ) {
2020-05-25 03:29:08 +00:00
if ! tb . whitelistHandler ( m ) {
return
}
2020-05-18 02:06:52 +00:00
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 ,
} } )
}
2020-05-25 03:29:08 +00:00
if len ( request ) == 0 {
tb . Client . SendMessage ( m . Chat . ID , "No results found, try harder." )
return
}
2020-05-18 02:06:52 +00:00
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 ) {
2020-05-25 03:29:08 +00:00
if ! tb . whitelistHandler ( m ) {
return
}
2020-05-18 02:06:52 +00:00
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 ) )
2020-05-18 02:06:52 +00:00
return
2020-05-17 06:25:29 +00:00
}
2020-05-18 02:06:52 +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
}
}