|
@@ -7,6 +7,7 @@ import (
|
|
|
"os"
|
|
"os"
|
|
|
"os/exec"
|
|
"os/exec"
|
|
|
"path/filepath"
|
|
"path/filepath"
|
|
|
|
|
+ "regexp"
|
|
|
"runtime"
|
|
"runtime"
|
|
|
"strings"
|
|
"strings"
|
|
|
|
|
|
|
@@ -17,6 +18,8 @@ import (
|
|
|
"github.com/rivo/tview"
|
|
"github.com/rivo/tview"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
+var linkRegex = regexp.MustCompile("https?://.+")
|
|
|
|
|
+
|
|
|
type MessagesTextView struct {
|
|
type MessagesTextView struct {
|
|
|
*tview.TextView
|
|
*tview.TextView
|
|
|
app *App
|
|
app *App
|
|
@@ -109,22 +112,57 @@ func (mtv *MessagesTextView) onInputCapture(e *tcell.EventKey) *tcell.EventKey {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if discord.HasPermission(mtv.app.Session.State, mtv.app.SelectedChannel.ID, discordgo.PermissionSendMessages) {
|
|
if discord.HasPermission(mtv.app.Session.State, mtv.app.SelectedChannel.ID, discordgo.PermissionSendMessages) {
|
|
|
- messageActionsList.AddItem("Reply", "", 'r', nil)
|
|
|
|
|
- messageActionsList.AddItem("Mention Reply", "", 'R', nil)
|
|
|
|
|
|
|
+ messageActionsList.AddItem("Reply", "", 'r', func() {
|
|
|
|
|
+ mtv.app.MessageInputField.SetTitle("Replying to " + m.Author.String())
|
|
|
|
|
+ mtv.app.
|
|
|
|
|
+ SetRoot(mtv.app.MainFlex, true).
|
|
|
|
|
+ SetFocus(mtv.app.MessageInputField)
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ messageActionsList.AddItem("Mention Reply", "", 'R', func() {
|
|
|
|
|
+ mtv.app.MessageInputField.SetTitle("[@] Replying to " + m.Author.String())
|
|
|
|
|
+ mtv.app.
|
|
|
|
|
+ SetRoot(mtv.app.MainFlex, false).
|
|
|
|
|
+ SetFocus(mtv.app.MessageInputField)
|
|
|
|
|
+ })
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if m.ReferencedMessage != nil {
|
|
if m.ReferencedMessage != nil {
|
|
|
messageActionsList.AddItem("Select Reply", "", 'm', nil)
|
|
messageActionsList.AddItem("Select Reply", "", 'm', nil)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ links := linkRegex.FindAllString(m.Content, -1)
|
|
|
|
|
+ if len(links) != 0 {
|
|
|
|
|
+ messageActionsList.AddItem("Open Link", "", 'l', func() {
|
|
|
|
|
+ for _, l := range links {
|
|
|
|
|
+ go Open(l)
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
if len(m.Attachments) != 0 {
|
|
if len(m.Attachments) != 0 {
|
|
|
messageActionsList.AddItem("Download Attachment", "", 'd', nil)
|
|
messageActionsList.AddItem("Download Attachment", "", 'd', nil)
|
|
|
messageActionsList.AddItem("Open Attachment", "", 'o', nil)
|
|
messageActionsList.AddItem("Open Attachment", "", 'o', nil)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ messageActionsList.AddItem("Copy Content", "", 'c', func() {
|
|
|
|
|
+ if err := clipboard.WriteAll(m.Content); err != nil {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ mtv.app.SetRoot(mtv.app.MainFlex, false)
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ messageActionsList.AddItem("Copy ID", "", 'i', func() {
|
|
|
|
|
+ if err := clipboard.WriteAll(m.ID); err != nil {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ mtv.app.SetRoot(mtv.app.MainFlex, true)
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
messageActionsList.
|
|
messageActionsList.
|
|
|
ShowSecondaryText(false).
|
|
ShowSecondaryText(false).
|
|
|
- AddItem("Copy Content", "", 'c', nil).
|
|
|
|
|
AddItem("Copy ID", "", 'i', nil).
|
|
AddItem("Copy ID", "", 'i', nil).
|
|
|
SetDoneFunc(func() {
|
|
SetDoneFunc(func() {
|
|
|
mtv.app.
|
|
mtv.app.
|
|
@@ -155,28 +193,6 @@ func (mtv *MessagesTextView) onInputCapture(e *tcell.EventKey) *tcell.EventKey {
|
|
|
|
|
|
|
|
func onMessageActionsListSelected(app *App, mainText string, m *discordgo.Message) {
|
|
func onMessageActionsListSelected(app *App, mainText string, m *discordgo.Message) {
|
|
|
switch mainText {
|
|
switch mainText {
|
|
|
- case "Copy Content":
|
|
|
|
|
- if err := clipboard.WriteAll(m.Content); err != nil {
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- app.SetRoot(app.MainFlex, false)
|
|
|
|
|
- case "Copy ID":
|
|
|
|
|
- if err := clipboard.WriteAll(m.ID); err != nil {
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- app.SetRoot(app.MainFlex, false)
|
|
|
|
|
- case "Reply":
|
|
|
|
|
- app.MessageInputField.SetTitle("Replying to " + m.Author.String())
|
|
|
|
|
- app.
|
|
|
|
|
- SetRoot(app.MainFlex, false).
|
|
|
|
|
- SetFocus(app.MessageInputField)
|
|
|
|
|
- case "Mention Reply":
|
|
|
|
|
- app.MessageInputField.SetTitle("[@] Replying to " + m.Author.String())
|
|
|
|
|
- app.
|
|
|
|
|
- SetRoot(app.MainFlex, false).
|
|
|
|
|
- SetFocus(app.MessageInputField)
|
|
|
|
|
case "Select Reply":
|
|
case "Select Reply":
|
|
|
app.SelectedMessage, _ = discord.FindMessageByID(app.SelectedChannel.Messages, m.ReferencedMessage.ID)
|
|
app.SelectedMessage, _ = discord.FindMessageByID(app.SelectedChannel.Messages, m.ReferencedMessage.ID)
|
|
|
app.MessagesTextView.
|
|
app.MessagesTextView.
|