Add pick db interaction

This commit is contained in:
Daniel_I_Am 2020-06-04 02:13:57 +02:00
parent 09e5b671c8
commit 57058060c2
No known key found for this signature in database
GPG Key ID: 80C428FCC9743E84

View File

@ -154,27 +154,8 @@ namespace ChaosBot.Discord.Modules
private void PickRaffle(StringBuilder sb) private void PickRaffle(StringBuilder sb)
{ {
int totalRaffle = _currentPot.Values.Sum(); Raffle winner = RaffleRepository.PickRandom();
sb.Append($"<@{winner.userId}> has won the raffle!");
if (totalRaffle == 0)
{
sb.Append("No one has any rafflepoints.");
return;
}
int winner = new Random().Next(totalRaffle);
foreach (ulong userId in _currentPot.Keys)
{
int userValue = _currentPot.GetValueOrDefault(userId);
if (winner <= userValue)
{
sb.Append($"<@{userId}> has won the raffle!");
ClearRaffle(sb, true);
return;
}
winner -= userValue;
}
} }
private void ClearRaffle(StringBuilder sb, bool noOutput = false) private void ClearRaffle(StringBuilder sb, bool noOutput = false)