config.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. package main
  2. import (
  3. "os"
  4. "github.com/BurntSushi/toml"
  5. )
  6. const userAgent = "" +
  7. "Mozilla/5.0 (X11; Linux x86_64) " +
  8. "AppleWebKit/537.36 (KHTML, like Gecko) " +
  9. "Chrome/92.0.4515.131 Safari/537.36"
  10. var conf *config
  11. type keybindingsChannelsTree struct {
  12. Focus string
  13. }
  14. type keybindingsMessagesView struct {
  15. Focus string
  16. SelectPrevious string
  17. SelectNext string
  18. SelectFirst string
  19. SelectLast string
  20. Reply string
  21. ReplyMention string
  22. }
  23. type keybindingsMessageInputField struct {
  24. Focus string
  25. }
  26. type keybindings struct {
  27. ChannelsTree keybindingsChannelsTree
  28. MessagesView keybindingsMessagesView
  29. MessageInputField keybindingsMessageInputField
  30. }
  31. type themeBackground struct {
  32. // Main background color for primitives.
  33. Primitive string
  34. // Background color for contrasting elements.
  35. Contrast string
  36. // Background color for even more contrasting elements.
  37. MoreContrast string
  38. }
  39. type themeText struct {
  40. // Primary text.
  41. Primary string
  42. // Secondary text (e.g. labels).
  43. Secondary string
  44. // Tertiary text (e.g. subtitles, notes).
  45. Tertiary string
  46. // Text on primary-colored backgrounds.
  47. Inverse string
  48. // Secondary text on ContrastBackgroundColor-colored backgrounds.
  49. ContrastSecondary string
  50. }
  51. type theme struct {
  52. // Box borders.
  53. Border string
  54. // Box titles.
  55. Title string
  56. // Graphics.
  57. Graphics string
  58. Background themeBackground
  59. Text themeText
  60. }
  61. type config struct {
  62. Token string
  63. Mouse bool
  64. Notifications bool
  65. UserAgent string
  66. GetMessagesLimit int
  67. Theme theme
  68. Keybindings keybindings
  69. }
  70. func loadConfig() *config {
  71. configPath, err := os.UserConfigDir()
  72. if err != nil {
  73. panic(err)
  74. }
  75. configPath += "/discordo.toml"
  76. var c config
  77. if _, err = os.Stat(configPath); os.IsNotExist(err) {
  78. f, err := os.Create(configPath)
  79. if err != nil {
  80. panic(err)
  81. }
  82. defer f.Close()
  83. c.Mouse = true
  84. c.Notifications = true
  85. c.UserAgent = userAgent
  86. c.GetMessagesLimit = 50
  87. c.Theme = theme{
  88. Border: "white",
  89. Title: "white",
  90. Graphics: "white",
  91. Background: themeBackground{
  92. Primitive: "black",
  93. Contrast: "blue",
  94. MoreContrast: "green",
  95. },
  96. Text: themeText{
  97. Primary: "white",
  98. Secondary: "yellow",
  99. Tertiary: "green",
  100. Inverse: "blue",
  101. ContrastSecondary: "darkcyan",
  102. },
  103. }
  104. c.Keybindings = keybindings{
  105. ChannelsTree: keybindingsChannelsTree{
  106. Focus: "Alt+Rune[1]",
  107. },
  108. MessagesView: keybindingsMessagesView{
  109. Focus: "Alt+Rune[2]",
  110. SelectPrevious: "Up",
  111. SelectNext: "Down",
  112. SelectFirst: "Home",
  113. SelectLast: "End",
  114. Reply: "Rune[r]",
  115. ReplyMention: "Rune[R]",
  116. },
  117. MessageInputField: keybindingsMessageInputField{
  118. Focus: "Alt+Rune[3]",
  119. },
  120. }
  121. err = toml.NewEncoder(f).Encode(c)
  122. if err != nil {
  123. panic(err)
  124. }
  125. } else {
  126. _, err = toml.DecodeFile(configPath, &c)
  127. if err != nil {
  128. panic(err)
  129. }
  130. }
  131. return &c
  132. }