diff --git a/config.go b/config.go index 4791ed8..2fedd45 100644 --- a/config.go +++ b/config.go @@ -11,6 +11,8 @@ const name = "discordo" type ( MessagesTextKeysConfig struct { + CopyContent string `yaml:"copy_content"` + Reply string `yaml:"reply"` ReplyMention string `yaml:"reply_mention"` SelectReply string `yaml:"select_reply"` @@ -90,6 +92,8 @@ func newConfig() (*Config, error) { Cancel: "Esc", MessagesText: MessagesTextKeysConfig{ + CopyContent: "Rune[c]", + Reply: "Rune[r]", ReplyMention: "Rune[R]", SelectReply: "Rune[s]", diff --git a/go.mod b/go.mod index aeb1d2c..d1e0542 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/ayn2op/discordo go 1.19 require ( + github.com/atotto/clipboard v0.1.4 github.com/diamondburned/arikawa/v3 v3.2.0 github.com/gdamore/tcell/v2 v2.5.4 github.com/rivo/tview v0.0.0-20230104153304-892d1a2eb0da diff --git a/go.sum b/go.sum index 5453662..0bf69dd 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,5 @@ +github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4= +github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI= github.com/diamondburned/arikawa/v3 v3.2.0 h1:aBUhg94pxblT6ks4EV7qxEk44tnl0ico67ydqjVnv9g= github.com/diamondburned/arikawa/v3 v3.2.0/go.mod h1:5jBSNnp82Z/EhsKa6Wk9FsOqSxfVkNZDTDBPOj47LpY= github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko= diff --git a/main.go b/main.go index 956bb94..6aae793 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,8 @@ import ( "context" "flag" "log" + "os" + "path/filepath" "github.com/rivo/tview" ) @@ -24,6 +26,26 @@ var ( func init() { flag.StringVar(&token, "token", "", "The authentication token.") + + path, err := os.UserCacheDir() + if err != nil { + log.Fatal(err) + } + + path = filepath.Join(path, name) + err = os.MkdirAll(path, os.ModePerm) + if err != nil { + log.Fatal(err) + } + + path = filepath.Join(path, "logs.txt") + f, err := os.OpenFile(path, os.O_CREATE|os.O_APPEND, os.ModePerm) + if err != nil { + log.Fatal(err) + } + + log.SetOutput(f) + log.SetFlags(log.LstdFlags | log.Llongfile) } func main() { diff --git a/messages_text.go b/messages_text.go index 323a64e..6bf2f0d 100644 --- a/messages_text.go +++ b/messages_text.go @@ -5,6 +5,7 @@ import ( "log" "time" + "github.com/atotto/clipboard" "github.com/ayn2op/discordo/discordmd" "github.com/diamondburned/arikawa/v3/discord" "github.com/gdamore/tcell/v2" @@ -125,6 +126,9 @@ func (mt *MessagesText) createFooter(m *discord.Message) { func (mt *MessagesText) onInputCapture(event *tcell.EventKey) *tcell.EventKey { switch event.Name() { + case config.Keys.MessagesText.CopyContent: + mt.copyContentAction() + return nil case config.Keys.MessagesText.Reply: mt.replyAction(false) return nil @@ -268,3 +272,17 @@ func (mt *MessagesText) selectReplyAction() { mt.ScrollToHighlight() } } + +func (mt *MessagesText) copyContentAction() { + ms, err := discordState.Cabinet.Messages(guildsTree.selectedChannel.ID) + if err != nil { + log.Println(err) + return + } + + err = clipboard.WriteAll(ms[mt.selectedMessage].Content) + if err != nil { + log.Println(err) + return + } +}