1
0
Fork 0
mirror of https://github.com/diamondburned/cchat-discord.git synced 2025-04-05 03:25:05 +00:00

Minor tweaks to appearance; fixed hyperlinks

This commit is contained in:
diamondburned 2020-07-08 21:13:49 -07:00
parent e08c31b895
commit 1e137df6de
4 changed files with 52 additions and 26 deletions

View file

@ -19,6 +19,7 @@ func completionUserEntry(s state.Store, u discord.User, g *discord.Guild) cchat.
return cchat.CompletionEntry{ return cchat.CompletionEntry{
Raw: u.Mention(), Raw: u.Mention(),
Text: RenderMemberName(*m, *g), Text: RenderMemberName(*m, *g),
Secondary: text.Rich{Content: u.Username + "#" + u.Discriminator},
IconURL: u.AvatarURL(), IconURL: u.AvatarURL(),
} }
} }
@ -27,6 +28,7 @@ func completionUserEntry(s state.Store, u discord.User, g *discord.Guild) cchat.
return cchat.CompletionEntry{ return cchat.CompletionEntry{
Raw: u.Mention(), Raw: u.Mention(),
Text: text.Rich{Content: u.Username}, Text: text.Rich{Content: u.Username},
Secondary: text.Rich{Content: u.Username + "#" + u.Discriminator},
IconURL: u.AvatarURL(), IconURL: u.AvatarURL(),
} }
} }
@ -75,6 +77,7 @@ func (ch *Channel) completeMentions(word string) (entries []cchat.CompletionEntr
entries = append(entries, cchat.CompletionEntry{ entries = append(entries, cchat.CompletionEntry{
Raw: u.Mention(), Raw: u.Mention(),
Text: text.Rich{Content: u.Username}, Text: text.Rich{Content: u.Username},
Secondary: text.Rich{Content: u.Username + "#" + u.Discriminator},
IconURL: u.AvatarURL(), IconURL: u.AvatarURL(),
}) })
if len(entries) >= MaxCompletion { if len(entries) >= MaxCompletion {
@ -106,6 +109,7 @@ func (ch *Channel) completeMentions(word string) (entries []cchat.CompletionEntr
entries = append(entries, cchat.CompletionEntry{ entries = append(entries, cchat.CompletionEntry{
Raw: mem.User.Mention(), Raw: mem.User.Mention(),
Text: RenderMemberName(mem, *g), Text: RenderMemberName(mem, *g),
Secondary: text.Rich{Content: mem.User.Username + "#" + mem.User.Discriminator},
IconURL: mem.User.AvatarURL(), IconURL: mem.User.AvatarURL(),
}) })
if len(entries) >= MaxCompletion { if len(entries) >= MaxCompletion {
@ -180,6 +184,7 @@ func (ch *Channel) completeEmojis(word string) (entries []cchat.CompletionEntry)
entries = append(entries, cchat.CompletionEntry{ entries = append(entries, cchat.CompletionEntry{
Raw: emoji.String(), Raw: emoji.String(),
Text: text.Rich{Content: ":" + emoji.Name + ":"}, Text: text.Rich{Content: ":" + emoji.Name + ":"},
Secondary: text.Rich{Content: guild.Name},
IconURL: urlutils.Sized(emoji.EmojiURL(), 32), // small IconURL: urlutils.Sized(emoji.EmojiURL(), 32), // small
Image: true, Image: true,
}) })

View file

@ -17,10 +17,12 @@ var imageExts = []string{".jpg", ".jpeg", ".png", ".webp", ".gif"}
func (r *TextRenderer) renderEmbeds(embeds []discord.Embed, m *discord.Message, s state.Store) { func (r *TextRenderer) renderEmbeds(embeds []discord.Embed, m *discord.Message, s state.Store) {
for _, embed := range embeds { for _, embed := range embeds {
r.startBlock() r.startBlock()
r.buf.WriteString("---\n") r.buf.WriteString("---")
r.ensureBreak()
r.renderEmbed(embed, m, s) r.renderEmbed(embed, m, s)
r.ensureBreak()
r.buf.WriteString("---") // render prepends newline already r.buf.WriteString("---") // render prepends newline already
r.endBlock() r.endBlock()
} }

View file

@ -5,6 +5,11 @@ import (
"github.com/yuin/goldmark/ast" "github.com/yuin/goldmark/ast"
) )
// linkState is used for ast.Link segments.
type linkState struct {
linkstack []int // stack of starting integers
}
type LinkSegment struct { type LinkSegment struct {
start, end int start, end int
url string url string
@ -13,17 +18,30 @@ type LinkSegment struct {
var _ text.Linker = (*LinkSegment)(nil) var _ text.Linker = (*LinkSegment)(nil)
func (r *TextRenderer) link(n *ast.Link, enter bool) ast.WalkStatus { func (r *TextRenderer) link(n *ast.Link, enter bool) ast.WalkStatus {
// If we're entering the link node, then add the starting point to the stack
// and move on.
if enter { if enter {
// Write the actual title. r.lnks.linkstack = append(r.lnks.linkstack, r.buf.Len())
start, end := r.write(n.Title) return ast.WalkContinue
}
// Close the segment. // If there's nothing in the stack, then don't do anything. This shouldn't
// happen.
if len(r.lnks.linkstack) == 0 {
return ast.WalkContinue
}
// We're exiting the link node. Pop the segment off the stack.
ilast := len(r.lnks.linkstack) - 1
start := r.lnks.linkstack[ilast]
r.lnks.linkstack = r.lnks.linkstack[:ilast]
// Close the segment on enter false.
r.append(LinkSegment{ r.append(LinkSegment{
start, start,
end, r.buf.Len(),
string(n.Destination), string(n.Destination),
}) })
}
return ast.WalkContinue return ast.WalkContinue
} }

View file

@ -55,6 +55,7 @@ type TextRenderer struct {
src []byte src []byte
segs []text.Segment segs []text.Segment
inls inlineState inls inlineState
lnks linkState
// these fields can be nil // these fields can be nil
msg *discord.Message msg *discord.Message