grim/wasdead

Fix the help message for the help command
draft
2019-04-08, Gary Kramlich
c06bc2e462ed
Fix the help message for the help command
package discord
import (
"fmt"
"strings"
"github.com/bwmarrin/discordgo"
"bitbucket.org/TheToyz/nowdead/presence"
)
type commandStatus struct{}
func (cmd *commandStatus) Help() string {
return "get the streaming status of a target"
}
func (cmd *commandStatus) Run(args []string, c *DiscordClient, m *discordgo.MessageCreate) (interface{}, error) {
uri := ""
if len(args) != 1 {
return nil, fmt.Errorf("invalid target")
}
target := args[0]
if strings.HasPrefix(target, "<@") {
mentionID := target[2 : len(target)-1]
for _, mentioned := range m.Mentions {
if mentioned.ID == mentionID {
p := c.getPresence(m.GuildID, mentioned.ID)
if p != nil && p.Game != nil && p.Game.Type == discordgo.GameTypeStreaming {
uri = p.Game.URL
} else {
return nil, fmt.Errorf("%s is not streaming", target)
}
}
}
} else {
uri = "https://twitch.tv/" + target
}
presence, err := presence.GetPresence(uri)
if err != nil {
return nil, err
}
return presenceEmbed(presence), nil
}