Merge branch 'master' of ssh://git.chaoticlogic.us:2302/discord-bots/chaosbot

This commit is contained in:
Daniel_I_Am 2020-06-04 01:55:32 +02:00
commit f4cdf5c9c6
No known key found for this signature in database
GPG Key ID: 80C428FCC9743E84
2 changed files with 22 additions and 17 deletions

View File

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

View File

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