riking / AutoDelete

A Discord bot that automatically deletes all messages in a designated channel on a rolling basis
Apache License 2.0
326 stars 118 forks source link

Update main.go #65

Open Darkchove opened 1 year ago

Darkchove commented 1 year ago

Use meaningful variable names: Improve the readability of the code by using more descriptive variable names. For example, instead of conf, you can use config. This will make the code easier to understand and maintain.

Split code into functions: Break down the main function into smaller, self-contained functions. This will improve code organization and make it easier to test and reuse the code. For example, you can create separate functions for reading the configuration file, setting up HTTP servers, and connecting to Discord.

Handle errors properly: Instead of using fmt.Println to print error messages, consider using the log package or returning errors. Printing error messages to the console is not a robust way of handling errors. You can log errors or return them from functions to provide more information about the error and allow for proper error handling.

Use constants or flags for magic numbers: Instead of hardcoding values like time.Hour*1, "/debug/pprof/", and "/metrics", define them as constants or flags. This improves code readability and makes it easier to change these values in the future.

Simplify goroutine creation: Instead of using an anonymous goroutine function, you can create named functions and use the go keyword to start them as goroutines. This makes the code easier to read and understand.

Avoid busy waiting: Instead of using select {} for an infinite loop, consider using a blocking operation such as time.Sleep to pause the execution of the program indefinitely. This avoids unnecessary CPU usage.

Use a logging library: Instead of printing log messages directly to the console, consider using a logging library like logrus or zap. These libraries provide more advanced logging features such as log levels, log formatting, and log rotation.

Apply best practices for error handling: Handle errors consistently throughout the codebase. Consider using error wrapping to provide more context to errors and improve error traceability.