mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-10 17:28:27 -04:00
Removed plantedcurrency repository
This commit is contained in:
@@ -6,6 +6,7 @@ using NadekoBot.Modules.Gambling.Common.WheelOfFortune;
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
@@ -136,7 +137,7 @@ WHERE CurrencyAmount > {config.Decay.MinThreshold} AND UserId!={_client.CurrentU
|
|||||||
{
|
{
|
||||||
cash = uow.DiscordUsers.GetTotalCurrency();
|
cash = uow.DiscordUsers.GetTotalCurrency();
|
||||||
onePercent = uow.DiscordUsers.GetTopOnePercentCurrency(_client.CurrentUser.Id);
|
onePercent = uow.DiscordUsers.GetTopOnePercentCurrency(_client.CurrentUser.Id);
|
||||||
planted = uow.PlantedCurrency.GetTotalPlanted();
|
planted = uow._context.PlantedCurrency.AsQueryable().Sum(x => x.Amount);
|
||||||
waifus = uow.Waifus.GetTotalValue();
|
waifus = uow.Waifus.GetTotalValue();
|
||||||
bot = uow.DiscordUsers.GetUserCurrency(_client.CurrentUser.Id);
|
bot = uow.DiscordUsers.GetUserCurrency(_client.CurrentUser.Id);
|
||||||
}
|
}
|
||||||
|
@@ -269,7 +269,17 @@ namespace NadekoBot.Modules.Gambling.Services
|
|||||||
// this method will sum all plants with that password,
|
// this method will sum all plants with that password,
|
||||||
// remove them, and get messageids of the removed plants
|
// remove them, and get messageids of the removed plants
|
||||||
|
|
||||||
(amount, ids) = uow.PlantedCurrency.RemoveSumAndGetMessageIdsFor(ch.Id, pass);
|
pass = pass?.Trim().TrimTo(10, hideDots: true).ToUpperInvariant();
|
||||||
|
// gets all plants in this channel with the same password
|
||||||
|
var entries = uow._context.PlantedCurrency
|
||||||
|
.AsQueryable()
|
||||||
|
.Where(x => x.ChannelId == ch.Id && pass == x.Password)
|
||||||
|
.ToList();
|
||||||
|
// sum how much currency that is, and get all of the message ids (so that i can delete them)
|
||||||
|
amount = entries.Sum(x => x.Amount);
|
||||||
|
ids = entries.Select(x => x.MessageId).ToArray();
|
||||||
|
// remove them from the database
|
||||||
|
uow._context.RemoveRange(entries);
|
||||||
|
|
||||||
|
|
||||||
if (amount > 0)
|
if (amount > 0)
|
||||||
@@ -360,7 +370,7 @@ namespace NadekoBot.Modules.Gambling.Services
|
|||||||
{
|
{
|
||||||
using (var uow = _db.GetDbContext())
|
using (var uow = _db.GetDbContext())
|
||||||
{
|
{
|
||||||
uow.PlantedCurrency.Add(new PlantedCurrency
|
uow._context.PlantedCurrency.Add(new PlantedCurrency
|
||||||
{
|
{
|
||||||
Amount = amount,
|
Amount = amount,
|
||||||
GuildId = gid,
|
GuildId = gid,
|
||||||
|
@@ -16,7 +16,6 @@ namespace NadekoBot.Core.Services.Database
|
|||||||
IDiscordUserRepository DiscordUsers { get; }
|
IDiscordUserRepository DiscordUsers { get; }
|
||||||
IWarningsRepository Warnings { get; }
|
IWarningsRepository Warnings { get; }
|
||||||
IXpRepository Xp { get; }
|
IXpRepository Xp { get; }
|
||||||
IPlantedCurrencyRepository PlantedCurrency { get; }
|
|
||||||
|
|
||||||
int SaveChanges();
|
int SaveChanges();
|
||||||
Task<int> SaveChangesAsync();
|
Task<int> SaveChangesAsync();
|
||||||
|
@@ -1,10 +0,0 @@
|
|||||||
using NadekoBot.Core.Services.Database.Models;
|
|
||||||
|
|
||||||
namespace NadekoBot.Core.Services.Database.Repositories
|
|
||||||
{
|
|
||||||
public interface IPlantedCurrencyRepository : IRepository<PlantedCurrency>
|
|
||||||
{
|
|
||||||
(long Sum, ulong[] MessageIds) RemoveSumAndGetMessageIdsFor(ulong cid, string pass);
|
|
||||||
decimal GetTotalPlanted();
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,32 +0,0 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using NadekoBot.Core.Services.Database.Models;
|
|
||||||
using NadekoBot.Extensions;
|
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace NadekoBot.Core.Services.Database.Repositories.Impl
|
|
||||||
{
|
|
||||||
public class PlantedCurrencyRepository : Repository<PlantedCurrency>, IPlantedCurrencyRepository
|
|
||||||
{
|
|
||||||
public PlantedCurrencyRepository(DbContext context) : base(context)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public decimal GetTotalPlanted()
|
|
||||||
{
|
|
||||||
return _set.Sum(x => x.Amount);
|
|
||||||
}
|
|
||||||
|
|
||||||
public (long Sum, ulong[] MessageIds) RemoveSumAndGetMessageIdsFor(ulong cid, string pass = null)
|
|
||||||
{
|
|
||||||
pass = pass?.Trim().TrimTo(10, hideDots: true).ToUpperInvariant();
|
|
||||||
// gets all plants in this channel with the same password
|
|
||||||
var entries = _set.AsQueryable().Where(x => x.ChannelId == cid && pass == x.Password).ToArray();
|
|
||||||
// sum how much currency that is, and get all of the message ids (so that i can delete them)
|
|
||||||
var toReturn = (entries.Sum(x => x.Amount), entries.Select(x => x.MessageId).ToArray());
|
|
||||||
// remove them from the database
|
|
||||||
_set.RemoveRange(entries);
|
|
||||||
|
|
||||||
return toReturn;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -33,9 +33,6 @@ namespace NadekoBot.Core.Services.Database
|
|||||||
private IXpRepository _xp;
|
private IXpRepository _xp;
|
||||||
public IXpRepository Xp => _xp ?? (_xp = new XpRepository(_context));
|
public IXpRepository Xp => _xp ?? (_xp = new XpRepository(_context));
|
||||||
|
|
||||||
private IPlantedCurrencyRepository _planted;
|
|
||||||
public IPlantedCurrencyRepository PlantedCurrency => _planted ?? (_planted = new PlantedCurrencyRepository(_context));
|
|
||||||
|
|
||||||
public UnitOfWork(NadekoContext context)
|
public UnitOfWork(NadekoContext context)
|
||||||
{
|
{
|
||||||
_context = context;
|
_context = context;
|
||||||
|
Reference in New Issue
Block a user