2022-10-29 05:08:17 +02:00
|
|
|
package core
|
|
|
|
|
2023-03-31 05:51:05 +02:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"regexp"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
2023-06-19 09:08:24 +02:00
|
|
|
"github.com/yeslayla/birdbot-common/common"
|
2023-03-31 05:51:05 +02:00
|
|
|
)
|
|
|
|
|
2022-10-29 05:08:17 +02:00
|
|
|
type Channel struct {
|
|
|
|
Name string
|
|
|
|
ID string
|
|
|
|
Verified bool
|
|
|
|
}
|
2023-03-31 05:51:05 +02:00
|
|
|
|
2023-03-31 22:49:50 +02:00
|
|
|
// GenerateEventChannelName deciphers a channel name from a given set of event data
|
2023-03-31 05:51:05 +02:00
|
|
|
func GenerateEventChannelName(eventName string, location string, dateTime time.Time) string {
|
|
|
|
month := GetMonthPrefix(dateTime)
|
|
|
|
day := dateTime.Day()
|
|
|
|
city := GetCityFromLocation(location)
|
|
|
|
year := dateTime.Year()
|
|
|
|
|
2023-06-10 10:24:57 +02:00
|
|
|
// Remove special characters
|
|
|
|
eventName = regexp.MustCompile(`[^a-zA-Z0-9 ]+`).ReplaceAllString(eventName, "")
|
|
|
|
eventName = strings.Trim(eventName, " ")
|
|
|
|
|
2023-03-31 05:51:05 +02:00
|
|
|
channel := fmt.Sprint(month, "-", day, city, "-", eventName, "-", year)
|
|
|
|
channel = strings.ReplaceAll(channel, " ", "-")
|
|
|
|
channel = strings.ToLower(channel)
|
|
|
|
|
|
|
|
re, _ := regexp.Compile(`[^\w\-]`)
|
|
|
|
channel = re.ReplaceAllString(channel, "")
|
|
|
|
|
|
|
|
return channel
|
|
|
|
}
|
|
|
|
|
2023-03-31 22:49:50 +02:00
|
|
|
// GenerateChannelFromEvent returns a channel object associated with an event
|
|
|
|
func GenerateChannelFromEvent(event common.Event) *Channel {
|
2023-03-31 05:51:05 +02:00
|
|
|
|
|
|
|
channelName := GenerateEventChannelName(event.Name, event.Location, event.DateTime)
|
|
|
|
|
|
|
|
return &Channel{
|
|
|
|
Name: channelName,
|
|
|
|
Verified: false,
|
|
|
|
}
|
|
|
|
}
|