all repos — disgord @ 1b8f5834bbf4f6a1fb79a5f46a77c1d41007c600

A simple Discord bot in Go.

utils.go (view raw)

 1package main
 2
 3import (
 4	"fmt"
 5
 6	"github.com/bwmarrin/discordgo"
 7)
 8
 9func (bc BotCommand) FormatHelp(command string) string {
10	var shortCodeStr string
11	if bc.ShortCode != "" {
12		shortCodeStr = fmt.Sprintf(" (%s)", formatCommand(bc.ShortCode))
13	}
14	return fmt.Sprintf(helpFmt, formatCommand(command)+shortCodeStr, bc.Help)
15}
16
17func getVoiceChannelID(s *discordgo.Session, m *discordgo.MessageCreate) (response string, g *discordgo.Guild, voiceChannelID string) {
18	if m.Member == nil {
19		response = "Please, use this inside a server."
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}