mirror of
https://github.com/diamondburned/arikawa.git
synced 2024-11-17 20:32:48 +00:00
State: implement #76
This commit is contained in:
parent
1df6bf61fc
commit
d9e0580e45
|
@ -121,34 +121,49 @@ func (s *State) MemberDisplayName(guildID, userID discord.Snowflake) (string, er
|
||||||
return member.Nick, nil
|
return member.Nick, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *State) AuthorColor(message *gateway.MessageCreateEvent) discord.Color {
|
func (s *State) AuthorColor(message *gateway.MessageCreateEvent) (discord.Color, error) {
|
||||||
if !message.GuildID.Valid() {
|
if !message.GuildID.Valid() {
|
||||||
return discord.DefaultMemberColor
|
return 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if message.Member != nil {
|
if message.Member != nil {
|
||||||
guild, err := s.Guild(message.GuildID)
|
guild, err := s.Guild(message.GuildID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return discord.DefaultMemberColor
|
return 0, nil
|
||||||
}
|
}
|
||||||
return discord.MemberColor(*guild, *message.Member)
|
return discord.MemberColor(*guild, *message.Member), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return s.MemberColor(message.GuildID, message.Author.ID)
|
return s.MemberColor(message.GuildID, message.Author.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *State) MemberColor(guildID, userID discord.Snowflake) discord.Color {
|
func (s *State) MemberColor(guildID, userID discord.Snowflake) (discord.Color, error) {
|
||||||
member, err := s.Member(guildID, userID)
|
var wg sync.WaitGroup
|
||||||
if err != nil {
|
|
||||||
return discord.DefaultMemberColor
|
g, gerr := s.Store.Guild(guildID)
|
||||||
|
if gerr != nil {
|
||||||
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
g, gerr = s.Session.Guild(guildID)
|
||||||
|
wg.Done()
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
guild, err := s.Guild(guildID)
|
m, merr := s.Store.Member(guildID, userID)
|
||||||
if err != nil {
|
if merr != nil {
|
||||||
return discord.DefaultMemberColor
|
m, merr = s.Member(guildID, userID)
|
||||||
|
if merr != nil {
|
||||||
|
return 0, errors.Wrap(merr, "failed to get member")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return discord.MemberColor(*guild, *member)
|
wg.Wait()
|
||||||
|
|
||||||
|
if gerr != nil {
|
||||||
|
return 0, errors.Wrap(merr, "failed to get guild")
|
||||||
|
}
|
||||||
|
|
||||||
|
return discord.MemberColor(*g, *m), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
////
|
////
|
||||||
|
@ -159,14 +174,29 @@ func (s *State) Permissions(channelID, userID discord.Snowflake) (discord.Permis
|
||||||
return 0, errors.Wrap(err, "Failed to get channel")
|
return 0, errors.Wrap(err, "Failed to get channel")
|
||||||
}
|
}
|
||||||
|
|
||||||
g, err := s.Guild(ch.GuildID)
|
var wg sync.WaitGroup
|
||||||
if err != nil {
|
|
||||||
return 0, errors.Wrap(err, "Failed to get guild")
|
g, gerr := s.Store.Guild(ch.GuildID)
|
||||||
|
if gerr != nil {
|
||||||
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
g, gerr = s.Session.Guild(ch.GuildID)
|
||||||
|
wg.Done()
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
m, err := s.Member(ch.GuildID, userID)
|
m, merr := s.Store.Member(ch.GuildID, userID)
|
||||||
if err != nil {
|
if merr != nil {
|
||||||
return 0, errors.Wrap(err, "Failed to get member")
|
m, merr = s.Member(ch.GuildID, userID)
|
||||||
|
if merr != nil {
|
||||||
|
return 0, errors.Wrap(merr, "failed to get member")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wg.Wait()
|
||||||
|
|
||||||
|
if gerr != nil {
|
||||||
|
return 0, errors.Wrap(merr, "failed to get guild")
|
||||||
}
|
}
|
||||||
|
|
||||||
return discord.CalcOverwrites(*g, *ch, *m), nil
|
return discord.CalcOverwrites(*g, *ch, *m), nil
|
||||||
|
|
Loading…
Reference in a new issue