scuzzy/commands/bot.go

84 lines
1.7 KiB
Go

package commands
import (
"errors"
"github.com/bwmarrin/discordgo"
"log"
"os"
"strings"
"time"
)
func (c *Commands) handleSetStatus(s *discordgo.Session, m *discordgo.MessageCreate) error {
if !c.Permissions.CheckAdminRole(m.Member) {
return errors.New("You do not have permissions to use that command.")
}
stSplit := strings.SplitN(m.Content, " ", 2)
if len(stSplit) < 2 {
return errors.New("You did not specify a status.")
}
st := stSplit[1]
err := s.UpdateGameStatus(0, st)
if err != nil {
return err
}
msg := c.CreateDefinedEmbed("Set Status", "Operation completed successfully.", "success", m.Author)
_, err = s.ChannelMessageSendEmbed(m.ChannelID, msg)
if err != nil {
return err
}
return nil
}
func (c *Commands) handleDisconnect(s *discordgo.Session, m *discordgo.MessageCreate) error {
if !c.Permissions.CheckAdminRole(m.Member) {
return errors.New("I'm sorry Dave, I'm afraid I can't do that.")
}
msg := c.CreateDefinedEmbed("Disconnect", "Attempting Disconnect...", "", m.Author)
_, err := s.ChannelMessageSendEmbed(m.ChannelID, msg)
if err != nil {
return err
}
err = s.Close()
if err != nil {
return err
}
os.Exit(0)
return nil
}
func (c *Commands) handleReconnect(s *discordgo.Session, m *discordgo.MessageCreate) error {
if !c.Permissions.CheckAdminRole(m.Member) {
return errors.New("You do not have permissions to use that command.")
}
t := time.Now()
err := s.Close()
if err != nil {
return err
}
err = s.Open()
if err != nil {
log.Fatal(err)
}
msg := c.CreateDefinedEmbed("Reconnect", "Reconnected Successfully.\nTime: `"+time.Since(t).String()+"`.", "success", m.Author)
_, err = s.ChannelMessageSendEmbed(m.ChannelID, msg)
if err != nil {
return err
}
return nil
}