mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 01:38:27 -04:00
A few more improvements and cleanup for the wallet
This commit is contained in:
@@ -73,6 +73,7 @@ public static class GuildConfigExtensions
|
|||||||
{
|
{
|
||||||
GuildConfig config;
|
GuildConfig config;
|
||||||
|
|
||||||
|
// todo linq2db
|
||||||
if (includes is null)
|
if (includes is null)
|
||||||
config = ctx.GuildConfigs.IncludeEverything().FirstOrDefault(c => c.GuildId == guildId);
|
config = ctx.GuildConfigs.IncludeEverything().FirstOrDefault(c => c.GuildId == guildId);
|
||||||
else
|
else
|
||||||
@@ -100,6 +101,26 @@ public static class GuildConfigExtensions
|
|||||||
}
|
}
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
|
|
||||||
|
// ctx.GuildConfigs
|
||||||
|
// .ToLinqToDBTable()
|
||||||
|
// .InsertOrUpdate(() => new()
|
||||||
|
// {
|
||||||
|
// GuildId = guildId,
|
||||||
|
// Permissions = Permissionv2.GetDefaultPermlist,
|
||||||
|
// WarningsInitialized = true,
|
||||||
|
// WarnPunishments = DefaultWarnPunishments
|
||||||
|
// },
|
||||||
|
// _ => new(),
|
||||||
|
// () => new()
|
||||||
|
// {
|
||||||
|
// GuildId = guildId
|
||||||
|
// });
|
||||||
|
//
|
||||||
|
// if(includes is null)
|
||||||
|
// return ctx.GuildConfigs
|
||||||
|
// .ToLinqToDBTable()
|
||||||
|
// .First(x => x.GuildId == guildId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static LogSetting LogSettingsFor(this NadekoContext ctx, ulong guildId)
|
public static LogSetting LogSettingsFor(this NadekoContext ctx, ulong guildId)
|
||||||
|
@@ -10,6 +10,7 @@ public static class CurrencyServiceExtensions
|
|||||||
return await wallet.GetBalance();
|
return await wallet.GetBalance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// todo transfer should be a transaction
|
||||||
public static async Task<bool> TransferAsync(
|
public static async Task<bool> TransferAsync(
|
||||||
this ICurrencyService cs,
|
this ICurrencyService cs,
|
||||||
ulong fromId,
|
ulong fromId,
|
||||||
|
@@ -43,17 +43,18 @@ public class DefaultWallet : IWallet
|
|||||||
if (changed == 0)
|
if (changed == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
await using var ctx2 = ctx.CreateLinqToDbContext();
|
await ctx
|
||||||
await ctx2
|
.GetTable<CurrencyTransaction>()
|
||||||
.InsertAsync(new CurrencyTransaction()
|
.InsertAsync(() => new()
|
||||||
{
|
{
|
||||||
Amount = -amount,
|
Amount = -amount,
|
||||||
Note = txData.Note,
|
Note = txData.Note,
|
||||||
UserId = UserId,
|
UserId = UserId,
|
||||||
Type = txData.Type,
|
Type = txData.Type,
|
||||||
Extra = txData.Extra,
|
Extra = txData.Extra,
|
||||||
OtherId = txData.OtherId
|
OtherId = txData.OtherId,
|
||||||
});
|
DateAdded = DateTime.UtcNow
|
||||||
|
});
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -88,17 +89,16 @@ public class DefaultWallet : IWallet
|
|||||||
await tran.CommitAsync();
|
await tran.CommitAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
var ct = new CurrencyTransaction()
|
await ctx.GetTable<CurrencyTransaction>()
|
||||||
{
|
.InsertAsync(() => new()
|
||||||
Amount = amount,
|
{
|
||||||
UserId = UserId,
|
Amount = amount,
|
||||||
Note = txData.Note,
|
UserId = UserId,
|
||||||
Type = txData.Type,
|
Note = txData.Note,
|
||||||
Extra = txData.Extra,
|
Type = txData.Type,
|
||||||
OtherId = txData.OtherId
|
Extra = txData.Extra,
|
||||||
};
|
OtherId = txData.OtherId,
|
||||||
|
DateAdded = DateTime.UtcNow
|
||||||
await using var ctx2 = ctx.CreateLinqToDbContext();
|
});
|
||||||
await ctx2.InsertAsync(ct);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user