mirror of
https://github.com/Xevion/banner.git
synced 2025-12-15 00:11:06 -06:00
Use custom struct for MeetingTimeFaculty.timeStart, move comand handlers
This commit is contained in:
57
helpers.go
57
helpers.go
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"math/rand"
|
||||
@@ -78,3 +79,59 @@ func Plural(n int) string {
|
||||
}
|
||||
return "s"
|
||||
}
|
||||
|
||||
func WeekdaysToString(days map[time.Weekday]bool) string {
|
||||
str := ""
|
||||
|
||||
if days[time.Monday] {
|
||||
str += "M"
|
||||
}
|
||||
|
||||
if days[time.Tuesday] {
|
||||
str += "Tu"
|
||||
}
|
||||
|
||||
if days[time.Wednesday] {
|
||||
str += "W"
|
||||
}
|
||||
|
||||
if days[time.Thursday] {
|
||||
str += "Th"
|
||||
}
|
||||
|
||||
if days[time.Friday] {
|
||||
str += "F"
|
||||
}
|
||||
|
||||
if days[time.Saturday] {
|
||||
str += "Sa"
|
||||
}
|
||||
|
||||
if days[time.Sunday] {
|
||||
str += "Su"
|
||||
}
|
||||
|
||||
return str
|
||||
}
|
||||
|
||||
type NaiveTime struct {
|
||||
Hours uint
|
||||
Minutes uint
|
||||
}
|
||||
|
||||
func ParseNaiveTime(integer uint64) NaiveTime {
|
||||
minutes := uint(integer % 100)
|
||||
hours := uint(integer / 100)
|
||||
|
||||
return NaiveTime{Hours: hours, Minutes: minutes}
|
||||
}
|
||||
|
||||
func (nt NaiveTime) String() string {
|
||||
meridiem := "AM"
|
||||
hour := nt.Hours
|
||||
if nt.Hours >= 12 {
|
||||
meridiem = "PM"
|
||||
hour -= 12
|
||||
}
|
||||
return fmt.Sprintf("%d:%02d%s", hour, nt.Minutes, meridiem)
|
||||
}
|
||||
|
||||
9
main.go
9
main.go
@@ -21,9 +21,6 @@ var (
|
||||
session *discordgo.Session
|
||||
RemoveCommands = flag.Bool("rmcmd", true, "Remove all commands after shutdowning or not")
|
||||
integerOptionMinValue = 0.0
|
||||
commandHandlers = map[string]func(s *discordgo.Session, i *discordgo.InteractionCreate){
|
||||
"time": TimeCommandHandler,
|
||||
}
|
||||
)
|
||||
|
||||
type MeetingTimeFaculty struct {
|
||||
@@ -43,8 +40,8 @@ type MeetingTimeResponse struct {
|
||||
building string
|
||||
buildingDescription string
|
||||
room string
|
||||
timeStart uint64
|
||||
timeEnd uint64
|
||||
timeStart NaiveTime
|
||||
timeEnd NaiveTime
|
||||
dateStart time.Time
|
||||
dateEnd time.Time
|
||||
hoursPerWeek float32
|
||||
@@ -87,7 +84,7 @@ func main() {
|
||||
}
|
||||
})
|
||||
|
||||
log.Println("Adding commands...")
|
||||
log.Printf("Adding %d command%s...", len(commandDefinitions), Plural(len(commandDefinitions)))
|
||||
registeredCommands := make([]*discordgo.ApplicationCommand, len(commandDefinitions))
|
||||
for i, v := range commandDefinitions {
|
||||
cmd, err := session.ApplicationCommandCreate(session.State.User.ID, os.Getenv("BOT_TARGET_GUILD"), v)
|
||||
|
||||
Reference in New Issue
Block a user