-
Notifications
You must be signed in to change notification settings - Fork 1
/
service_handler_prompt.go
40 lines (32 loc) · 1.1 KB
/
service_handler_prompt.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
package service
import (
"context"
"strconv"
"github.com/bwmarrin/discordgo"
"github.com/rl404/fairy/errors/stack"
"github.com/rl404/naka/internal/domain/template/entity"
"github.com/rl404/naka/internal/errors"
)
// HandlePrompt to handle prompt response.
func (s *service) HandlePrompt(ctx context.Context, m *discordgo.MessageCreate, g *discordgo.Guild, content string) error {
search := s.prompt.GetSearch(ctx, m.Author.ID)
if search != nil && len(search.IDs) > 0 {
defer s.prompt.DeleteSearch(ctx, m.Author.ID)
i, err := strconv.Atoi(content)
if err != nil {
if _, err := s.discord.SendMessage(ctx, m.ChannelID, entity.InvalidPrompt); err != nil {
return stack.Wrap(ctx, err)
}
return stack.Wrap(ctx, err)
}
if i <= 0 || i > len(search.IDs) {
if _, err := s.discord.SendMessage(ctx, m.ChannelID, entity.InvalidPrompt); err != nil {
return stack.Wrap(ctx, err)
}
return stack.Wrap(ctx, errors.ErrInvalidPrompt)
}
videoID := search.IDs[i-1]
return stack.Wrap(ctx, s.searchSong(ctx, m, g, []string{s.youtube.GenerateVideoURL(videoID)}, search.Play))
}
return nil
}