Adding Raffle Add and massInsert

This commit is contained in:
Sean "Solao Bajiuik" Stoves 2020-06-03 19:47:17 -04:00
parent 146eba94f6
commit 705e996ec6
2 changed files with 22 additions and 17 deletions

View File

@ -22,14 +22,15 @@ namespace ChaosBot.Database.Repository
Controller.InsertQuery(Table, dict);
}
public static void massInsert(Raffle raffle, int amount)
public static void massInsert(List<Raffle> raffles)
{
Dictionary<string, object> dict = new Dictionary<string, object>();
dict.Add("userId", raffle.userId);
for (int i = 0; i < amount; i++)
foreach (var raf in raffles)
{
Dictionary<string, object> dict = new Dictionary<string, object>();
dict.Add("userId", raf.userId);
Controller.InsertQuery(Table, dict);
}
}
// public static void delete()

View File

@ -3,14 +3,12 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ChaosBot.Database;
using ChaosBot.Database.Entity;
using ChaosBot.Database.Repository;
using Discord;
using Discord.Commands;
using Discord.WebSocket;
using Microsoft.Extensions.Configuration;
using NLog;
using ChaosBot.Database.Repository;
namespace ChaosBot.Discord.Modules
{
@ -129,23 +127,29 @@ namespace ChaosBot.Discord.Modules
}
}
private void AddRaffle(StringBuilder sb, string user, int amount)
private void AddRaffle(StringBuilder sb, string user, int amount = 1)
{
ulong userId = Convert.ToUInt64(user.Substring(3, user.Length-4));
int currentAmount;
if (_currentPot.TryGetValue(userId, out currentAmount))
if (amount > 1)
{
_currentPot.Remove(userId);
_currentPot.Add(userId, currentAmount + amount);
List<Raffle> raffles = new List<Raffle>();
for (int i = 0; i < amount; i++)
raffles.Add(new Raffle(userId.ToString()));
RaffleRepository.massInsert(raffles);
}
else
{
_currentPot.Add(userId, amount);
RaffleRepository.insert(new Raffle(userId.ToString()));
}
sb.AppendLine($"{Context.User.Mention} has added {amount} rafflepoints to <@{userId}>.");
sb.AppendLine();
sb.AppendLine($"<@{userId}> now has {_currentPot.GetValueOrDefault(userId)} rafflepoints!");
sb.AppendLine($"<@{userId}> now has WIP rafflepoints!");
}
private void PickRaffle(StringBuilder sb)