2020-11-29 21:47:02 -08:00
|
|
|
package transmitter
|
|
|
|
|
|
|
|
import (
|
2022-03-12 08:06:39 -08:00
|
|
|
"github.com/bwmarrin/discordgo"
|
2020-11-29 21:47:02 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
// isDiscordPermissionError returns false for nil, and true if a Discord RESTError with code discordgo.ErrorCodeMissionPermissions
|
|
|
|
func isDiscordPermissionError(err error) bool {
|
|
|
|
if err == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
restErr, ok := err.(*discordgo.RESTError)
|
|
|
|
if !ok {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return restErr.Message != nil && restErr.Message.Code == discordgo.ErrCodeMissingPermissions
|
|
|
|
}
|
|
|
|
|
|
|
|
// getDiscordUserID gets own user ID from state, and fallback on API request
|
|
|
|
func getDiscordUserID(session *discordgo.Session) (string, error) {
|
|
|
|
if user := session.State.User; user != nil {
|
|
|
|
return user.ID, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
user, err := session.User("@me")
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
return user.ID, nil
|
|
|
|
}
|