mirror of
https://github.com/diamondburned/arikawa.git
synced 2025-01-08 04:57:31 +00:00
State: implement #114
This commit is contained in:
parent
efd2ce4c03
commit
943ca00ae5
|
@ -412,26 +412,40 @@ func (s *State) Members(guildID discord.Snowflake) ([]discord.Member, error) {
|
||||||
|
|
||||||
////
|
////
|
||||||
|
|
||||||
func (s *State) Message(
|
func (s *State) Message(channelID, messageID discord.Snowflake) (*discord.Message, error) {
|
||||||
channelID, messageID discord.Snowflake) (*discord.Message, error) {
|
|
||||||
|
|
||||||
m, err := s.Store.Message(channelID, messageID)
|
m, err := s.Store.Message(channelID, messageID)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
m, err = s.Session.Message(channelID, messageID)
|
var wg sync.WaitGroup
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
c, cerr := s.Store.Channel(channelID)
|
||||||
|
if cerr != nil {
|
||||||
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
c, err = s.Session.Channel(channelID)
|
||||||
|
if err == nil {
|
||||||
|
err = s.Store.ChannelSet(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fill the GuildID, because Discord doesn't do it for us.
|
wg.Done()
|
||||||
c, err := s.Channel(channelID)
|
}()
|
||||||
if err == nil {
|
|
||||||
// If it's 0, it's 0 anyway. We don't need a check here.
|
|
||||||
m.GuildID = c.GuildID
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m, err = s.Session.Message(channelID, messageID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "unable to fetch message")
|
||||||
|
}
|
||||||
|
|
||||||
|
wg.Wait()
|
||||||
|
|
||||||
|
if cerr != nil {
|
||||||
|
return nil, errors.Wrap(cerr, "unable to fetch channel")
|
||||||
|
}
|
||||||
|
|
||||||
|
m.ChannelID = c.ID
|
||||||
|
|
||||||
return m, s.Store.MessageSet(m)
|
return m, s.Store.MessageSet(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue