Add channel-link highlighting
MODIFY
internal/ui/chatview.go
internal/ui/chatview.go
@@ -2,6 +2,7 @@ package ui
import (
"fmt"
+ "regexp"
"strings"
"github.com/Bios-Marcel/cordless/internal/config"
@@ -12,13 +13,15 @@ import (
type ChatView struct {
internalTextView *tview.TextView
+ session *discordgo.Session
data []*discordgo.Message
ownUserID string
}
-func NewChatView(ownUserID string) *ChatView {
+func NewChatView(session *discordgo.Session, ownUserID string) *ChatView {
chatView := ChatView{
internalTextView: tview.NewTextView(),
+ session: session,
ownUserID: ownUserID,
}
@@ -70,6 +73,20 @@ func (chatView *ChatView) SetMessages(messages []*discordgo.Message) {
).Replace(messageText)
}
+ messageText = regexp.
+ MustCompile("<#\\d*>").
+ ReplaceAllStringFunc(messageText, func(data string) string {
+ channelID := strings.TrimSuffix(strings.TrimPrefix(data, "<#"), ">")
+ channel, cacheError := chatView.session.State.Channel(channelID)
+ if cacheError != nil {
+ return data
+ }
+
+ return "[blue]#" + channel.Name + "[white]"
+ })
+
+ //TODO Role mentions
+
if message.Attachments != nil && len(message.Attachments) != 0 {
if messageText != "" {
messageText = messageText + " "

MODIFY
internal/ui/window.go
internal/ui/window.go
@@ -316,7 +316,7 @@ func NewWindow(discord *discordgo.Session) (*Window, error) {
window.chatArea = tview.NewFlex()
window.chatArea.SetDirection(tview.FlexRow)
- window.chatView = NewChatView(window.session.State.User.ID)
+ window.chatView = NewChatView(window.session, window.session.State.User.ID)
window.messageContainer = window.chatView.GetPrimitive()
window.messageInput = tview.NewInputField()

Add channel-link highlighting