1
0
Fork 0
mirror of https://github.com/diamondburned/cchat-discord.git synced 2024-11-23 06:32:50 +00:00

Tweaked embeds' appearance to be a bit more appealing

This commit is contained in:
diamondburned 2020-07-08 02:15:45 -07:00
parent cd5d00a07e
commit 601e8abeb2
2 changed files with 16 additions and 11 deletions

View file

@ -33,7 +33,7 @@ func (r *TextRenderer) renderEmbed(embed discord.Embed, m *discord.Message, s st
} }
start, end := r.writeString(a.Name) start, end := r.writeString(a.Name)
r.buf.WriteByte('\n') r.ensureBreak()
if a.URL != "" { if a.URL != "" {
r.append(LinkSegment{ r.append(LinkSegment{
@ -46,7 +46,7 @@ func (r *TextRenderer) renderEmbed(embed discord.Embed, m *discord.Message, s st
if embed.Title != "" { if embed.Title != "" {
start, end := r.writeString(embed.Title) start, end := r.writeString(embed.Title)
r.buf.WriteByte('\n') r.ensureBreak()
if embed.URL != "" { if embed.URL != "" {
r.append(LinkSegment{ r.append(LinkSegment{
@ -60,7 +60,7 @@ func (r *TextRenderer) renderEmbed(embed discord.Embed, m *discord.Message, s st
// If we have a thumbnail, then write one. // If we have a thumbnail, then write one.
if embed.Thumbnail != nil { if embed.Thumbnail != nil {
r.append(EmbedThumbnail(r.buf.Len(), *embed.Thumbnail)) r.append(EmbedThumbnail(r.buf.Len(), *embed.Thumbnail))
r.buf.WriteByte('\n') r.ensureBreak()
} }
if embed.Description != "" { if embed.Description != "" {
@ -75,12 +75,12 @@ func (r *TextRenderer) renderEmbed(embed discord.Embed, m *discord.Message, s st
// Join the created state. // Join the created state.
r.join(desc) r.join(desc)
// Write a new line. // Write a new line.
r.buf.WriteByte('\n') r.ensureBreak()
} }
if len(embed.Fields) > 0 { if len(embed.Fields) > 0 {
// Pad another new line. // Pad two new lines.
r.buf.WriteByte('\n') r.startBlockN(2)
// Write fields indented once. // Write fields indented once.
for _, field := range embed.Fields { for _, field := range embed.Fields {
@ -95,7 +95,7 @@ func (r *TextRenderer) renderEmbed(embed discord.Embed, m *discord.Message, s st
} }
r.buf.WriteString(f.Text) r.buf.WriteString(f.Text)
r.buf.WriteByte('\n') r.ensureBreak()
} }
if embed.Timestamp.Valid() { if embed.Timestamp.Valid() {
@ -104,13 +104,13 @@ func (r *TextRenderer) renderEmbed(embed discord.Embed, m *discord.Message, s st
} }
r.buf.WriteString(embed.Timestamp.Format(time.RFC1123)) r.buf.WriteString(embed.Timestamp.Format(time.RFC1123))
r.buf.WriteByte('\n') r.ensureBreak()
} }
// Write an image if there's one. // Write an image if there's one.
if embed.Image != nil { if embed.Image != nil {
r.append(EmbedImage(r.buf.Len(), *embed.Image)) r.append(EmbedImage(r.buf.Len(), *embed.Image))
r.buf.WriteByte('\n') r.ensureBreak()
} }
} }
@ -120,8 +120,8 @@ func (r *TextRenderer) renderAttachments(attachments []discord.Attachment) {
return return
} }
// Start a (small) new block before rendering attachments. // Start a (small)new block before rendering attachments.
r.startBlockN(1) r.ensureBreak()
// Render all attachments. Newline delimited. // Render all attachments. Newline delimited.
for i, attachment := range attachments { for i, attachment := range attachments {

View file

@ -127,6 +127,11 @@ func (r *TextRenderer) startBlock() {
r.startBlockN(2) r.startBlockN(2)
} }
// ensureBreak ensures that the current line is a new line.
func (r *TextRenderer) ensureBreak() {
r.startBlockN(1)
}
// startBlockN allows a custom block level. // startBlockN allows a custom block level.
func (r *TextRenderer) startBlockN(n int) { func (r *TextRenderer) startBlockN(n int) {
var maxNewlines = 0 var maxNewlines = 0