await usings and minor cleanup

This commit is contained in:
Kwoth
2021-12-20 03:02:02 +01:00
parent 1b2017024c
commit da2ee0c158
55 changed files with 176 additions and 174 deletions

View File

@@ -40,7 +40,7 @@ public partial class Gambling
using (var img1 = GetDice(num1))
using (var img2 = GetDice(num2))
using (var img = new[] { img1, img2 }.Merge(out var format))
using (var ms = img.ToStream(format))
await using (var ms = img.ToStream(format))
{
await ctx.Channel.SendFileAsync(ms,
$"dice.{format.FileExtensions.First()}",
@@ -116,7 +116,7 @@ public partial class Gambling
}
using (var bitmap = dice.Merge(out var format))
using (var ms = bitmap.ToStream(format))
await using (var ms = bitmap.ToStream(format))
{
foreach (var d in dice)
{

View File

@@ -80,7 +80,7 @@ public partial class Gambling
num = 10;
var (ImageStream, ToSend) = await InternalDraw(num, ctx.Guild.Id).ConfigureAwait(false);
using (ImageStream)
await using (ImageStream)
{
await ctx.Channel.SendFileAsync(ImageStream, num + " cards.jpg", ToSend).ConfigureAwait(false);
}
@@ -95,7 +95,7 @@ public partial class Gambling
num = 10;
var (ImageStream, ToSend) = await InternalDraw(num).ConfigureAwait(false);
using (ImageStream)
await using (ImageStream)
{
await ctx.Channel.SendFileAsync(ImageStream, num + " cards.jpg", ToSend).ConfigureAwait(false);
}

View File

@@ -55,7 +55,7 @@ public partial class Gambling
}
}
using (var img = imgs.Merge(out var format))
using (var stream = img.ToStream(format))
await using (var stream = img.ToStream(format))
{
foreach (var i in imgs)
{

View File

@@ -187,7 +187,7 @@ public partial class Gambling : GamblingModule<GamblingService>
return;
var trs = new List<CurrencyTransaction>();
using (var uow = _db.GetDbContext())
await using (var uow = _db.GetDbContext())
{
trs = uow.CurrencyTransactions.GetPageFor(userId, page);
}
@@ -528,7 +528,7 @@ public partial class Gambling : GamblingModule<GamblingService>
{
var now = DateTime.UtcNow;
using (var uow = _db.GetDbContext())
await using (var uow = _db.GetDbContext())
{
cleanRichest = uow.DiscordUser.GetTopRichest(_client.CurrentUser.Id, 10_000);
}
@@ -542,7 +542,7 @@ public partial class Gambling : GamblingModule<GamblingService>
}
else
{
using (var uow = _db.GetDbContext())
await using (var uow = _db.GetDbContext())
{
cleanRichest = uow.DiscordUser.GetTopRichest(_client.CurrentUser.Id, 9, page).ToList();
}

View File

@@ -33,7 +33,7 @@ public class ShopService : IShopService, INService
if (newPrice <= 0)
throw new ArgumentOutOfRangeException(nameof(newPrice));
using var uow = _db.GetDbContext();
await using var uow = _db.GetDbContext();
var entries = GetEntriesInternal(uow, guildId);
if (index >= entries.Count)
@@ -51,7 +51,7 @@ public class ShopService : IShopService, INService
if (string.IsNullOrWhiteSpace(newName))
throw new ArgumentNullException(nameof(newName));
using var uow = _db.GetDbContext();
await using var uow = _db.GetDbContext();
var entries = GetEntriesInternal(uow, guildId);
if (index >= entries.Count)
@@ -69,7 +69,7 @@ public class ShopService : IShopService, INService
if (index2 < 0)
throw new ArgumentOutOfRangeException(nameof(index2));
using var uow = _db.GetDbContext();
await using var uow = _db.GetDbContext();
var entries = GetEntriesInternal(uow, guildId);
if (index1 >= entries.Count || index2 >= entries.Count || index1 == index2)
@@ -89,7 +89,7 @@ public class ShopService : IShopService, INService
if (toIndex < 0)
throw new ArgumentOutOfRangeException(nameof(toIndex));
using var uow = _db.GetDbContext();
await using var uow = _db.GetDbContext();
var entries = GetEntriesInternal(uow, guildId);
if (fromIndex >= entries.Count || toIndex >= entries.Count || fromIndex == toIndex)

View File

@@ -219,7 +219,7 @@ public class PlantPickService : INService
var pw = config.Generation.HasPassword ? GenerateCurrencyPassword().ToUpperInvariant() : null;
IUserMessage sent;
using (var stream = GetRandomCurrencyImage(pw, out var ext))
await using (var stream = GetRandomCurrencyImage(pw, out var ext))
{
sent = await channel.SendFileAsync(stream, $"currency_image.{ext}", toSend).ConfigureAwait(false);
}
@@ -259,7 +259,7 @@ public class PlantPickService : INService
{
long amount;
ulong[] ids;
using (var uow = _db.GetDbContext())
await using (var uow = _db.GetDbContext())
{
// this method will sum all plants with that password,
// remove them, and get messageids of the removed plants
@@ -318,7 +318,7 @@ public class PlantPickService : INService
msgToSend += " " + GetText(gid, strs.pick_sn(prefix));
//get the image
using (var stream = GetRandomCurrencyImage(pass, out var ext))
await using (var stream = GetRandomCurrencyImage(pass, out var ext))
{
// send it
var msg = await ch.SendFileAsync(stream, $"img.{ext}", msgToSend).ConfigureAwait(false);
@@ -362,7 +362,7 @@ public class PlantPickService : INService
private async Task AddPlantToDatabase(ulong gid, ulong cid, ulong uid, ulong mid, long amount, string pass)
{
using (var uow = _db.GetDbContext())
await using (var uow = _db.GetDbContext())
{
uow.PlantedCurrency.Add(new()
{

View File

@@ -39,8 +39,8 @@ public class WaifuService : INService
return false;
var settings = _gss.Data;
using (var uow = _db.GetDbContext())
await using (var uow = _db.GetDbContext())
{
var waifu = uow.WaifuInfo.ByWaifuUserId(waifuId);
var ownerUser = uow.GetOrCreateUser(owner);
@@ -116,7 +116,7 @@ public class WaifuService : INService
public async Task<bool> TryReset(IUser user)
{
using (var uow = _db.GetDbContext())
await using (var uow = _db.GetDbContext())
{
var price = GetResetPrice(user);
if (!await _cs.RemoveAsync(user.Id, "Waifu Reset", price, gamble: true))
@@ -161,7 +161,7 @@ public class WaifuService : INService
WaifuClaimResult result;
WaifuInfo w;
bool isAffinity;
using (var uow = _db.GetDbContext())
await using (var uow = _db.GetDbContext())
{
w = uow.WaifuInfo.ByWaifuUserId(target.Id);
isAffinity = (w?.Affinity?.UserId == user.Id);
@@ -251,7 +251,7 @@ public class WaifuService : INService
DiscordUser oldAff = null;
var success = false;
TimeSpan? remaining = null;
using (var uow = _db.GetDbContext())
await using (var uow = _db.GetDbContext())
{
var w = uow.WaifuInfo.ByWaifuUserId(user.Id);
var newAff = target is null ? null : uow.GetOrCreateUser(target);
@@ -323,7 +323,7 @@ public class WaifuService : INService
TimeSpan? remaining = null;
long amount = 0;
WaifuInfo w = null;
using (var uow = _db.GetDbContext())
await using (var uow = _db.GetDbContext())
{
w = uow.WaifuInfo.ByWaifuUserId(targetId);
var now = DateTime.UtcNow;
@@ -375,7 +375,7 @@ public class WaifuService : INService
return false;
}
using (var uow = _db.GetDbContext())
await using (var uow = _db.GetDbContext())
{
var w = uow.WaifuInfo.ByWaifuUserId(giftedWaifu.Id,
set => set.Include(x => x.Items)

View File

@@ -89,7 +89,7 @@ public partial class Gambling
if (index < 0)
return;
ShopEntry entry;
using (var uow = _db.GetDbContext())
await using (var uow = _db.GetDbContext())
{
var config = uow.GuildConfigsForId(ctx.Guild.Id, set => set
.Include(x => x.ShopEntries)
@@ -159,7 +159,7 @@ public partial class Gambling
if (await _cs.RemoveAsync(ctx.User.Id, $"Shop purchase - {entry.Type}", entry.Price).ConfigureAwait(false))
{
using (var uow = _db.GetDbContext())
await using (var uow = _db.GetDbContext())
{
var x = uow.Set<ShopEntryItem>().Remove(item);
uow.SaveChanges();
@@ -183,7 +183,7 @@ public partial class Gambling
await _cs.AddAsync(ctx.User.Id,
$"Shop error refund - {entry.Name}",
entry.Price).ConfigureAwait(false);
using (var uow = _db.GetDbContext())
await using (var uow = _db.GetDbContext())
{
var entries = new IndexedCollection<ShopEntry>(uow.GuildConfigsForId(ctx.Guild.Id,
set => set.Include(x => x.ShopEntries)
@@ -232,7 +232,7 @@ public partial class Gambling
RoleId = role.Id,
RoleName = role.Name
};
using (var uow = _db.GetDbContext())
await using (var uow = _db.GetDbContext())
{
var entries = new IndexedCollection<ShopEntry>(uow.GuildConfigsForId(ctx.Guild.Id,
set => set.Include(x => x.ShopEntries)
@@ -263,7 +263,7 @@ public partial class Gambling
AuthorId = ctx.User.Id,
Items = new(),
};
using (var uow = _db.GetDbContext())
await using (var uow = _db.GetDbContext())
{
var entries = new IndexedCollection<ShopEntry>(uow.GuildConfigsForId(ctx.Guild.Id,
set => set.Include(x => x.ShopEntries)
@@ -294,7 +294,7 @@ public partial class Gambling
ShopEntry entry;
var rightType = false;
var added = false;
using (var uow = _db.GetDbContext())
await using (var uow = _db.GetDbContext())
{
var entries = new IndexedCollection<ShopEntry>(uow.GuildConfigsForId(ctx.Guild.Id,
set => set.Include(x => x.ShopEntries)
@@ -327,7 +327,7 @@ public partial class Gambling
if (index < 0)
return;
ShopEntry removed;
using (var uow = _db.GetDbContext())
await using (var uow = _db.GetDbContext())
{
var config = uow.GuildConfigsForId(ctx.Guild.Id, set => set
.Include(x => x.ShopEntries)

View File

@@ -172,7 +172,7 @@ public partial class Gambling
Interlocked.Add(ref _totalPaidOut, result.Won);
long ownedAmount;
using (var uow = _db.GetDbContext())
await using (var uow = _db.GetDbContext())
{
ownedAmount = uow.Set<DiscordUser>()
.FirstOrDefault(x => x.UserId == ctx.User.Id)
@@ -243,7 +243,7 @@ public partial class Gambling
msg = GetText(strs.slot_jackpot(30));
}
using (var imgStream = bgImage.ToStream())
await using (var imgStream = bgImage.ToStream())
{
await ctx.Channel.SendFileAsync(imgStream,
filename: "result.png",