From 57058060c280a0bad621c6907c849d67e75ba393 Mon Sep 17 00:00:00 2001 From: Daniel-I-Am Date: Thu, 4 Jun 2020 02:13:57 +0200 Subject: [PATCH] Add pick db interaction --- ChaosBot/Discord/Modules/RaffleSystem.cs | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/ChaosBot/Discord/Modules/RaffleSystem.cs b/ChaosBot/Discord/Modules/RaffleSystem.cs index b48db2e..bfeb5cf 100644 --- a/ChaosBot/Discord/Modules/RaffleSystem.cs +++ b/ChaosBot/Discord/Modules/RaffleSystem.cs @@ -154,27 +154,8 @@ namespace ChaosBot.Discord.Modules private void PickRaffle(StringBuilder sb) { - int totalRaffle = _currentPot.Values.Sum(); - - 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; - } + Raffle winner = RaffleRepository.PickRandom(); + sb.Append($"<@{winner.userId}> has won the raffle!"); } private void ClearRaffle(StringBuilder sb, bool noOutput = false)