46 lines
1.0 KiB
Go
46 lines
1.0 KiB
Go
package shared
|
|
|
|
import (
|
|
"strconv"
|
|
|
|
"velox-bot/internal/db/services"
|
|
|
|
"github.com/bwmarrin/discordgo"
|
|
)
|
|
|
|
func RespondEphemeral(s *discordgo.Session, i *discordgo.InteractionCreate, msg string) {
|
|
_ = s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
|
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
|
Data: &discordgo.InteractionResponseData{
|
|
Content: msg,
|
|
Flags: discordgo.MessageFlagsEphemeral,
|
|
},
|
|
})
|
|
}
|
|
|
|
func RequireUserSettingsService(s *discordgo.Session, i *discordgo.InteractionCreate) bool {
|
|
if services.Global == nil || services.Global.UserSettings == nil {
|
|
RespondEphemeral(s, i, "User settings service is not available.")
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
func CurrentUserID(i *discordgo.InteractionCreate) (int64, bool) {
|
|
var idStr string
|
|
if i.Member != nil && i.Member.User != nil {
|
|
idStr = i.Member.User.ID
|
|
} else if i.User != nil {
|
|
idStr = i.User.ID
|
|
}
|
|
if idStr == "" {
|
|
return 0, false
|
|
}
|
|
uid, err := strconv.ParseInt(idStr, 10, 64)
|
|
if err != nil {
|
|
return 0, false
|
|
}
|
|
return uid, true
|
|
}
|
|
|