Added bot suffixes

This commit is contained in:
diamondburned 2020-07-15 23:25:08 -07:00
parent d1e516c919
commit 093bedb304
6 changed files with 32 additions and 4 deletions

2
go.mod
View File

@ -5,7 +5,7 @@ go 1.14
require (
github.com/diamondburned/arikawa v0.10.5
github.com/diamondburned/cchat v0.0.43
github.com/diamondburned/ningen v0.1.1-0.20200715034121-61de7138eb56
github.com/diamondburned/ningen v0.1.1-0.20200715040340-2395a0dbd0fa
github.com/dustin/go-humanize v1.0.0
github.com/go-test/deep v1.0.6
github.com/pkg/errors v0.9.1

2
go.sum
View File

@ -65,6 +65,8 @@ github.com/diamondburned/ningen v0.1.1-0.20200715015332-cb3c7378b3c8 h1:0IxrMc4b
github.com/diamondburned/ningen v0.1.1-0.20200715015332-cb3c7378b3c8/go.mod h1:SKPY3387RHCbMrnefex9D+zlrA2yB+LCtaaQAgatAuc=
github.com/diamondburned/ningen v0.1.1-0.20200715034121-61de7138eb56 h1:DAk3bEwJZycjfZu4OXDYrR/nmpy3ZS/dfUF0rskfVj0=
github.com/diamondburned/ningen v0.1.1-0.20200715034121-61de7138eb56/go.mod h1:SKPY3387RHCbMrnefex9D+zlrA2yB+LCtaaQAgatAuc=
github.com/diamondburned/ningen v0.1.1-0.20200715040340-2395a0dbd0fa h1:ntHcz6GNzxn3TovtYZVwOBvL3xn7Iq1luaV/KEIEXrk=
github.com/diamondburned/ningen v0.1.1-0.20200715040340-2395a0dbd0fa/go.mod h1:SKPY3387RHCbMrnefex9D+zlrA2yB+LCtaaQAgatAuc=
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=

View File

@ -64,9 +64,17 @@ type Author struct {
}
func NewUser(u discord.User) Author {
var name = text.Rich{Content: u.Username}
if u.Bot {
name.Content += " "
name.Segments = append(name.Segments,
segments.NewBlurpleSegment(segments.Write(&name, "[BOT]")),
)
}
return Author{
id: u.ID,
name: text.Rich{Content: u.Username},
name: name,
avatar: AvatarURL(u.AvatarURL()),
}
}
@ -96,6 +104,13 @@ func RenderMemberName(m discord.Member, g discord.Guild) text.Rich {
}
}
if m.User.Bot {
name.Content += " "
name.Segments = append(name.Segments,
segments.NewBlurpleSegment(segments.Write(&name, "[BOT]")),
)
}
return name
}

View File

@ -2,6 +2,8 @@ package segments
import "github.com/diamondburned/cchat/text"
const blurple = 0x7289DA
type Colored struct {
start int
end int
@ -17,6 +19,10 @@ func NewColored(strlen int, color uint32) Colored {
return Colored{0, strlen, color}
}
func NewBlurpleSegment(start, end int) Colored {
return NewColoredSegment(start, end, blurple)
}
func NewColoredSegment(start, end int, color uint32) Colored {
return Colored{start, end, color}
}

View File

@ -11,6 +11,13 @@ import (
"github.com/yuin/goldmark/ast"
)
func Write(rich *text.Rich, content string, segs ...text.Segment) (start, end int) {
start = len(rich.Content)
end = len(rich.Content) + len(content)
rich.Content += content
return
}
func ParseMessage(m *discord.Message, s state.Store) text.Rich {
var content = []byte(m.Content)
var node = md.ParseWithMessage(content, s, m, true)

View File

@ -12,8 +12,6 @@ import (
"github.com/yuin/goldmark/ast"
)
const blurple = 0x7289DA
type MentionSegment struct {
start, end int
*md.Mention