Skip to content

Commit

Permalink
Update main.go
Browse files Browse the repository at this point in the history
  • Loading branch information
vcc3v authored Nov 8, 2023
1 parent 5c56974 commit df705a2
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -904,27 +904,27 @@ func bansContains(b []Ban, addr string, id string) bool {
}
return false
}

func logUserActivity(user *User, action string, loggingEnabled bool) {
if !loggingEnabled { false //user logging on devzat is disabled by default, to enable please switch the statement to true

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
return
}

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

var message string
message := ""

Check failure on line 914 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"
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)
fmt.Println("Error Opening CSV File:", err)
return
}
defer file.Close()
Expand All @@ -933,12 +933,13 @@ func logUserActivity(user *User, action string, loggingEnabled bool) {

record := []string{user.Name, action, timestamp}
if err := writer.Write(record); err != nil {
fmt.Println("Error writing to CSV:", err)
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
}
}

0 comments on commit df705a2

Please sign in to comment.