Added an optional param
This commit is contained in:
parent
8c2d7189c7
commit
d2f94dec79
2 changed files with 33 additions and 11 deletions
|
@ -12,18 +12,32 @@ import (
|
||||||
func MarkovCommand(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
func MarkovCommand(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
log.Println("MarkovCommand called")
|
log.Println("MarkovCommand called")
|
||||||
|
|
||||||
// Get the channel ID from the interaction
|
// Get the channel ID from the interaction
|
||||||
channelID := i.ChannelID
|
channelID := i.ChannelID
|
||||||
log.Printf("Channel ID: %s", channelID)
|
log.Printf("Channel ID: %s", channelID)
|
||||||
|
|
||||||
// Fetch the last 100 messages from the channel
|
// Get the number of messages to fetch from the option
|
||||||
messages, err := s.ChannelMessages(channelID, 100, "", "", "")
|
numMessages := 100 // Default value
|
||||||
if err != nil {
|
if len(i.ApplicationCommandData().Options) > 0 {
|
||||||
log.Printf("Error fetching messages: %v", err)
|
if i.ApplicationCommandData().Options[0].Name == "messages" {
|
||||||
respondWithError(s, i, "Failed to fetch messages")
|
numMessages = int(i.ApplicationCommandData().Options[0].IntValue())
|
||||||
return
|
if numMessages <= 0 {
|
||||||
}
|
numMessages = 100
|
||||||
log.Printf("Fetched %d messages", len(messages))
|
} 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
|
// Build the Markov chain from the fetched messages
|
||||||
chain := buildMarkovChain(messages)
|
chain := buildMarkovChain(messages)
|
||||||
|
|
8
main.go
8
main.go
|
@ -32,6 +32,14 @@ var (
|
||||||
{
|
{
|
||||||
Name: "markov",
|
Name: "markov",
|
||||||
Description: "Why did the Markov chain break up with its partner? Because it couldn't handle the past!",
|
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,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue