mirror of
https://github.com/Xevion/banner.git
synced 2025-12-07 07:14:25 -06:00
Setup command definitions, meetingtime command fields, footer fetch time
This commit is contained in:
64
commands.go
64
commands.go
@@ -1,12 +1,46 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
)
|
)
|
||||||
|
|
||||||
var commandDefinitions = []*discordgo.ApplicationCommand{TimeCommandDefinition}
|
var (
|
||||||
|
commandDefinitions = []*discordgo.ApplicationCommand{TermCommandDefinition, TimeCommandDefinition}
|
||||||
|
commandHandlers = map[string]func(s *discordgo.Session, i *discordgo.InteractionCreate){
|
||||||
|
"time": TimeCommandHandler,
|
||||||
|
"term": TermCommandHandler,
|
||||||
|
}
|
||||||
|
minLength = 0
|
||||||
|
)
|
||||||
|
|
||||||
|
var TermCommandDefinition = &discordgo.ApplicationCommand{
|
||||||
|
Name: "term",
|
||||||
|
Description: "Guess the current term, or search for a specific term",
|
||||||
|
Options: []*discordgo.ApplicationCommandOption{
|
||||||
|
{
|
||||||
|
Type: discordgo.ApplicationCommandOptionString,
|
||||||
|
MinLength: &minLength,
|
||||||
|
MaxLength: 8,
|
||||||
|
Name: "term",
|
||||||
|
Description: "Term to search for",
|
||||||
|
Required: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func TermCommandHandler(session *discordgo.Session, interaction *discordgo.InteractionCreate) {
|
||||||
|
GetTerms("", 1, 25)
|
||||||
|
|
||||||
|
session.InteractionRespond(interaction.Interaction, &discordgo.InteractionResponse{
|
||||||
|
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||||
|
Data: &discordgo.InteractionResponseData{
|
||||||
|
Content: fmt.Sprintf("```json\n%s```", "{\n \"name\": \"Term\",\n \"value\": \"202420\"\n}"),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
var TimeCommandDefinition = &discordgo.ApplicationCommand{
|
var TimeCommandDefinition = &discordgo.ApplicationCommand{
|
||||||
Name: "time",
|
Name: "time",
|
||||||
@@ -28,8 +62,9 @@ var TimeCommandDefinition = &discordgo.ApplicationCommand{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TimeCommandHandler(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
func TimeCommandHandler(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
|
fetch_time := time.Now()
|
||||||
crn := i.ApplicationCommandData().Options[0].IntValue()
|
crn := i.ApplicationCommandData().Options[0].IntValue()
|
||||||
_, 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{
|
||||||
@@ -45,9 +80,28 @@ func TimeCommandHandler(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
|||||||
Data: &discordgo.InteractionResponseData{
|
Data: &discordgo.InteractionResponseData{
|
||||||
Embeds: []*discordgo.MessageEmbed{
|
Embeds: []*discordgo.MessageEmbed{
|
||||||
{
|
{
|
||||||
Title: "CRN " + strconv.Itoa(int(crn)),
|
Footer: &discordgo.MessageEmbedFooter{
|
||||||
|
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{
|
||||||
|
{
|
||||||
|
Name: "Start Date",
|
||||||
|
Value: courseMeetingTime.dateStart.Format("Monday, January 2, 2006"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "End Date",
|
||||||
|
Value: courseMeetingTime.dateEnd.Format("Monday, January 2, 2006"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "Start/End Time",
|
||||||
|
Value: fmt.Sprintf("%s - %s", courseMeetingTime.timeStart.String(), courseMeetingTime.timeEnd.String()),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "Weekdays",
|
||||||
|
Value: WeekdaysToString(courseMeetingTime.weekdays),
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
AllowedMentions: &discordgo.MessageAllowedMentions{},
|
AllowedMentions: &discordgo.MessageAllowedMentions{},
|
||||||
|
|||||||
Reference in New Issue
Block a user