Skip to content

Commit

Permalink
[Core] fix one-time login (#719)
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkRRb authored Dec 29, 2024
1 parent d00c8da commit 89c4c17
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Lagrange.OneBot/Core/Login/LoginService.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Text.Json;
using Lagrange.Core;
using Lagrange.Core.Common.Interface.Api;
using Lagrange.Core.Event.EventArg;
Expand Down Expand Up @@ -57,6 +58,9 @@ public async Task StartAsync(CancellationToken token)

if (!isSucceed) throw new Exception("All login failed!");

string keystoreJson = JsonSerializer.Serialize(_lagrange.UpdateKeystore());
File.WriteAllText(configuration["ConfigPath:Keystore"] ?? "keystore.json", keystoreJson);

_logger.LogInformation("Bot Uin: {}", _lagrange.BotUin);

await _web.StartAsync(token);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,14 @@ public static HostApplicationBuilder ConfigureLagrangeCore(this HostApplicationB
var configuration = services.GetRequiredService<IConfiguration>();
string path = configuration["ConfigPath:DeviceInfo"] ?? "device.json";

return File.Exists(path)
var device = File.Exists(path)
? JsonSerializer.Deserialize<BotDeviceInfo>(File.ReadAllText(path)) ?? BotDeviceInfo.GenerateInfo()
: BotDeviceInfo.GenerateInfo();

string deviceJson = JsonSerializer.Serialize(device);
File.WriteAllText(path, deviceJson);

return device;
})
.AddSingleton((services) => // Keystore
{
Expand Down

0 comments on commit 89c4c17

Please sign in to comment.