|
|
|
@ -1,13 +1,32 @@
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import "github.com/bwmarrin/discordgo"
|
|
|
|
|
import (
|
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
|
|
"github.com/bwmarrin/discordgo"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var trustCache map[string]float64
|
|
|
|
|
|
|
|
|
|
func getTrust(discordID string) (float64, error) {
|
|
|
|
|
var errNotMember = errors.New("trust: only members have trust value")
|
|
|
|
|
|
|
|
|
|
func getTrust(s *discordgo.Session, discordID string) (float64, error) {
|
|
|
|
|
if v, ok := trustCache[discordID]; ok {
|
|
|
|
|
return v, nil
|
|
|
|
|
}
|
|
|
|
|
member, err := s.GuildMember(guildID, discordID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return 0.0, err
|
|
|
|
|
}
|
|
|
|
|
isMember := false
|
|
|
|
|
for _, role := range member.Roles {
|
|
|
|
|
if role == memberRoleID {
|
|
|
|
|
isMember = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if !isMember {
|
|
|
|
|
return 0.0, errNotMember
|
|
|
|
|
}
|
|
|
|
|
votes, err := getTrustVote(discordID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return 0.0, err
|
|
|
|
@ -27,7 +46,16 @@ func getTotalTrust(s *discordgo.Session) (float64, error) {
|
|
|
|
|
}
|
|
|
|
|
var total float64
|
|
|
|
|
for _, member := range members {
|
|
|
|
|
trust, err := getTrust(member.User.ID)
|
|
|
|
|
isMember := false
|
|
|
|
|
for _, role := range member.Roles {
|
|
|
|
|
if role == memberRoleID {
|
|
|
|
|
isMember = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if !isMember {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
trust, err := getTrust(s, member.User.ID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return 0.0, err
|
|
|
|
|
}
|
|
|
|
|