|
|
|
@ -18,6 +18,8 @@ type confirmedResult struct {
|
|
|
|
|
IsPositive bool
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const invalidVote = -1
|
|
|
|
|
|
|
|
|
|
var voteMutex sync.Mutex
|
|
|
|
|
var toAnnounceResultList []confirmedResult
|
|
|
|
|
|
|
|
|
@ -25,6 +27,9 @@ func ListenToVoteFinishes(s *discordgo.Session) {
|
|
|
|
|
for {
|
|
|
|
|
voteMutex.Lock()
|
|
|
|
|
for _, v := range toAnnounceResultList {
|
|
|
|
|
if v.VoteID == invalidVote {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
message.AuditInfo(s, fmt.Sprintf("Announcing the result of vote %d.", v.VoteID))
|
|
|
|
|
if err := db.FinishVote(v.VoteID); err != nil {
|
|
|
|
|
message.AuditError(s, "", err)
|
|
|
|
@ -72,13 +77,13 @@ func checkForVoteResult(s *discordgo.Session, id int) {
|
|
|
|
|
lowestPossible := (currentScore + remainingTrust) / totalGlobalTrust
|
|
|
|
|
highestPossible := (currentScore + remainingTrust*5) / totalGlobalTrust
|
|
|
|
|
|
|
|
|
|
voteMutex.Lock()
|
|
|
|
|
defer voteMutex.Unlock()
|
|
|
|
|
if highestPossible <= 3.5 || absoluteRejectionVote {
|
|
|
|
|
//Rejection confirmed.
|
|
|
|
|
voteMutex.Lock()
|
|
|
|
|
for _, v := range toAnnounceResultList {
|
|
|
|
|
if v.VoteID == id {
|
|
|
|
|
//It's already queued to be announced in the next announcement cycle.
|
|
|
|
|
voteMutex.Unlock()
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -87,15 +92,11 @@ func checkForVoteResult(s *discordgo.Session, id int) {
|
|
|
|
|
VoteID: id,
|
|
|
|
|
IsPositive: false,
|
|
|
|
|
})
|
|
|
|
|
voteMutex.Unlock()
|
|
|
|
|
}
|
|
|
|
|
if lowestPossible >= 3.5 {
|
|
|
|
|
} else if lowestPossible >= 3.5 {
|
|
|
|
|
//Acceptance confirmed.
|
|
|
|
|
voteMutex.Lock()
|
|
|
|
|
for _, v := range toAnnounceResultList {
|
|
|
|
|
if v.VoteID == id {
|
|
|
|
|
//It's already queued to be announced in the next announcement cycle.
|
|
|
|
|
voteMutex.Unlock()
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -104,6 +105,17 @@ func checkForVoteResult(s *discordgo.Session, id int) {
|
|
|
|
|
VoteID: id,
|
|
|
|
|
IsPositive: true,
|
|
|
|
|
})
|
|
|
|
|
voteMutex.Unlock()
|
|
|
|
|
} else {
|
|
|
|
|
//Nothing happened. Make sure it's not in the queue.
|
|
|
|
|
for k, v := range toAnnounceResultList {
|
|
|
|
|
if v.VoteID == id {
|
|
|
|
|
//It's already queued to be announced in the next announcement cycle.
|
|
|
|
|
toAnnounceResultList[k] = confirmedResult{
|
|
|
|
|
VoteID: invalidVote,
|
|
|
|
|
IsPositive: false,
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|