mirror of
https://github.com/barelyprofessional/KfChatDotNet.git
synced 2026-05-02 04:22:04 -04:00
Removed Newtonsoft
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using System.Text.RegularExpressions;
|
using System.Text.Json;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using KfChatDotNetBot.Extensions;
|
using KfChatDotNetBot.Extensions;
|
||||||
using KfChatDotNetBot.Models;
|
using KfChatDotNetBot.Models;
|
||||||
using KfChatDotNetBot.Models.DbModels;
|
using KfChatDotNetBot.Models.DbModels;
|
||||||
@@ -6,7 +7,6 @@ using KfChatDotNetBot.Services;
|
|||||||
using KfChatDotNetBot.Settings;
|
using KfChatDotNetBot.Settings;
|
||||||
using KfChatDotNetWsClient.Models.Events;
|
using KfChatDotNetWsClient.Models.Events;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using NLog;
|
|
||||||
using RandN.Compat;
|
using RandN.Compat;
|
||||||
using RandN;
|
using RandN;
|
||||||
|
|
||||||
@@ -106,7 +106,7 @@ public class BlackjackCommand : ICommand
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var existingGameState = existingGame.GameMeta.JsonDeserialize<BlackjackGameMetaModel>();
|
var existingGameState = JsonSerializer.Deserialize<BlackjackGameMetaModel>(existingGame.GameMeta);
|
||||||
|
|
||||||
if (existingGameState == null)
|
if (existingGameState == null)
|
||||||
{
|
{
|
||||||
@@ -177,7 +177,7 @@ public class BlackjackCommand : ICommand
|
|||||||
|
|
||||||
newGameState.WagerId = createdWager.Id;
|
newGameState.WagerId = createdWager.Id;
|
||||||
db.Attach(createdWager);
|
db.Attach(createdWager);
|
||||||
createdWager.GameMeta = newGameState.JsonSerialize();
|
createdWager.GameMeta = JsonSerializer.Serialize(newGameState);
|
||||||
await db.SaveChangesAsync(ctx);
|
await db.SaveChangesAsync(ctx);
|
||||||
|
|
||||||
// Check for immediate blackjacks
|
// Check for immediate blackjacks
|
||||||
@@ -240,7 +240,7 @@ public class BlackjackCommand : ICommand
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var currentGameState = activeWager.GameMeta.JsonDeserialize<BlackjackGameMetaModel>();
|
var currentGameState = JsonSerializer.Deserialize<BlackjackGameMetaModel>(activeWager.GameMeta);
|
||||||
if (currentGameState == null)
|
if (currentGameState == null)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -321,7 +321,7 @@ public class BlackjackCommand : ICommand
|
|||||||
// Continue game
|
// Continue game
|
||||||
await using var db = new ApplicationDbContext();
|
await using var db = new ApplicationDbContext();
|
||||||
db.Attach(wager);
|
db.Attach(wager);
|
||||||
wager.GameMeta = gameState.JsonSerialize();
|
wager.GameMeta = JsonSerializer.Serialize(gameState);
|
||||||
await db.SaveChangesAsync(ctx);
|
await db.SaveChangesAsync(ctx);
|
||||||
|
|
||||||
await botInstance.SendChatMessageAsync(
|
await botInstance.SendChatMessageAsync(
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using KfChatDotNetBot.Models.DbModels;
|
using KfChatDotNetBot.Models.DbModels;
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
namespace KfChatDotNetBot.Extensions;
|
namespace KfChatDotNetBot.Extensions;
|
||||||
|
|
||||||
@@ -138,30 +137,4 @@ public static class Extensions
|
|||||||
{
|
{
|
||||||
return $"@{user.KfUsername}";
|
return $"@{user.KfUsername}";
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Deserialize a JSON string to the specified type using Newtonsoft.Json
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T">Type to deserialize to</typeparam>
|
|
||||||
/// <param name="jsonString">JSON string to deserialize</param>
|
|
||||||
/// <returns>Deserialized object or null if string is null/empty</returns>
|
|
||||||
public static T? JsonDeserialize<T>(this string? jsonString) where T : class
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(jsonString))
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return JsonConvert.DeserializeObject<T>(jsonString);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Serialize an object to JSON string using Newtonsoft.Json
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="obj">Object to serialize</param>
|
|
||||||
/// <returns>JSON string representation</returns>
|
|
||||||
public static string JsonSerialize(this object obj)
|
|
||||||
{
|
|
||||||
return JsonConvert.SerializeObject(obj, Formatting.Indented);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user