From 2b9000ad55fcb69b20c85aee3ed413753b40e12c Mon Sep 17 00:00:00 2001 From: Jonas Franz Date: Sat, 27 Oct 2018 00:48:41 +0200 Subject: [PATCH] Add date handler and remove spaghatti code --- bot.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/bot.go b/bot.go index d3dc381..c2653e0 100644 --- a/bot.go +++ b/bot.go @@ -65,7 +65,16 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) { } if m.Content == "!mensa" { - sendMealsForDate(s, time.Now(), m.ChannelID) + date := time.Now() + switch date.Weekday() { + case time.Saturday: + date = date.AddDate(0, 0, -1) + break + case time.Sunday: + date = date.AddDate(0,0, -2) + break + } + sendMealsForDate(s, date, m.ChannelID) } } @@ -103,7 +112,7 @@ func sendMealsForDate(s *discordgo.Session, t time.Time, channel string) { } s.ChannelMessageSendComplex(channel, &discordgo.MessageSend{ Embed: &discordgo.MessageEmbed{ - Title: fmt.Sprintf("** :spaghetti: MenĂ¼ vom %s**", t.Format("02.01.2006")), + Title: fmt.Sprintf("**MenĂ¼ vom %s**", t.Format("02.01.2006")), Fields: messages, Footer: &discordgo.MessageEmbedFooter{ IconURL: "https://pbs.twimg.com/profile_images/643755515118505984/xzZMK7fU_400x400.png",