Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core] fix one-time login #719

Merged
merged 3 commits into from
Dec 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading