From 5c569741286ab8adb5ab3304d18b47a7102cad11 Mon Sep 17 00:00:00 2001 From: Caen Jones <131218155+CaenJones@users.noreply.github.com> Date: Wed, 8 Nov 2023 15:03:45 +0000 Subject: [PATCH] Update main.go --- main.go | 72 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/main.go b/main.go index 9c5df6f9..33436846 100644 --- a/main.go +++ b/main.go @@ -904,41 +904,41 @@ func bansContains(b []Ban, addr string, id string) bool { } return false } - func logUserActivity(user *User, action string, loggingEnabled bool) { - if !loggingEnabled { false //logging on Devzat is disabled by default, to enable it please switch the statement from false to true - return - } - - timestamp := time.Now().Format("2010-03-07 15:04:05") - message := "%s joined at: %timestamp%" - - switch action { - case "login": - message = fmt.Sprintf("%s joined at %s", user.Name, timestamp) - case "logout": - message = fmt.Sprintf("%s left at %s", user.Name, timestamp) - default: - message = "Invalid action" - } - - file, err := os.OpenFile("users.csv", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644) -if err != nil { - fmt.Println("Error opening file:", err) - return -} -defer file.Close() - - writer := csv.NewWriter(file) - - record := []string{user.Name, action, timestamp} - if err := writer.Write(record); err != nil { - fmt.Println("Error writing to CSV:", err) - } - - writer.Flush() - - if err := writer.Error(); err != nil { - fmt.Println("Error flushing CSV writer:", err) - } + if !loggingEnabled { false //user logging on devzat is disabled by default, to enable please switch the statement to true + return + } + + timestamp := time.Now().Format("2010-03-07 15:04:05") + + var message string + + switch action { + case "login": + message = fmt.Sprintf("%s joined at %s", user.Name, timestamp) + case "logout": + message = fmt.Sprintf("%s left at %s", user.Name, timestamp) + default: + message = "Invalid action" + } + + file, err := os.OpenFile("users.csv", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644) + if err != nil { + fmt.Println("Error opening file:", err) + return + } + defer file.Close() + + writer := csv.NewWriter(file) + + record := []string{user.Name, action, timestamp} + if err := writer.Write(record); err != nil { + fmt.Println("Error writing to CSV:", err) + } + + writer.Flush() + + if err := writer.Error(); err != nil { + fmt.Println("Error flushing CSV writer:", err) + } }