package commands import ( "fmt" "strings" "github.com/bwmarrin/discordgo" ) var ActionCommand = &discordgo.ApplicationCommand{ Name: "action", Description: "Perform an action towards someone.", Options: []*discordgo.ApplicationCommandOption{ { Type: discordgo.ApplicationCommandOptionString, Name: "action", Description: "Choose an action to perform", Required: true, Choices: []*discordgo.ApplicationCommandOptionChoice{ {Name: "hugs", Value: "hugs"}, {Name: "high-five", Value: "highfive"}, {Name: "slaps", Value: "slaps"}, {Name: "kisses", Value: "kisses"}, {Name: "pokes", Value: "pokes"}, {Name: "tickles", Value: "tickles"}, {Name: "smiles", Value: "smiles"}, {Name: "rolls eyes", Value: "rollseyes"}, {Name: "scoffs", Value: "scoffs"}, {Name: "glares", Value: "glares"}, {Name: "shrugs", Value: "shrugs"}, {Name: "snarks", Value: "snarks"}, {Name: "pouts", Value: "pouts"}, }, }, { Type: discordgo.ApplicationCommandOptionUser, Name: "receiver", Description: "The person to receive the action", Required: false, }, { Type: discordgo.ApplicationCommandOptionBoolean, Name: "useemojis", Description: "Use emojis instead of emoticons (default is false)", Required: false, }, }, } var emojiMap = map[string]string{ "hugs": "🤗", "highfive": "✋", "slaps": "😵", "kisses": "😘", "pokes": "👉", "tickles": "😂", "smiles": "😊", "rollseyes": "🙄", "scoffs": "😒", "glares": "😠", "shrugs": "🤷", "snarks": "😏", "pouts": "😤", } var emoticonMap = map[string]string{ "hugs": "(<^_^>)", "highfive": "o/\\o", "slaps": "*slaps*", "kisses": ":-*", "pokes": "->", "tickles": "*tickles*", "smiles": ":3", "rollseyes": "*rolls eyes*", "scoffs": "*scoffs*", "glares": ">:(", "shrugs": "¯\\_(ツ)_/¯", "snarks": "*snarks*", "pouts": ":(", } // Special messages for when the sender targets themselves or the bot var specialMessages = map[string]map[string]string{ "hugs": { "self": "You give yourself a warm hug. Sometimes self-love is the best love!", "bot": "OWO thamkies for hug!!!", }, "highfive": { "self": "High-fiving yourself? That's some self-confidence!", "bot": "YAY high-five!", }, "slaps": { "self": "Stop it, get some help", "bot": "OI! Go away! *HMPH!*", }, "kisses": { "self": "Do you taste good???", "bot": ">///////////////<", }, "pokes": { "self": "Poking yourself is a sign you need a break", "bot": "*grrrrrrrrrrrrrrrrr*", }, "tickles": { "self": "???????????????????", "bot": "*FKLDJLKFSDLKFJDSKLFJLKSDF **CEASE!!!***", }, "smiles": { "self": ":D", "bot": ":D", }, "rollseyes": { "self": "bleh 🙄", "bot": "*SASSING ME???? W-WELL I BORK AT YOU!!!*", }, "scoffs": { "self": "Scoffing at yourself isn't very productive.", "bot": "I hear you, but try being kinder!", }, "glares": { "self": "Maybe take a break from the mirror...", "bot": ">~<\n*sh-shtooopppppp!*", }, "shrugs": { "self": "IDK man it's a your problem", "bot": "", }, "pouts": { "self": "Pouting at yourself won't change a thing!", "bot": "# *HMPH!*", }, } func HandleAction(s *discordgo.Session, i *discordgo.InteractionCreate) { actionSelected := strings.ToLower(i.ApplicationCommandData().Options[0].StringValue()) // Check optional boolean parameter "useemojis" useEmojis := false if len(i.ApplicationCommandData().Options) > 2 { option := i.ApplicationCommandData().Options[2] if option.Value != nil { useEmojis, _ = option.Value.(bool) } } // Choose the mapping based on the option var mapping map[string]string if useEmojis { mapping = emojiMap } else { mapping = emoticonMap } // Determine the display symbol for the action symbol, exists := mapping[actionSelected] if !exists { symbol = "😄" } // Get the receiver if provided; if not, default to "someone special" var receiverID string receiverMention := "someone special" if len(i.ApplicationCommandData().Options) > 1 { if id, ok := i.ApplicationCommandData().Options[1].Value.(string); ok { receiverID = id if i.ApplicationCommandData().Resolved != nil && i.ApplicationCommandData().Resolved.Users != nil { if user, found := i.ApplicationCommandData().Resolved.Users[id]; found { receiverMention = fmt.Sprintf("<@%s>", user.ID) } else { receiverMention = fmt.Sprintf("<@%s>", id) } } else { receiverMention = fmt.Sprintf("<@%s>", id) } } } // Determine the sender mention. senderID := i.User.ID if i.Member != nil { senderID = i.Member.User.ID } senderMention := fmt.Sprintf("<@%s>", senderID) // Check for special cases. responseMessage := fmt.Sprintf("%s %s %s %s", senderMention, actionSelected, receiverMention, symbol) if receiverID != "" { botID := s.State.User.ID if receiverID == senderID { // Special message for acting on yourself. if special, ok := specialMessages[actionSelected]["self"]; ok { responseMessage = special } } else if receiverID == botID { // Special message for acting on the bot. if special, ok := specialMessages[actionSelected]["bot"]; ok { responseMessage = special } } } // Send the interaction response. s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ Type: discordgo.InteractionResponseChannelMessageWithSource, Data: &discordgo.InteractionResponseData{ Content: responseMessage, }, }) }