From 260d681d047d8855f5457b3948100b09cf2371ad Mon Sep 17 00:00:00 2001 From: Dusty Pianalto Date: Sun, 19 Apr 2020 21:59:38 -0800 Subject: [PATCH] Add logging handler and channel --- djpianalto.com/goff/utils/logging.go | 34 ++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 djpianalto.com/goff/utils/logging.go diff --git a/djpianalto.com/goff/utils/logging.go b/djpianalto.com/goff/utils/logging.go new file mode 100644 index 0000000..111a344 --- /dev/null +++ b/djpianalto.com/goff/utils/logging.go @@ -0,0 +1,34 @@ +package utils + +import ( + "fmt" + "github.com/bwmarrin/discordgo" +) + +var LoggingChannel = make(chan *LogEvent, 10) + +type LogEvent struct { + // Embed with log message + Embed discordgo.MessageEmbed + // Guild to log event in + GuildID string + // Discordgo Session. Needed for sending messages + Session discordgo.Session +} + +func LoggingHandler(lc chan *LogEvent) { + for event := range lc { + var channelID string + row := Database.QueryRow("SELECT logging_channel FROM guilds where id=$1", event.GuildID) + err := row.Scan(&channelID) + if err != nil { + fmt.Println(err) + return + } + if channelID == "" { + return + } + + _, _ = event.Session.ChannelMessageSendEmbed(channelID, &event.Embed) + } +}