Add support for recurring events and add year to channel name (#3)

This commit is contained in:
2023-03-05 13:08:18 -05:00
committed by GitHub
parent 97c9006fef
commit 228c293b70
7 changed files with 81 additions and 15 deletions

View File

@ -5,6 +5,7 @@ import (
"fmt"
"log"
"os"
"strings"
"github.com/ilyakaznacheev/cleanenv"
"github.com/yeslayla/birdbot/core"
@ -104,7 +105,7 @@ func (app *Bot) Notify(message string) {
}
func (app *Bot) onReady(d *discord.Discord) {
app.Notify(fmt.Sprintf("BirdBot %s is ready!", Version))
app.session.SetStatus(fmt.Sprintf("with fire! (%s)", Version))
}
func (app *Bot) onEventCreate(d *discord.Discord, event *core.Event) {
@ -184,6 +185,18 @@ func (app *Bot) onEventComplete(d *discord.Discord, event *core.Event) {
log.Printf("Deleted channel: '%s'", channel.Name)
}
if strings.Contains(strings.ToLower(event.Description), "recurring weekly") {
startTime := event.DateTime.AddDate(0, 0, 7)
finishTime := event.CompleteTime.AddDate(0, 0, 7)
nextEvent := event
nextEvent.DateTime = startTime
nextEvent.CompleteTime = finishTime
if err := app.session.CreateEvent(nextEvent); err != nil {
log.Print("Failed to create recurring event: ", err)
}
}
}
func NewBot() *Bot {