| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- package util
- import (
- "os"
- "github.com/BurntSushi/toml"
- "github.com/rivo/tview"
- )
- const userAgent = "" +
- "Mozilla/5.0 (X11; Linux x86_64) " +
- "AppleWebKit/537.36 (KHTML, like Gecko) " +
- "Chrome/92.0.4515.131 Safari/537.36"
- type keybindings struct {
- FocusChannelsTree string `toml:"focus_channels_tree"`
- FocusMessagesView string `toml:"focus_messages_view"`
- FocusMessageInputField string `toml:"focus_message_input_field"`
- SelectPreviousMessage string `toml:"select_previous_message"`
- SelectNextMessage string `toml:"select_next_message"`
- SelectFirstMessage string `toml:"select_first_message"`
- SelectLastMessage string `toml:"select_last_message"`
- SelectMessageReference string `toml:"select_message_reference"`
- ReplySelectedMessage string `toml:"reply_selected_message"`
- MentionReplySelectedMessage string `toml:"mention_reply_selected_message"`
- CopySelectedMessage string `toml:"copy_selected_message"`
- }
- type theme struct {
- Background string `toml:"background"`
- Border string `toml:"border"`
- Title string `toml:"title"`
- Graphics string `toml:"graphics"`
- Text string `toml:"text"`
- }
- type borders struct {
- Horizontal rune
- Vertical rune
- TopLeft rune
- TopRight rune
- BottomLeft rune
- BottomRight rune
- LeftT rune
- RightT rune
- TopT rune
- BottomT rune
- Cross rune
- HorizontalFocus rune
- VerticalFocus rune
- TopLeftFocus rune
- TopRightFocus rune
- BottomLeftFocus rune
- BottomRightFocus rune
- }
- type Config struct {
- Token string `toml:"token"`
- UserAgent string `toml:"user_agent"`
- Mouse bool `toml:"mouse"`
- Notifications bool `toml:"notifications"`
- GetMessagesLimit int `toml:"get_messages_limit"`
- Theme theme `toml:"theme"`
- Keybindings keybindings `toml:"keybindings"`
- Borders borders `toml:"borders"`
- }
- func LoadConfig() *Config {
- configPath, err := os.UserConfigDir()
- if err != nil {
- panic(err)
- }
- configPath += "/discordo.toml"
- var c Config
- 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: userAgent,
- GetMessagesLimit: 50,
- Borders: tview.Borders,
- Theme: theme{
- Background: "black",
- Border: "white",
- Title: "white",
- Graphics: "white",
- Text: "white",
- },
- Keybindings: keybindings{
- FocusChannelsTree: "Alt+Left",
- FocusMessagesView: "Alt+Right",
- FocusMessageInputField: "Alt+Down",
- SelectPreviousMessage: "Up",
- SelectNextMessage: "Down",
- SelectFirstMessage: "Home",
- SelectLastMessage: "End",
- ReplySelectedMessage: "Rune[r]",
- MentionReplySelectedMessage: "Rune[R]",
- CopySelectedMessage: "Rune[c]",
- SelectMessageReference: "Rune[m]",
- },
- }
- err = toml.NewEncoder(f).Encode(c)
- if err != nil {
- panic(err)
- }
- } else {
- _, err = toml.DecodeFile(configPath, &c)
- if err != nil {
- panic(err)
- }
- }
- return &c
- }
|