mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 09:48:26 -04:00
More cleanup, namespace fixes, convenience methods for IKernel
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
#nullable disable
|
||||
using Nadeko.Common;
|
||||
using NadekoBot.Modules.Gambling.Common.AnimalRacing.Exceptions;
|
||||
using NadekoBot.Modules.Games.Common;
|
||||
|
||||
|
@@ -1,5 +1,4 @@
|
||||
#nullable disable
|
||||
using Nadeko.Common;
|
||||
using NadekoBot.Common.TypeReaders;
|
||||
using NadekoBot.Modules.Gambling.Common;
|
||||
using NadekoBot.Modules.Gambling.Common.AnimalRacing;
|
||||
|
@@ -1,6 +1,5 @@
|
||||
using LinqToDB;
|
||||
using LinqToDB.EntityFrameworkCore;
|
||||
using NadekoBot.Db.Models;
|
||||
|
||||
namespace NadekoBot.Modules.Gambling.Bank;
|
||||
|
||||
|
@@ -1,5 +1,4 @@
|
||||
#nullable disable
|
||||
using Nadeko.Common;
|
||||
using NadekoBot.Common.TypeReaders;
|
||||
using NadekoBot.Modules.Gambling.Common;
|
||||
using NadekoBot.Modules.Gambling.Common.Blackjack;
|
||||
|
@@ -1,7 +1,6 @@
|
||||
#nullable disable
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using System.Collections.Concurrent;
|
||||
using Nadeko.Common;
|
||||
|
||||
namespace NadekoBot.Modules.Gambling.Common.Events;
|
||||
|
||||
|
@@ -1,5 +1,4 @@
|
||||
#nullable disable
|
||||
using Nadeko.Common;
|
||||
using NadekoBot.Common.TypeReaders;
|
||||
using NadekoBot.Modules.Gambling.Common;
|
||||
using NadekoBot.Modules.Gambling.Services;
|
||||
|
@@ -1,8 +1,6 @@
|
||||
#nullable disable
|
||||
using Nadeko.Common;
|
||||
using NadekoBot.Common.Configs;
|
||||
using NadekoBot.Modules.Gambling.Common;
|
||||
using NadekoBot.Services;
|
||||
|
||||
namespace NadekoBot.Modules.Gambling.Services;
|
||||
|
||||
|
@@ -14,8 +14,6 @@ public class GamblingService : INService, IReadyExecutor
|
||||
public ConcurrentDictionary<(ulong, ulong), RollDuelGame> Duels { get; } = new();
|
||||
public ConcurrentDictionary<ulong, Connect4Game> Connect4Games { get; } = new();
|
||||
private readonly DbService _db;
|
||||
private readonly ICurrencyService _cs;
|
||||
private readonly IBot _bot;
|
||||
private readonly DiscordSocketClient _client;
|
||||
private readonly IBotCache _cache;
|
||||
private readonly GamblingConfigService _gss;
|
||||
@@ -24,13 +22,11 @@ public class GamblingService : INService, IReadyExecutor
|
||||
|
||||
public GamblingService(
|
||||
DbService db,
|
||||
ICurrencyService cs,
|
||||
DiscordSocketClient client,
|
||||
IBotCache cache,
|
||||
GamblingConfigService gss)
|
||||
{
|
||||
_db = db;
|
||||
_cs = cs;
|
||||
_client = client;
|
||||
_cache = cache;
|
||||
_gss = gss;
|
||||
@@ -57,7 +53,7 @@ public class GamblingService : INService, IReadyExecutor
|
||||
var days = TimeSpan.FromDays(lifetime);
|
||||
await using var uow = _db.GetDbContext();
|
||||
await uow.CurrencyTransactions
|
||||
.DeleteAsync(ct => ct.DateAdded == null || now - ct.DateAdded < days);
|
||||
.DeleteAsync(ct => ct.DateAdded == null || now - ct.DateAdded < days);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -67,7 +63,7 @@ public class GamblingService : INService, IReadyExecutor
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private async Task CurrencyDecayLoopAsync()
|
||||
{
|
||||
if (_client.ShardId != 0)
|
||||
@@ -84,7 +80,7 @@ public class GamblingService : INService, IReadyExecutor
|
||||
continue;
|
||||
|
||||
var now = DateTime.UtcNow;
|
||||
|
||||
|
||||
await using var uow = _db.GetDbContext();
|
||||
var result = await _cache.GetAsync(_curDecayKey);
|
||||
|
||||
@@ -109,14 +105,14 @@ public class GamblingService : INService, IReadyExecutor
|
||||
|
||||
var decay = (double)config.Decay.Percent;
|
||||
await uow.DiscordUser
|
||||
.Where(x => x.CurrencyAmount > config.Decay.MinThreshold && x.UserId != _client.CurrentUser.Id)
|
||||
.UpdateAsync(old => new()
|
||||
{
|
||||
CurrencyAmount =
|
||||
maxDecay > Sql.Round((old.CurrencyAmount * decay) - 0.5)
|
||||
? (long)(old.CurrencyAmount - Sql.Round((old.CurrencyAmount * decay) - 0.5))
|
||||
: old.CurrencyAmount - maxDecay
|
||||
});
|
||||
.Where(x => x.CurrencyAmount > config.Decay.MinThreshold && x.UserId != _client.CurrentUser.Id)
|
||||
.UpdateAsync(old => new()
|
||||
{
|
||||
CurrencyAmount =
|
||||
maxDecay > Sql.Round((old.CurrencyAmount * decay) - 0.5)
|
||||
? (long)(old.CurrencyAmount - Sql.Round((old.CurrencyAmount * decay) - 0.5))
|
||||
: old.CurrencyAmount - maxDecay
|
||||
});
|
||||
|
||||
await uow.SaveChangesAsync();
|
||||
|
||||
@@ -145,7 +141,7 @@ public class GamblingService : INService, IReadyExecutor
|
||||
var waifus = uow.WaifuInfo.GetTotalValue();
|
||||
var bot = await uow.DiscordUser.GetUserCurrencyAsync(_client.CurrentUser.Id);
|
||||
decimal bank = await uow.GetTable<BankUser>()
|
||||
.SumAsyncLinqToDB(x => x.Balance);
|
||||
.SumAsyncLinqToDB(x => x.Balance);
|
||||
|
||||
var result = new EconomyResult
|
||||
{
|
||||
@@ -165,10 +161,11 @@ public class GamblingService : INService, IReadyExecutor
|
||||
}
|
||||
|
||||
|
||||
private static readonly SemaphoreSlim _timelyLock = new (1, 1);
|
||||
private static readonly SemaphoreSlim _timelyLock = new(1, 1);
|
||||
|
||||
private static TypedKey<Dictionary<ulong, long>> _timelyKey
|
||||
= new("timely:claims");
|
||||
|
||||
public async Task<TimeSpan?> ClaimTimelyAsync(ulong userId, int period)
|
||||
{
|
||||
if (period == 0)
|
||||
@@ -196,7 +193,7 @@ public class GamblingService : INService, IReadyExecutor
|
||||
// update the cache
|
||||
dict[userId] = nowB;
|
||||
await _cache.AddAsync(_timelyKey, dict);
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
else
|
||||
|
@@ -1,10 +1,7 @@
|
||||
#nullable disable
|
||||
using NadekoBot.Modules.Gambling.Services;
|
||||
using System.Globalization;
|
||||
using System.Numerics;
|
||||
using Discord;
|
||||
using Nadeko.Bot.Common;
|
||||
using NadekoBot.Common;
|
||||
|
||||
namespace NadekoBot.Modules.Gambling.Common;
|
||||
|
||||
|
@@ -1,5 +1,4 @@
|
||||
#nullable disable
|
||||
using Nadeko.Common;
|
||||
using NadekoBot.Common.TypeReaders;
|
||||
using NadekoBot.Modules.Gambling.Common;
|
||||
using NadekoBot.Modules.Gambling.Services;
|
||||
|
@@ -1,5 +1,4 @@
|
||||
#nullable disable
|
||||
using Nadeko.Common;
|
||||
using NadekoBot.Common.TypeReaders;
|
||||
using NadekoBot.Modules.Gambling.Common;
|
||||
using NadekoBot.Modules.Gambling.Services;
|
||||
|
@@ -1,6 +1,5 @@
|
||||
#nullable disable
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Nadeko.Common;
|
||||
using NadekoBot.Db;
|
||||
using NadekoBot.Modules.Gambling.Common;
|
||||
using NadekoBot.Modules.Gambling.Services;
|
||||
|
@@ -1,6 +1,5 @@
|
||||
#nullable disable
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Nadeko.Common;
|
||||
using NadekoBot.Db;
|
||||
using NadekoBot.Services.Database;
|
||||
using NadekoBot.Services.Database.Models;
|
||||
|
@@ -7,7 +7,6 @@ using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.Drawing.Processing;
|
||||
using SixLabors.ImageSharp.PixelFormats;
|
||||
using SixLabors.ImageSharp.Processing;
|
||||
using System.Text;
|
||||
using Nadeko.Econ.Gambling;
|
||||
using NadekoBot.Common.TypeReaders;
|
||||
using Color = SixLabors.ImageSharp.Color;
|
||||
|
@@ -2,9 +2,6 @@
|
||||
using NadekoBot.Common.ModuleBehaviors;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Discord.WebSocket;
|
||||
using NadekoBot.Services;
|
||||
using Serilog;
|
||||
|
||||
namespace NadekoBot.Modules.Gambling.Services;
|
||||
|
||||
|
@@ -1,5 +1,4 @@
|
||||
#nullable disable
|
||||
using Nadeko.Common;
|
||||
using NadekoBot.Modules.Gambling.Common;
|
||||
using NadekoBot.Modules.Gambling.Common.Waifu;
|
||||
using NadekoBot.Modules.Gambling.Services;
|
||||
|
@@ -1,11 +1,9 @@
|
||||
#nullable disable
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Nadeko.Common;
|
||||
using NadekoBot.Common.ModuleBehaviors;
|
||||
using NadekoBot.Modules.Games.Common;
|
||||
using NadekoBot.Modules.Games.Common.Acrophobia;
|
||||
using NadekoBot.Modules.Games.Common.Nunchi;
|
||||
using NadekoBot.Modules.Games.Common.Trivia;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace NadekoBot.Modules.Games.Services;
|
||||
|
@@ -1,5 +1,4 @@
|
||||
#nullable disable
|
||||
using Nadeko.Common;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.Processing;
|
||||
using Image = SixLabors.ImageSharp.Image;
|
||||
|
@@ -1,4 +1,3 @@
|
||||
using Nadeko.Common;
|
||||
using NadekoBot.Modules.Games.Hangman;
|
||||
|
||||
namespace NadekoBot.Modules.Games;
|
||||
|
Reference in New Issue
Block a user