Signed-off-by: Eicy <im@crash.work>
This commit is contained in:
2024-12-17 00:23:59 +08:00
commit 88abc095c2
12 changed files with 1061 additions and 0 deletions

16
Utility/Console.cs Normal file
View File

@@ -0,0 +1,16 @@
using Lagrange.Core.Event.EventArg;
namespace Shrink.Utility;
public static class Console
{
public static void ChangeColorByTitle(this LogLevel level) => System.Console.ForegroundColor = level switch
{
LogLevel.Debug => ConsoleColor.White,
LogLevel.Verbose => ConsoleColor.DarkGray,
LogLevel.Information => ConsoleColor.Blue,
LogLevel.Warning => ConsoleColor.Yellow,
LogLevel.Fatal => ConsoleColor.Red,
_ => System.Console.ForegroundColor
};
}

43
Utility/Data.cs.disable Normal file
View File

@@ -0,0 +1,43 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using Lagrange.Core.Common;
namespace Shrink.Utility;
public static class Data
{
public static void SaveKeystore(BotKeystore keystore) =>
File.WriteAllText("Keystore.json", JsonSerializer.Serialize(keystore));
public static BotDeviceInfo GetDeviceInfo()
{
if (File.Exists("DeviceInfo.json"))
{
var info = JsonSerializer.Deserialize<BotDeviceInfo>(File.ReadAllText("DeviceInfo.json"));
if (info != null) return info;
info = BotDeviceInfo.GenerateInfo();
File.WriteAllText("DeviceInfo.json", JsonSerializer.Serialize(info));
return info;
}
var deviceInfo = BotDeviceInfo.GenerateInfo();
File.WriteAllText("DeviceInfo.json", JsonSerializer.Serialize(deviceInfo));
return deviceInfo;
}
public static BotKeystore? LoadKeystore()
{
try
{
var text = File.ReadAllText("Keystore.json");
return JsonSerializer.Deserialize<BotKeystore>(text, new JsonSerializerOptions()
{
ReferenceHandler = ReferenceHandler.Preserve
});
}
catch
{
return null;
}
}
}