src/utils.go (view raw)
1package src
2
3import (
4 "fmt"
5 "strings"
6
7 "github.com/bwmarrin/discordgo"
8)
9
10func getVoiceChannelID(s *discordgo.Session, m *discordgo.MessageCreate) (response string, g *discordgo.Guild, voiceChannelID string) {
11 if m.Member == nil {
12 response = "Please, use this inside a server."
13 return
14 }
15
16 _, err := s.Guild(m.GuildID)
17 if err != nil {
18 logger.Errorf("could not update guild: %s", err)
19 response = msgError
20 return
21 }
22
23 g, err = s.State.Guild(m.GuildID)
24 if err != nil {
25 logger.Errorf("could not get guild: %s", err)
26 response = msgError
27 return
28 }
29
30 for _, vs := range g.VoiceStates {
31 if vs.UserID == m.Author.ID {
32 voiceChannelID = vs.ChannelID
33 break
34 }
35 }
36
37 if voiceChannelID == "" {
38 response = "You need to be in a voice channel to use this command."
39 }
40 return
41}
42
43func formatCommand(command string) string {
44 return fmt.Sprintf("`%s%s`", Config.Values.Prefix, command)
45}
46
47func parseUserMessage(messageContent string) (command string, args []string, ok bool) {
48 after, found := strings.CutPrefix(messageContent, Config.Values.Prefix)
49 if !found {
50 return
51 }
52
53 userInput := strings.Split(after, " ")
54 command = strings.ToLower(userInput[0])
55 return command, userInput[1:], len(command) > 0
56}