Add role mentions. Resolves
MODIFY
internal/ui/chatview.go
internal/ui/chatview.go
@@ -202,6 +202,16 @@ func (chatView *ChatView) AddMessages(messages []*discordgo.Message) {
if message.Type == discordgo.MessageTypeDefault {
messageText = tview.Escape(message.Content)
+
+ for _, roleID := range message.MentionRoles {
+ role, cacheError := chatView.session.State.Role(message.GuildID, roleID)
+ if cacheError == nil {
+ messageText = strings.NewReplacer(
+ "<@&"+roleID+">", "[blue]@"+role.Name+"[white]",
+ ).Replace(messageText)
+ }
+ }
+
for _, user := range message.Mentions {
var userName string
if message.GuildID != "" {

MODIFY
internal/ui/window.go
internal/ui/window.go
@@ -467,6 +467,14 @@ func NewWindow(app *tview.Application, discord *discordgo.Session) (*Window, err
mentionWindow.GetRoot().AddChild(userNode)
}
}
+
+ for _, role := range guild.Roles {
+ if strings.Contains(strings.ToUpper(role.Name), strings.ToUpper(namePart)) {
+ roleNode := tview.NewTreeNode(role.Name)
+ roleNode.SetReference(role)
+ mentionWindow.GetRoot().AddChild(roleNode)
+ }
+ }
}
} else {
for _, user := range window.selectedChannel.Recipients {
@@ -824,10 +832,16 @@ func NewWindow(app *tview.Application, discord *discordgo.Session) (*Window, err
beginIdx, endIdx := window.messageInput.GetCurrentMentionIndices()
if beginIdx != endIdx {
data, ok := node.GetReference().(string)
- if ok {
oldText := window.messageInput.GetText()
+ if ok {
newText := oldText[:beginIdx] + strings.TrimSpace(data) + oldText[endIdx+1:] + " "
window.messageInput.SetText(newText)
+ } else {
+ role, ok := node.GetReference().(*discordgo.Role)
+ if ok {
+ newText := oldText[:beginIdx-1] + "<@&" + strings.TrimSpace(role.ID) + ">" + oldText[endIdx+1:] + " "
+ window.messageInput.SetText(newText)
+ }
}
}
window.messageInput.mentionHideHandler()

Add role mentions. Resolves #20