| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- package main
- import (
- "os"
- "github.com/BurntSushi/toml"
- )
- var conf *config
- type keybindingsChannelsTree struct {
- Focus string
- }
- type keybindingsMessagesView struct {
- Focus string
- SelectPrevious string
- SelectNext string
- SelectFirst string
- SelectLast string
- Reply string
- ReplyMention string
- }
- type keybindingsMessageInputField struct {
- Focus string
- }
- type keybindings struct {
- ChannelsTree keybindingsChannelsTree
- MessagesView keybindingsMessagesView
- MessageInputField keybindingsMessageInputField
- }
- type themeBackground struct {
- // Main background color for primitives.
- Primitive string
- // Background color for contrasting elements.
- Contrast string
- // Background color for even more contrasting elements.
- MoreContrast string
- }
- type themeText struct {
- // Primary text.
- Primary string
- // Secondary text (e.g. labels).
- Secondary string
- // Tertiary text (e.g. subtitles, notes).
- Tertiary string
- // Text on primary-colored backgrounds.
- Inverse string
- // Secondary text on ContrastBackgroundColor-colored backgrounds.
- ContrastSecondary string
- }
- type theme struct {
- // Box borders.
- Border string
- // Box titles.
- Title string
- // Graphics.
- Graphics string
- Background themeBackground
- Text themeText
- }
- type config struct {
- Token string
- Mouse bool
- Notifications bool
- UserAgent string
- GetMessagesLimit int
- Theme theme
- Keybindings keybindings
- }
- func loadConfig() *config {
- u, err := os.UserHomeDir()
- if err != nil {
- panic(err)
- }
- configPath := u + "/.config/discordo.toml"
- if _, err = os.Stat(configPath); os.IsNotExist(err) {
- f, err := os.Create(configPath)
- if err != nil {
- panic(err)
- }
- defer f.Close()
- c := config{
- Mouse: true,
- Notifications: true,
- UserAgent: "" +
- "Mozilla/5.0 (X11; Linux x86_64) " +
- "AppleWebKit/537.36 (KHTML, like Gecko) " +
- "Chrome/92.0.4515.131 Safari/537.36",
- GetMessagesLimit: 50,
- Theme: theme{
- Border: "white",
- Title: "white",
- Graphics: "white",
- Background: themeBackground{
- Primitive: "black",
- Contrast: "blue",
- MoreContrast: "green",
- },
- Text: themeText{
- Primary: "white",
- Secondary: "yellow",
- Tertiary: "green",
- Inverse: "blue",
- ContrastSecondary: "darkcyan",
- },
- },
- Keybindings: keybindings{
- ChannelsTree: keybindingsChannelsTree{
- Focus: "Alt+Rune[1]",
- },
- MessagesView: keybindingsMessagesView{
- Focus: "Alt+Rune[2]",
- SelectPrevious: "Up",
- SelectNext: "Down",
- SelectFirst: "Home",
- SelectLast: "End",
- Reply: "Rune[r]",
- ReplyMention: "Rune[R]",
- },
- MessageInputField: keybindingsMessageInputField{
- Focus: "Alt+Rune[3]",
- },
- },
- }
- err = toml.NewEncoder(f).Encode(c)
- if err != nil {
- panic(err)
- }
- return &c
- }
- var c config
- _, err = toml.DecodeFile(configPath, &c)
- if err != nil {
- panic(err)
- }
- return &c
- }
|