Setup search command stub, remove unused term cmd option for term lookup cmd

This commit is contained in:
2024-01-07 08:38:17 -06:00
parent b4b2930a58
commit a4c00af1fe
+57 -7
View File
@@ -12,10 +12,67 @@ var (
commandHandlers = map[string]func(s *discordgo.Session, i *discordgo.InteractionCreate){ commandHandlers = map[string]func(s *discordgo.Session, i *discordgo.InteractionCreate){
"time": TimeCommandHandler, "time": TimeCommandHandler,
"term": TermCommandHandler, "term": TermCommandHandler,
"search": SearchCommandHandler,
} }
minLength = 0 minLength = 0
) )
var SearchCommandDefinition = &discordgo.ApplicationCommand{
Name: "search",
Description: "Search for a course",
Options: []*discordgo.ApplicationCommandOption{
{
Type: discordgo.ApplicationCommandOptionString,
MinLength: &minLength,
MaxLength: 8,
Name: "query",
Description: "Search query",
Required: true,
},
},
}
func SearchCommandHandler(session *discordgo.Session, interaction *discordgo.InteractionCreate) {
query := Query{
Keywords: &[]string{"Computer Science"},
}
courses := Search(query, 0, 5, "", false)
fetch_time := time.Now()
fields := []*discordgo.MessageEmbedField{}
for _, course := range courses.Data {
fields = append(fields, &discordgo.MessageEmbedField{
Name: "Name",
Value: course.CourseTitle,
Inline: true,
}, &discordgo.MessageEmbedField{
Name: "CRN",
Value: "12345",
Inline: true,
}, &discordgo.MessageEmbedField{
Name: "Credits",
Value: "3",
Inline: true,
})
}
session.InteractionRespond(interaction.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Embeds: []*discordgo.MessageEmbed{
{
Footer: &discordgo.MessageEmbedFooter{
Text: fmt.Sprintf("Fetched at %s", fetch_time.Format("Monday, January 2, 2006 at 3:04:05PM")),
},
Description: "",
Fields: fields,
},
},
AllowedMentions: &discordgo.MessageAllowedMentions{},
},
})
}
var TermCommandDefinition = &discordgo.ApplicationCommand{ var TermCommandDefinition = &discordgo.ApplicationCommand{
Name: "term", Name: "term",
Description: "Guess the current term, or search for a specific term", Description: "Guess the current term, or search for a specific term",
@@ -52,12 +109,6 @@ var TimeCommandDefinition = &discordgo.ApplicationCommand{
Description: "Course Reference Number", Description: "Course Reference Number",
Required: true, Required: true,
}, },
{
Type: discordgo.ApplicationCommandOptionString,
Name: "term",
Description: "Term",
Required: false,
},
}, },
} }
@@ -65,7 +116,6 @@ func TimeCommandHandler(s *discordgo.Session, i *discordgo.InteractionCreate) {
fetch_time := time.Now() fetch_time := time.Now()
crn := i.ApplicationCommandData().Options[0].IntValue() crn := i.ApplicationCommandData().Options[0].IntValue()
courseMeetingTime, err := GetCourseMeetingTime(202420, int(crn)) courseMeetingTime, err := GetCourseMeetingTime(202420, int(crn))
if err != nil { if err != nil {
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource, Type: discordgo.InteractionResponseChannelMessageWithSource,