diff --git a/Lagrange.Core/BotContext.cs b/Lagrange.Core/BotContext.cs
index 6892a33a1..45ef3dfdb 100644
--- a/Lagrange.Core/BotContext.cs
+++ b/Lagrange.Core/BotContext.cs
@@ -24,13 +24,13 @@ public class BotContext : IDisposable
private readonly BotKeystore _keystore;
- internal BotContext(BotConfig config, BotDeviceInfo deviceInfo, BotKeystore keystore)
+ internal BotContext(BotConfig config, BotDeviceInfo deviceInfo, BotKeystore keystore, BotAppInfo appInfo)
{
Invoker = new EventInvoker(this);
Scheduler = new Utility.TaskScheduler();
Config = config;
- AppInfo = BotAppInfo.ProtocolToAppInfo[config.Protocol];
+ AppInfo = appInfo;
_deviceInfo = deviceInfo;
_keystore = keystore;
diff --git a/Lagrange.Core/Common/BotAppInfo.cs b/Lagrange.Core/Common/BotAppInfo.cs
index 134f3fae9..e2b2357f2 100644
--- a/Lagrange.Core/Common/BotAppInfo.cs
+++ b/Lagrange.Core/Common/BotAppInfo.cs
@@ -4,38 +4,38 @@ namespace Lagrange.Core.Common;
public class BotAppInfo
{
- public string Os { get; private set; }
+ public string Os { get; set; }
- public string VendorOs { get; private set; }
+ public string VendorOs { get; set; }
- public string Kernel { get; private set; }
+ public string Kernel { get; set; }
- public string CurrentVersion { get; private set; }
+ public string CurrentVersion { get; set; }
- public int MiscBitmap { get; private set; }
+ public int MiscBitmap { get; set; }
- public string PtVersion { get; private set; }
+ public string PtVersion { get; set; }
- public int SsoVersion { get; private set; }
+ public int SsoVersion { get; set; }
- public string PackageName { get; private set; }
+ public string PackageName { get; set; }
- public string WtLoginSdk { get; private set; }
+ public string WtLoginSdk { get; set; }
- public int AppId { get; private set; }
+ public int AppId { get; set; }
/// Or known as pubId in tencent log
- public int SubAppId { get; private set; }
+ public int SubAppId { get; set; }
- public int AppIdQrCode { get; private set; }
+ public int AppIdQrCode { get; set; }
- public ushort AppClientVersion { get; private set; }
+ public ushort AppClientVersion { get; set; }
- public uint MainSigMap { get; private set; }
+ public uint MainSigMap { get; set; }
- public ushort SubSigMap { get; private set; }
+ public ushort SubSigMap { get; set; }
- public ushort NTLoginType { get; private set; }
+ public ushort NTLoginType { get; set; }
private static readonly BotAppInfo Linux = new()
{
diff --git a/Lagrange.Core/Common/Interface/BotFactory.cs b/Lagrange.Core/Common/Interface/BotFactory.cs
index 4eb436e53..fe1a92b0e 100644
--- a/Lagrange.Core/Common/Interface/BotFactory.cs
+++ b/Lagrange.Core/Common/Interface/BotFactory.cs
@@ -10,7 +10,18 @@ public static class BotFactory
/// Existing Keystore from deserialization
/// Created BotContext Instance
public static BotContext Create(BotConfig config, BotDeviceInfo deviceInfo, BotKeystore keystore) =>
- new(config, deviceInfo, keystore);
+ new(config, deviceInfo, keystore, BotAppInfo.ProtocolToAppInfo[config.Protocol]);
+
+ ///
+ /// Create new Bot from existing and with custom
+ ///
+ /// The config for Bot
+ /// Existing DeviceInfo from deserialization
+ /// Existing Keystore from deserialization
+ /// Custom BotAppInfo, including client version, app ID, etc
+ ///
+ public static BotContext Create(BotConfig config, BotDeviceInfo deviceInfo, BotKeystore keystore, BotAppInfo appInfo) =>
+ new(config, deviceInfo, keystore, appInfo);
///
/// Create new Bot from Password and uin
@@ -21,5 +32,17 @@ public static BotContext Create(BotConfig config, BotDeviceInfo deviceInfo, BotK
/// Created device, should be serialized to files for next use
/// Created BotContext Instance
public static BotContext Create(BotConfig config, uint uin, string password, out BotDeviceInfo device) =>
- new(config, device = BotDeviceInfo.GenerateInfo(), new BotKeystore(uin, password));
+ new(config, device = BotDeviceInfo.GenerateInfo(), new BotKeystore(uin, password), BotAppInfo.ProtocolToAppInfo[config.Protocol]);
+
+ ///
+ /// Create new Bot from Password and uin with custom
+ ///
+ /// The config for Bot
+ /// Uin, if QrCode login is used, ensure the account that scans QrCode is consistent with this Uin
+ /// The password of account, for Password Login
+ /// Custom BotAppInfo, including client version, app ID, etc
+ /// Created device, should be serialized to files for next use
+ ///
+ public static BotContext Create(BotConfig config, uint uin, string password, BotAppInfo appInfo, out BotDeviceInfo device) =>
+ new(config, device = BotDeviceInfo.GenerateInfo(), new BotKeystore(uin, password), appInfo);
}
\ No newline at end of file
diff --git a/Lagrange.OneBot/LagrangeAppBuilder.cs b/Lagrange.OneBot/LagrangeAppBuilder.cs
index 5f8ac37ea..ed357287f 100644
--- a/Lagrange.OneBot/LagrangeAppBuilder.cs
+++ b/Lagrange.OneBot/LagrangeAppBuilder.cs
@@ -41,6 +41,7 @@ public LagrangeAppBuilder ConfigureBots()
{
string keystorePath = Configuration["ConfigPath:Keystore"] ?? "keystore.json";
string deviceInfoPath = Configuration["ConfigPath:DeviceInfo"] ?? "device.json";
+ string appInfoPath = Configuration["ConfigPath:AppInfo"] ?? "appinfo.json";
bool isSuccess = Enum.TryParse(Configuration["Account:Protocol"], out var protocol);
var config = new BotConfig
@@ -86,7 +87,24 @@ public LagrangeAppBuilder ConfigureBots()
deviceInfo = JsonSerializer.Deserialize(File.ReadAllText(deviceInfoPath)) ?? BotDeviceInfo.GenerateInfo();
}
- Services.AddSingleton(BotFactory.Create(config, deviceInfo, keystore));
+ BotAppInfo appInfo;
+ if (!File.Exists(appInfoPath))
+ {
+ appInfo = BotAppInfo.ProtocolToAppInfo[config.Protocol];
+ string json = JsonSerializer.Serialize(appInfo);
+ string? directoryPath = Path.GetDirectoryName(appInfoPath);
+ if (!string.IsNullOrEmpty(directoryPath))
+ {
+ Directory.CreateDirectory(directoryPath);
+ }
+ File.WriteAllText(appInfoPath, json);
+ }
+ else
+ {
+ appInfo = JsonSerializer.Deserialize(File.ReadAllText(appInfoPath)) ?? BotAppInfo.ProtocolToAppInfo[config.Protocol];
+ }
+
+ Services.AddSingleton(BotFactory.Create(config, deviceInfo, keystore, appInfo));
return this;
}