-
Notifications
You must be signed in to change notification settings - Fork 927
/
memberfetcher.go
50 lines (40 loc) · 1.17 KB
/
memberfetcher.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package bot
import (
"github.com/jonas747/dstate/v4"
"github.com/jonas747/yagpdb/bot/shardmemberfetcher"
"github.com/jonas747/yagpdb/common"
)
var (
memberFetcher *shardmemberfetcher.Manager
)
// GetMember will either return a member from state or fetch one from the member fetcher and then put it in state
func GetMember(guildID, userID int64) (*dstate.MemberState, error) {
if memberFetcher != nil {
return memberFetcher.GetMember(guildID, userID)
}
ms := State.GetMember(guildID, userID)
if ms != nil && ms.Member != nil {
return ms, nil
}
member, err := common.BotSession.GuildMember(guildID, userID)
if err != nil {
return nil, err
}
return dstate.MemberStateFromMember(member), nil
}
// GetMembers is the same as GetMember but with multiple members
func GetMembers(guildID int64, userIDs ...int64) ([]*dstate.MemberState, error) {
if memberFetcher != nil {
return memberFetcher.GetMembers(guildID, userIDs...)
}
// fall back to something really slow
result := make([]*dstate.MemberState, 0, len(userIDs))
for _, v := range userIDs {
r, err := GetMember(guildID, v)
if err != nil {
continue
}
result = append(result, r)
}
return result, nil
}