1
0
Fork 0
mirror of https://github.com/diamondburned/cchat-discord.git synced 2024-11-01 12:24:15 +00:00
cchat-discord/segments/mention.go

49 lines
880 B
Go
Raw Normal View History

2020-06-19 01:00:24 +00:00
package segments
import (
"github.com/diamondburned/cchat/text"
"github.com/diamondburned/ningen/md"
"github.com/yuin/goldmark/ast"
)
const (
mentionChannel uint8 = iota
mentionUser
mentionRole
)
type MentionSegment struct {
start, end int
}
var _ text.Segment = (*MentionSegment)(nil)
func (r *TextRenderer) mention(n *md.Mention, enter bool) ast.WalkStatus {
if enter {
seg := MentionSegment{start: r.i()}
switch {
case n.Channel != nil:
r.buf.WriteString("#" + n.Channel.Name)
case n.GuildUser != nil:
r.buf.WriteString("@" + n.GuildUser.Username)
case n.GuildRole != nil:
r.buf.WriteString("@" + n.GuildRole.Name)
}
seg.end = r.i()
r.append(seg)
}
return ast.WalkContinue
}
func (m MentionSegment) Bounds() (start, end int) {
return m.start, m.end
}
// TODO
func (m MentionSegment) MentionInfo() text.Rich {
return text.Rich{}
}