Mirror of github.com/gissleh/irc
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.1 KiB

6 years ago
6 years ago
6 years ago
  1. package irc
  2. import (
  3. "strconv"
  4. )
  5. // The Config for an IRC client.
  6. type Config struct {
  7. // The nick that you go by. By default it's "IrcUser"
  8. Nick string `json:"nick"`
  9. // Alternatives are a list of nicks to try if Nick is occupied, in order of preference. By default
  10. // it's your nick with numbers 1 through 9.
  11. Alternatives []string `json:"alternatives"`
  12. // User is sent along with all messages and commonly shown before the @ on join, quit, etc....
  13. // Some servers tack on a ~ in front of it if you do not have an ident server.
  14. User string `json:"user"`
  15. // RealName is shown in WHOIS as your real name. By default "..."
  16. RealName string `json:"realName"`
  17. // SkipSSLVerification disables SSL certificate verification. Do not do this
  18. // in production.
  19. SkipSSLVerification bool `json:"skipSslVerification"`
  20. // The Password used upon connection. This is not your NickServ/SASL password!
  21. Password string `json:"password"`
  22. // The rate (lines per second) to send with Client.SendQueued. Default is 2, which is how
  23. // clients that don't excess flood does it.
  24. SendRate int `json:"sendRate"`
  25. // Languages to request.
  26. Languages []string `json:"languages"`
  27. // Auto-join on invite (bad idea).
  28. AutoJoinInvites bool `json:"autoJoinInvites"`
  29. // Whether to use the server time tag to overwrite event time.
  30. UseServerTime bool `json:"useServerTime"`
  31. // Use SASL authorization if supported.
  32. SASL *SASLConfig `json:"sasl"`
  33. }
  34. type SASLConfig struct {
  35. AuthenticationIdentity string `json:"authenticationIdentity"`
  36. AuthorizationIdentity string `json:"authorizationIdentity"`
  37. Password string `json:"password"`
  38. }
  39. // WithDefaults returns the config with the default values
  40. func (config Config) WithDefaults() Config {
  41. if config.Nick == "" {
  42. config.Nick = "IrcUser"
  43. }
  44. if config.User == "" {
  45. config.User = "IrcUser"
  46. }
  47. if config.RealName == "" {
  48. config.RealName = "..."
  49. }
  50. if len(config.Alternatives) == 0 {
  51. config.Alternatives = make([]string, 9)
  52. for i := 0; i < 9; i++ {
  53. config.Alternatives[i] = config.Nick + strconv.FormatInt(int64(i+1), 10)
  54. }
  55. }
  56. if config.SendRate <= 0 {
  57. config.SendRate = 2
  58. }
  59. return config
  60. }