config.go 2.9 KB

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