diff --git a/command/markov.go b/command/markov.go index 8d3d6e4..3696840 100644 --- a/command/markov.go +++ b/command/markov.go @@ -12,18 +12,32 @@ import ( func MarkovCommand(s *discordgo.Session, i *discordgo.InteractionCreate) { log.Println("MarkovCommand called") - // Get the channel ID from the interaction - channelID := i.ChannelID - log.Printf("Channel ID: %s", channelID) + // Get the channel ID from the interaction + channelID := i.ChannelID + log.Printf("Channel ID: %s", channelID) - // Fetch the last 100 messages from the channel - messages, err := s.ChannelMessages(channelID, 100, "", "", "") - if err != nil { - log.Printf("Error fetching messages: %v", err) - respondWithError(s, i, "Failed to fetch messages") - return - } - log.Printf("Fetched %d messages", len(messages)) + // Get the number of messages to fetch from the option + numMessages := 100 // Default value + if len(i.ApplicationCommandData().Options) > 0 { + if i.ApplicationCommandData().Options[0].Name == "messages" { + numMessages = int(i.ApplicationCommandData().Options[0].IntValue()) + if numMessages <= 0 { + numMessages = 100 + } else if numMessages > 1000 { + numMessages = 1000 + } + } + } + log.Printf("Fetching %d messages", numMessages) + + // Fetch the specified number of messages from the channel + messages, err := s.ChannelMessages(channelID, numMessages, "", "", "") + if err != nil { + log.Printf("Error fetching messages: %v", err) + respondWithError(s, i, "Failed to fetch messages") + return + } + log.Printf("Fetched %d messages", len(messages)) // Build the Markov chain from the fetched messages chain := buildMarkovChain(messages) diff --git a/main.go b/main.go index 2a97b59..8f65a9e 100644 --- a/main.go +++ b/main.go @@ -32,6 +32,14 @@ var ( { Name: "markov", Description: "Why did the Markov chain break up with its partner? Because it couldn't handle the past!", + Options: []*discordgo.ApplicationCommandOption{ + { + Type: discordgo.ApplicationCommandOptionInteger, + Name: "messages", + Description: "Number of messages to use (default: 100, max: 1000)", + Required: false, + }, + }, }, }