Skip to content

Commit

Permalink
Update main.go
Browse files Browse the repository at this point in the history
  • Loading branch information
CaenJones authored Nov 10, 2023
1 parent 48643fe commit fbaffdb
Showing 1 changed file with 36 additions and 35 deletions.
71 changes: 36 additions & 35 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -906,39 +906,40 @@ func bansContains(b []Ban, addr string, id string) bool {
}

func logUserActivity(user *User, action string, loggingEnabled bool) {
if !loggingEnabled { false //logging on devzat is disabled by default, to enable logging please switch the statement to true
return // If logging is not enabled, it exits the function immediately
}

timestamp := time.Now().Format("2010-03-07 15:04:05")

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 CSV 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 File:", err)
}

writer.Flush()

if err := writer.Error(); err != nil {
fmt.Println("Error flushing CSV writer:", err)
//todo: add averages for user join times and messages sent
}
if !loggingEnabled { false

Check failure on line 909 in main.go

View workflow job for this annotation

GitHub Actions / build_devzat

false (untyped bool constant) is not used
// logging on devzat is disabled by default, to enable logging please switch the statement to true
return // If logging is not enabled, exit the function immediately
}

timestamp := time.Now().Format("2010-03-07 15:04:05")
message := ""

Check failure on line 915 in main.go

View workflow job for this annotation

GitHub Actions / build_devzat

message declared and not used

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 CSV 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 File:", err)
}

writer.Flush()

if err := writer.Error(); err != nil {
fmt.Println("Error flushing CSV writer:", err)
}
}

0 comments on commit fbaffdb

Please sign in to comment.