Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
810d971567 | |||
7c21e20162 | |||
61a16393fa |
3
Makefile
3
Makefile
@ -48,6 +48,9 @@ docker-build:
|
||||
docker-run: docker-build
|
||||
@docker run -it -v `pwd`/build:/etc/birdbot yeslayla/birdbot:latest
|
||||
|
||||
docker-push: docker-build
|
||||
@docker push yeslayla/birdbot:latest
|
||||
|
||||
## install: Download and install dependencies
|
||||
install: go-get
|
||||
|
||||
|
17
app/bot.go
17
app/bot.go
@ -5,7 +5,6 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
"github.com/ilyakaznacheev/cleanenv"
|
||||
@ -32,9 +31,9 @@ func (app *Bot) Initialize(config_path string) error {
|
||||
_, err := os.Stat(config_path)
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
log.Printf("Config file not found: '%s'", config_path)
|
||||
err := cleanenv.ReadEnv(&cfg)
|
||||
err := cleanenv.ReadEnv(cfg)
|
||||
if err != nil {
|
||||
return nil
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
err := cleanenv.ReadConfig(config_path, cfg)
|
||||
@ -77,7 +76,6 @@ func (app *Bot) Run() error {
|
||||
|
||||
// Keep alive
|
||||
app.stop = make(chan os.Signal, 1)
|
||||
signal.Notify(app.stop, os.Interrupt)
|
||||
<-app.stop
|
||||
return nil
|
||||
}
|
||||
@ -108,6 +106,10 @@ func (app *Bot) onReady(s *discordgo.Session, r *discordgo.Ready) {
|
||||
}
|
||||
|
||||
func (app *Bot) onEventCreate(s *discordgo.Session, r *discordgo.GuildScheduledEventCreate) {
|
||||
if r.GuildID != app.guildID {
|
||||
return
|
||||
}
|
||||
|
||||
event := &Event{}
|
||||
event.Name = r.Name
|
||||
event.OrganizerID = r.CreatorID
|
||||
@ -137,6 +139,9 @@ func (app *Bot) onEventCreate(s *discordgo.Session, r *discordgo.GuildScheduledE
|
||||
}
|
||||
|
||||
func (app *Bot) onEventDelete(s *discordgo.Session, r *discordgo.GuildScheduledEventDelete) {
|
||||
if r.GuildID != app.guildID {
|
||||
return
|
||||
}
|
||||
|
||||
// Create Event Object
|
||||
event := &Event{}
|
||||
@ -158,6 +163,9 @@ func (app *Bot) onEventDelete(s *discordgo.Session, r *discordgo.GuildScheduledE
|
||||
}
|
||||
|
||||
func (app *Bot) onEventUpdate(s *discordgo.Session, r *discordgo.GuildScheduledEventUpdate) {
|
||||
if r.GuildID != app.guildID {
|
||||
return
|
||||
}
|
||||
|
||||
// Create Event Object
|
||||
event := &Event{}
|
||||
@ -178,6 +186,7 @@ func (app *Bot) onEventUpdate(s *discordgo.Session, r *discordgo.GuildScheduledE
|
||||
}
|
||||
|
||||
func (app *Bot) onEventComplete(s *discordgo.Session, event *Event) {
|
||||
|
||||
channel_name := event.GetChannelName()
|
||||
|
||||
if app.archiveCategoryID != "" {
|
||||
|
@ -19,10 +19,10 @@ type Event struct {
|
||||
|
||||
func (event *Event) GetChannelName() string {
|
||||
month := event.GetMonthPrefix()
|
||||
day := event.DateTime.Day() - 1
|
||||
day := event.DateTime.Day()
|
||||
city := event.GetCityFromLocation()
|
||||
|
||||
channel := fmt.Sprint(month, "-", day, "-", city, "-", event.Name)
|
||||
channel := fmt.Sprint(month, "-", day, city, "-", event.Name)
|
||||
channel = strings.ReplaceAll(channel, " ", "-")
|
||||
channel = strings.ToLower(channel)
|
||||
|
||||
@ -46,7 +46,7 @@ func (event *Event) GetCityFromLocation() string {
|
||||
if part == "mi" || part == "michigan" {
|
||||
index = i - 1
|
||||
if index < 0 {
|
||||
return "unknown"
|
||||
return ""
|
||||
}
|
||||
if index > 0 && parts[index] == "," {
|
||||
index -= 1
|
||||
@ -62,7 +62,7 @@ func (event *Event) GetCityFromLocation() string {
|
||||
}
|
||||
}
|
||||
|
||||
return loc
|
||||
return fmt.Sprint("-", loc)
|
||||
}
|
||||
|
||||
func (event *Event) GetMonthPrefix() string {
|
||||
|
Reference in New Issue
Block a user