birdbot/app/event.go

87 lines
1.6 KiB
Go
Raw Normal View History

2022-10-27 03:55:23 +02:00
package app
import (
"fmt"
"regexp"
"strings"
"time"
)
const REMOTE_LOCATION string = "online"
type Event struct {
Name string
Location string
DateTime time.Time
OrganizerID string
}
func (event *Event) GetChannelName() string {
month := event.GetMonthPrefix()
2022-10-27 05:29:24 +02:00
day := event.DateTime.Day()
2022-10-27 03:55:23 +02:00
city := event.GetCityFromLocation()
2022-10-27 05:29:24 +02:00
channel := fmt.Sprint(month, "-", day, city, "-", event.Name)
2022-10-27 03:55:23 +02:00
channel = strings.ReplaceAll(channel, " ", "-")
channel = strings.ToLower(channel)
re, _ := regexp.Compile(`[^\w\-]`)
channel = re.ReplaceAllString(channel, "")
return channel
}
func (event *Event) GetCityFromLocation() string {
if event.Location == REMOTE_LOCATION {
return REMOTE_LOCATION
}
parts := strings.Split(event.Location, " ")
index := -1
loc := event.Location
for i, v := range parts {
part := strings.ToLower(v)
if part == "mi" || part == "michigan" {
index = i - 1
if index < 0 {
2022-10-27 05:29:24 +02:00
return ""
2022-10-27 03:55:23 +02:00
}
if index > 0 && parts[index] == "," {
index -= 1
}
if index > 1 && strings.Contains(parts[index-2], ",") {
loc = fmt.Sprintf("%s-%s", parts[index-1], parts[index])
break
}
loc = parts[index]
break
}
}
2022-10-27 05:29:24 +02:00
return fmt.Sprint("-", loc)
2022-10-27 03:55:23 +02:00
}
func (event *Event) GetMonthPrefix() string {
month := event.DateTime.Month()
data := map[time.Month]string{
time.January: "jan",
time.February: "feb",
time.March: "march",
time.April: "april",
time.May: "may",
time.June: "june",
time.July: "july",
time.August: "aug",
time.September: "sept",
time.October: "oct",
time.November: "nov",
time.December: "dec",
}
return data[month]
}