1
0
Fork 0
mirror of https://github.com/diamondburned/cchat-discord.git synced 2024-12-22 20:36:45 +00:00

user mention cache; update deps

This commit is contained in:
diamondburned 2021-01-01 00:42:33 -08:00
parent 96e97aa117
commit d8599a5287
3 changed files with 31 additions and 20 deletions

4
go.mod
View file

@ -3,9 +3,9 @@ module github.com/diamondburned/cchat-discord
go 1.14
require (
github.com/diamondburned/arikawa/v2 v2.0.0-20201227001310-f3f075b27f44
github.com/diamondburned/arikawa/v2 v2.0.0-20210101083335-169b36126239
github.com/diamondburned/cchat v0.3.15
github.com/diamondburned/ningen/v2 v2.0.0-20201227034843-dc1d22fc28e4
github.com/diamondburned/ningen/v2 v2.0.0-20210101084041-d9a5058b63b5
github.com/dustin/go-humanize v1.0.0
github.com/go-test/deep v1.0.7
github.com/lithammer/fuzzysearch v1.1.1

5
go.sum
View file

@ -63,6 +63,9 @@ github.com/diamondburned/arikawa/v2 v2.0.0-20201220032235-088b30430377 h1:71BLnE
github.com/diamondburned/arikawa/v2 v2.0.0-20201220032235-088b30430377/go.mod h1:e+lhS20ni2luFEU06Pc8paCxgZL99/RZb77dOC82CF0=
github.com/diamondburned/arikawa/v2 v2.0.0-20201227001310-f3f075b27f44 h1:i6Jec7bvVY8NhwW3L0SlpfWM6r2p2i67XuhiOEzkfwI=
github.com/diamondburned/arikawa/v2 v2.0.0-20201227001310-f3f075b27f44/go.mod h1:e+lhS20ni2luFEU06Pc8paCxgZL99/RZb77dOC82CF0=
github.com/diamondburned/arikawa/v2 v2.0.0-20210101074829-c6d8c741e883/go.mod h1:e+lhS20ni2luFEU06Pc8paCxgZL99/RZb77dOC82CF0=
github.com/diamondburned/arikawa/v2 v2.0.0-20210101083335-169b36126239 h1:ogL6/TJJecNYkvREJa+nHZ326b+QjHN/eLXMUtiyz/A=
github.com/diamondburned/arikawa/v2 v2.0.0-20210101083335-169b36126239/go.mod h1:e+lhS20ni2luFEU06Pc8paCxgZL99/RZb77dOC82CF0=
github.com/diamondburned/cchat v0.0.34 h1:BGiVxMRA9dmW3rLilIldBvjVan7eTTpaWCCfX9IKBYU=
github.com/diamondburned/cchat v0.0.34/go.mod h1:+zXktogE45A0om4fT6B/z6Ii7FXNafjxsNspI0rlhbU=
github.com/diamondburned/cchat v0.0.35 h1:WiMGl8BQJgbP9E4xRxgLGlqUsHpTcJgDKDt8/6a7lBk=
@ -203,6 +206,8 @@ github.com/diamondburned/ningen/v2 v2.0.0-20201227020621-a4e33db11d3c h1:IWn/N54
github.com/diamondburned/ningen/v2 v2.0.0-20201227020621-a4e33db11d3c/go.mod h1:zQkAo1RT4ru4HW6B5T4IRO2pee8ITzTUA2Y7XNpgjqo=
github.com/diamondburned/ningen/v2 v2.0.0-20201227034843-dc1d22fc28e4 h1:ptIpcyB/FIBM5viKLVXuBiE1utqBcH4S3l5kUQrsL9Q=
github.com/diamondburned/ningen/v2 v2.0.0-20201227034843-dc1d22fc28e4/go.mod h1:zQkAo1RT4ru4HW6B5T4IRO2pee8ITzTUA2Y7XNpgjqo=
github.com/diamondburned/ningen/v2 v2.0.0-20210101084041-d9a5058b63b5 h1:GKqBXunV2AC/owpkiaFng1wPxgxE76sQ8HEPAHGj29o=
github.com/diamondburned/ningen/v2 v2.0.0-20210101084041-d9a5058b63b5/go.mod h1:WRQCUX/dTH4OPEy3JANLA5D6fbumzp5zk03uSUAZppA=
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,7 +64,7 @@ func (m NameSegment) AsAvatarer() text.Avatarer { return &m.um }
// AsColorer only returns User if the user actually has a colored role.
func (m NameSegment) AsColorer() text.Colorer {
if m.um.HasColor() {
return m.um
return &m.um
}
return nil
}
@ -75,6 +75,10 @@ type User struct {
Guild discord.Guild
Member discord.Member
color uint32
hasColor bool
fetchedColor bool
}
var (
@ -115,51 +119,53 @@ func (um *User) WithState(state *ningen.State) {
}
// HasColor returns true if the current user has a color.
func (um User) HasColor() bool {
func (um *User) HasColor() bool {
if um.fetchedColor {
return um.hasColor
}
// We don't have any member color if we have neither the member nor guild.
if !um.Guild.ID.IsValid() || !um.Member.User.ID.IsValid() {
um.fetchedColor = true
return false
}
g, err := um.store.Guild(um.Guild.ID)
if err != nil {
um.fetchedColor = true
return false
}
_, ok := MemberColor(*g, um.Member)
return ok
um.fetchedColor = true
um.color, um.hasColor = MemberColor(*g, um.Member)
return um.hasColor
}
func (um User) Color() uint32 {
g, err := um.store.Guild(um.Guild.ID)
if err != nil {
return colored.Blurple
func (um *User) Color() uint32 {
if um.HasColor() {
return text.SolidColor(um.color)
}
color, ok := MemberColor(*g, um.Member)
if !ok {
return colored.Blurple
}
return text.SolidColor(color)
return colored.Blurple
}
func (um User) AvatarSize() int {
func (um *User) AvatarSize() int {
return 96
}
func (um User) AvatarText() string {
func (um *User) AvatarText() string {
if um.Member.Nick != "" {
return um.Member.Nick
}
return um.Member.User.Username
}
func (um User) Avatar() (url string) {
func (um *User) Avatar() (url string) {
return urlutils.AvatarURL(um.Member.User.AvatarURL())
}
func (um User) MentionInfo() text.Rich {
func (um *User) MentionInfo() text.Rich {
var content bytes.Buffer
var segment text.Rich