Expand search response fidelity, footer shortcut fn

This commit is contained in:
2024-01-18 02:11:43 -06:00
parent 076291de8e
commit 26bdad9c94
2 changed files with 20 additions and 10 deletions
+14 -10
View File
@@ -87,9 +87,16 @@ func SearchCommandHandler(session *discordgo.Session, interaction *discordgo.Int
fields := []*discordgo.MessageEmbedField{} fields := []*discordgo.MessageEmbedField{}
for _, course := range courses.Data { for _, course := range courses.Data {
displayName := course.Faculty[0].DisplayName
categoryLink := fmt.Sprintf("[%s](https://catalog.utsa.edu/undergraduate/coursedescriptions/%s/)", course.Subject, strings.ToLower(course.Subject))
classLink := fmt.Sprintf("[%s-%s](https://catalog.utsa.edu/search/?P=%s%%20%s)", course.CourseNumber, course.SequenceNumber, course.Subject, course.CourseNumber)
professorLink := fmt.Sprintf("[%s](https://google.com)", displayName)
identifierText := fmt.Sprintf("%s %s (CRN %s)\n%s", categoryLink, classLink, course.CourseReferenceNumber, professorLink)
fields = append(fields, &discordgo.MessageEmbedField{ fields = append(fields, &discordgo.MessageEmbedField{
Name: "Identifier", Name: "Identifier",
Value: fmt.Sprintf("%s %s-%s [%s]", course.Subject, course.CourseNumber, course.SequenceNumber, course.CourseReferenceNumber), Value: identifierText,
Inline: true, Inline: true,
}, &discordgo.MessageEmbedField{ }, &discordgo.MessageEmbedField{
Name: "Name", Name: "Name",
@@ -99,7 +106,8 @@ func SearchCommandHandler(session *discordgo.Session, interaction *discordgo.Int
Name: "Meeting Time", Name: "Meeting Time",
Value: "MWF 11AM-12:15PM", Value: "MWF 11AM-12:15PM",
Inline: true, Inline: true,
}) },
)
} }
err = session.InteractionRespond(interaction.Interaction, &discordgo.InteractionResponse{ err = session.InteractionRespond(interaction.Interaction, &discordgo.InteractionResponse{
@@ -107,11 +115,9 @@ func SearchCommandHandler(session *discordgo.Session, interaction *discordgo.Int
Data: &discordgo.InteractionResponseData{ Data: &discordgo.InteractionResponseData{
Embeds: []*discordgo.MessageEmbed{ Embeds: []*discordgo.MessageEmbed{
{ {
Footer: &discordgo.MessageEmbedFooter{ Footer: GetFooter(fetch_time),
Text: fmt.Sprintf("Fetched at %s", fetch_time.Format("Monday, January 2, 2006 at 3:04:05PM")), Description: fmt.Sprintf("%d Classes", courses.TotalCount),
}, Fields: fields[:min(25, len(fields))],
Description: "",
Fields: fields,
}, },
}, },
AllowedMentions: &discordgo.MessageAllowedMentions{}, AllowedMentions: &discordgo.MessageAllowedMentions{},
@@ -202,9 +208,7 @@ func TimeCommandHandler(s *discordgo.Session, i *discordgo.InteractionCreate) er
Data: &discordgo.InteractionResponseData{ Data: &discordgo.InteractionResponseData{
Embeds: []*discordgo.MessageEmbed{ Embeds: []*discordgo.MessageEmbed{
{ {
Footer: &discordgo.MessageEmbedFooter{ Footer: GetFooter(fetch_time),
Text: fmt.Sprintf("Fetched at %s", fetch_time.Format("Monday, January 2, 2006 at 3:04:05PM")),
},
Description: "", Description: "",
Fields: []*discordgo.MessageEmbedField{ Fields: []*discordgo.MessageEmbedField{
{ {
+6
View File
@@ -318,3 +318,9 @@ func RespondError(session *discordgo.Session, interaction *discordgo.Interaction
}, },
}) })
} }
func GetFooter(time time.Time) *discordgo.MessageEmbedFooter {
return &discordgo.MessageEmbedFooter{
Text: fmt.Sprintf("Fetched at %s", time.Format("Monday, January 2, 2006 at 3:04:05PM")),
}
}