Add option for GET Channel Messages limit (#12)
This commit is contained in:
parent
041225ac09
commit
0667b37698
3 changed files with 69 additions and 62 deletions
16
discordo.go
16
discordo.go
|
|
@ -23,7 +23,7 @@ var (
|
|||
mainFlex *tview.Flex
|
||||
|
||||
loginVia string
|
||||
theme *util.Theme
|
||||
config *util.Config
|
||||
session *discordgo.Session
|
||||
currentGuild *discordgo.Guild
|
||||
currentChannel *discordgo.Channel
|
||||
|
|
@ -43,12 +43,12 @@ func main() {
|
|||
tview.Borders.BottomLeft = ' '
|
||||
tview.Borders.BottomRight = ' '
|
||||
|
||||
theme = util.NewTheme()
|
||||
config = util.NewConfig()
|
||||
loginModal = ui.NewLoginModal(onLoginModalDone)
|
||||
guildsDropDown = ui.NewGuildsDropDown(onGuildsDropDownSelected, theme)
|
||||
guildsDropDown = ui.NewGuildsDropDown(onGuildsDropDownSelected, config.Theme)
|
||||
channelsTreeNode = ui.NewChannelsTreeNode()
|
||||
channelsTreeView = ui.NewChannelsTreeView(channelsTreeNode, onChannelsTreeViewSelected, theme)
|
||||
messagesTextView = ui.NewMessagesTextView(onMessagesTextViewChanged, theme)
|
||||
channelsTreeView = ui.NewChannelsTreeView(channelsTreeNode, onChannelsTreeViewSelected, config.Theme)
|
||||
messagesTextView = ui.NewMessagesTextView(onMessagesTextViewChanged, config.Theme)
|
||||
mainFlex = ui.NewMainFlex(guildsDropDown, channelsTreeView, messagesTextView)
|
||||
app = ui.NewApp()
|
||||
|
||||
|
|
@ -180,7 +180,7 @@ func onGuildsDropDownSelected(text string, _ int) {
|
|||
|
||||
switch channel.Type {
|
||||
case discordgo.ChannelTypeGuildCategory:
|
||||
channelNode.SetColor(tcell.GetColor(theme.TreeNodeForeground))
|
||||
channelNode.SetColor(tcell.GetColor(config.Theme.TreeNodeForeground))
|
||||
channelsTreeNode.AddChild(channelNode)
|
||||
default:
|
||||
if channel.ParentID == "" {
|
||||
|
|
@ -195,7 +195,7 @@ func onChannelsTreeViewSelected(node *tview.TreeNode) {
|
|||
messagesTextView.Clear()
|
||||
|
||||
if messageInputField == nil {
|
||||
messageInputField = ui.NewMessageInputField(onMessageInputFieldDone, theme)
|
||||
messageInputField = ui.NewMessageInputField(onMessageInputFieldDone, config.Theme)
|
||||
mainFlex.AddItem(messageInputField, 3, 1, false)
|
||||
}
|
||||
|
||||
|
|
@ -218,7 +218,7 @@ func onChannelsTreeViewSelected(node *tview.TreeNode) {
|
|||
messagesTextView.SetTitle(currentChannel.Name)
|
||||
app.SetFocus(messageInputField)
|
||||
|
||||
messages, err := session.ChannelMessages(currentChannel.ID, 50, "", "", "")
|
||||
messages, err := session.ChannelMessages(currentChannel.ID, config.GetMessagesLimit, "", "", "")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
|
|||
61
util/config.go
Normal file
61
util/config.go
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
package util
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
)
|
||||
|
||||
type Theme struct {
|
||||
DropDownBackground string `json:"dropdown.background"`
|
||||
TreeViewBackground string `json:"treeview.background"`
|
||||
TextViewBackground string `json:"textview.background"`
|
||||
InputFieldBackground string `json:"inputField.background"`
|
||||
|
||||
DropDownForeground string `json:"dropdown.foreground"`
|
||||
TextViewForeground string `json:"textview.foreground"`
|
||||
TreeNodeForeground string `json:"treenode.foreground"`
|
||||
InputFieldForeground string `json:"inputField.foreground"`
|
||||
InputFieldPlaceholderForeground string `json:"inputField.placeholderTextForeground"`
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
GetMessagesLimit int `json:"getMessagesLimit"`
|
||||
Theme *Theme `json:"theme"`
|
||||
}
|
||||
|
||||
func NewConfig() *Config {
|
||||
userHomeDir, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
var config Config = Config{
|
||||
GetMessagesLimit: 50,
|
||||
Theme: &Theme{},
|
||||
}
|
||||
config.Theme.DropDownBackground = "#3B4252"
|
||||
config.Theme.TreeViewBackground = "#282a36"
|
||||
config.Theme.TextViewBackground = "#282a36"
|
||||
config.Theme.InputFieldBackground = "#3B4252"
|
||||
config.Theme.DropDownForeground = "#f8f8f2"
|
||||
config.Theme.TextViewForeground = "#f8f8f2"
|
||||
config.Theme.TreeNodeForeground = "#8be9fd"
|
||||
config.Theme.InputFieldForeground = "#f8f8f2"
|
||||
config.Theme.InputFieldPlaceholderForeground = "#6272a4"
|
||||
|
||||
configPath := userHomeDir + "/.config/discordo/config.json"
|
||||
if _, err := os.Stat(configPath); os.IsNotExist(err) {
|
||||
return &config
|
||||
}
|
||||
|
||||
data, err := os.ReadFile(configPath)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if err = json.Unmarshal(data, &config); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return &config
|
||||
}
|
||||
|
|
@ -1,54 +0,0 @@
|
|||
package util
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
)
|
||||
|
||||
type Theme struct {
|
||||
DropDownBackground string `json:"dropdown.background"`
|
||||
TreeViewBackground string `json:"treeview.background"`
|
||||
TextViewBackground string `json:"textview.background"`
|
||||
InputFieldBackground string `json:"inputField.background"`
|
||||
|
||||
DropDownForeground string `json:"dropdown.foreground"`
|
||||
TextViewForeground string `json:"textview.foreground"`
|
||||
TreeNodeForeground string `json:"treenode.foreground"`
|
||||
InputFieldForeground string `json:"inputField.foreground"`
|
||||
InputFieldPlaceholderForeground string `json:"inputField.placeholderTextForeground"`
|
||||
}
|
||||
|
||||
func NewTheme() *Theme {
|
||||
var theme Theme
|
||||
theme.DropDownBackground = "#3B4252"
|
||||
theme.TreeViewBackground = "#282a36"
|
||||
theme.TextViewBackground = "#282a36"
|
||||
theme.InputFieldBackground = "#3B4252"
|
||||
|
||||
theme.DropDownForeground = "#f8f8f2"
|
||||
theme.TextViewForeground = "#f8f8f2"
|
||||
theme.TreeNodeForeground = "#8be9fd"
|
||||
theme.InputFieldForeground = "#f8f8f2"
|
||||
theme.InputFieldPlaceholderForeground = "#6272a4"
|
||||
|
||||
userHomeDir, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
themeFilePath := userHomeDir + "/.config/discordo/theme.json"
|
||||
if _, err := os.Stat(themeFilePath); os.IsNotExist(err) {
|
||||
return &theme
|
||||
}
|
||||
|
||||
data, err := os.ReadFile(themeFilePath)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if err = json.Unmarshal(data, &theme); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return &theme
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue