mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-10 17:28:27 -04:00
dev: Using built in rng.Shuffle, using some new .net types, removed some transactions
This commit is contained in:
@@ -291,8 +291,7 @@ public class MuteService : INService
|
||||
|
||||
public async Task<IRole> GetMuteRole(IGuild guild)
|
||||
{
|
||||
if (guild is null)
|
||||
throw new ArgumentNullException(nameof(guild));
|
||||
ArgumentNullException.ThrowIfNull(guild);
|
||||
|
||||
const string defaultMuteRoleName = "nadeko-mute";
|
||||
|
||||
|
@@ -130,8 +130,7 @@ public class VcRoleService : INService
|
||||
|
||||
public void AddVcRole(ulong guildId, IRole role, ulong vcId)
|
||||
{
|
||||
if (role is null)
|
||||
throw new ArgumentNullException(nameof(role));
|
||||
ArgumentNullException.ThrowIfNull(role);
|
||||
|
||||
var guildVcRoles = VcRoles.GetOrAdd(guildId, new ConcurrentDictionary<ulong, IRole>());
|
||||
|
||||
|
@@ -24,6 +24,7 @@ public abstract class GamblingModule<TService> : NadekoModule<TService>
|
||||
{
|
||||
if (amount < 1)
|
||||
return false;
|
||||
|
||||
if (amount < Config.MinBet)
|
||||
{
|
||||
await Response().Error(strs.min_bet_limit(Format.Bold(Config.MinBet.ToString()) + CurrencySign)).SendAsync();
|
||||
|
@@ -267,20 +267,8 @@ public sealed partial class MusicQueue : IMusicQueue
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
var list = tracks.ToList();
|
||||
|
||||
for (var i = 0; i < list.Count; i++)
|
||||
{
|
||||
var struck = rng.Next(i, list.Count);
|
||||
(list[struck], list[i]) = (list[i], list[struck]);
|
||||
|
||||
// could preserving the index during shuffling be done better?
|
||||
if (i == index)
|
||||
index = struck;
|
||||
else if (struck == index)
|
||||
index = i;
|
||||
}
|
||||
|
||||
var list = tracks.ToArray();
|
||||
rng.Shuffle(list);
|
||||
tracks = new(list);
|
||||
}
|
||||
}
|
||||
|
@@ -111,7 +111,6 @@ public sealed class PatronageService
|
||||
var lastDate = lastRun.ToDateOnly();
|
||||
|
||||
await using var ctx = _db.GetDbContext();
|
||||
await using var tran = await ctx.Database.BeginTransactionAsync();
|
||||
|
||||
if ((lastDate.Day == 1 || (lastDate.Month != nowDate.Month)) && nowDate.Day > 1)
|
||||
{
|
||||
@@ -141,7 +140,6 @@ public sealed class PatronageService
|
||||
|
||||
// assumes that the code above runs in less than an hour
|
||||
await _cache.AddAsync(_quotaKey, now.ToBinary());
|
||||
await tran.CommitAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -171,7 +169,6 @@ public sealed class PatronageService
|
||||
|
||||
var lastChargeUtc = subscriber.LastCharge.Value.ToUniversalTime();
|
||||
var dateInOneMonth = lastChargeUtc.Date.AddMonths(1);
|
||||
// await using var tran = await ctx.Database.BeginTransactionAsync();
|
||||
try
|
||||
{
|
||||
var dbPatron = await ctx.GetTable<PatronUser>()
|
||||
|
@@ -1469,7 +1469,6 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand
|
||||
}
|
||||
|
||||
await using var ctx = _db.GetDbContext();
|
||||
// await using var tran = await ctx.Database.BeginTransactionAsync();
|
||||
try
|
||||
{
|
||||
if (await ctx.GetTable<XpShopOwnedItem>()
|
||||
|
Reference in New Issue
Block a user