46 lines
831 B
Go
46 lines
831 B
Go
package util
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"runtime/debug"
|
|
|
|
"github.com/bwmarrin/discordgo"
|
|
)
|
|
|
|
var (
|
|
ErrRequireAdmin = errors.New("This command requires administrator.")
|
|
)
|
|
|
|
var ReportTarget string
|
|
|
|
func ReportError(dg *discordgo.Session, toReport error) {
|
|
msg := "```\n" + toReport.Error() + "\n" + string(debug.Stack()) + "```"
|
|
|
|
if dg == nil {
|
|
fmt.Println(msg)
|
|
fmt.Println("DiscordGo not provided")
|
|
return
|
|
}
|
|
|
|
channel, err := dg.UserChannelCreate(ReportTarget)
|
|
if err != nil {
|
|
fmt.Println(msg)
|
|
fmt.Println(err)
|
|
return
|
|
}
|
|
_, err = dg.ChannelMessageSend(channel.ID, msg)
|
|
if err != nil {
|
|
fmt.Println(msg)
|
|
fmt.Println(err)
|
|
}
|
|
}
|
|
|
|
func SendMessage(dg *discordgo.Session, channelID string, message string) {
|
|
_, err := dg.ChannelMessageSend(channelID, message)
|
|
if err != nil {
|
|
ReportError(dg, err)
|
|
return
|
|
}
|
|
}
|