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 g, err := s.State.Guild(m.GuildID)
17 if err != nil {
18 logger.Errorf("could not get guild: %s", err)
19 response = msgError
20 return
21 }
22
23 for _, vs := range g.VoiceStates {
24 if vs.UserID == m.Author.ID {
25 voiceChannelID = vs.ChannelID
26 break
27 }
28 }
29
30 if voiceChannelID == "" {
31 response = "You need to be in a voice channel to use this command."
32 }
33 return
34}
35
36func formatCommand(command string) string {
37 return fmt.Sprintf("`%s%s`", Config.Values.Prefix, command)
38}
39
40func parseUserMessage(messageContent string) (command string, args []string, ok bool) {
41 after, found := strings.CutPrefix(messageContent, Config.Values.Prefix)
42 if !found {
43 return
44 }
45
46 userInput := strings.Split(after, " ")
47 command = strings.ToLower(userInput[0])
48 return command, userInput[1:], len(command) > 0
49}