using System.Text.Json;
using Lagrange.Core.Common;
using RoBot.Core.ConstValue;
namespace RoBot.Start.Keystore
{
///
/// 账号登录信息
///
public class KeystoreConfig
{
///
/// 获取账号登录信息
///
///
public static async Task GetBotKeystore()
{
KeystoreInfo result = new()
{
ReLogin = false
};
var botKeystore = File.Exists(Consts.KeystoreConfig)
? JsonSerializer.Deserialize(await File.ReadAllTextAsync(Consts.KeystoreConfig)) ?? new()
: new();
result.BotKeystore = botKeystore;
if (botKeystore.Session.TempPassword?.Length > 0)
{
result.ReLogin = true;
}
return result;
}
///
/// 保存登录信息
///
///
///
public static async Task SaveBotKeystore(BotKeystore botKeystore)
{
string keystoreJson = JsonSerializer.Serialize(botKeystore);
await File.WriteAllTextAsync(Consts.KeystoreConfig, keystoreJson);
}
}
public class KeystoreInfo
{
///
/// BotKeystore
///
public BotKeystore BotKeystore { get; set; }
///
/// 是否需要重新登录
///
public bool ReLogin { get; set; }
}
}