|
| 1 | +using Konata.Core; |
| 2 | +using Konata.Core.Common; |
| 3 | +using Konata.Core.Interfaces; |
| 4 | +using Newtonsoft.Json; |
| 5 | +using Path = Andreal.Core.Path; |
| 6 | + |
| 7 | +namespace Andreal; |
| 8 | + |
| 9 | +public class ConfigJson |
| 10 | +{ |
| 11 | + [JsonProperty("keystore")] public BotKeyStore? KeyStore { get; set; } |
| 12 | + [JsonProperty("device")] public BotDevice? Device { get; set; } |
| 13 | +} |
| 14 | + |
| 15 | +public class AccountInfo |
| 16 | +{ |
| 17 | + [JsonProperty("uid")] public uint Account { get; set; } |
| 18 | + [JsonProperty("password")] public string Password { get; set; } = ""; |
| 19 | + |
| 20 | + internal Bot GenerateBotInstance() |
| 21 | + { |
| 22 | + var pth = Path.BotConfig(Account); |
| 23 | + if (File.Exists(pth)) |
| 24 | + { |
| 25 | + var cfg = JsonConvert.DeserializeObject<ConfigJson>(File.ReadAllText(pth))!; |
| 26 | + return BotFather.Create(BotConfig.Default(), cfg.Device, cfg.KeyStore); |
| 27 | + } |
| 28 | + else |
| 29 | + { |
| 30 | + var bot = BotFather.Create(Account.ToString(), Password, out _, out var device, out var keystore); |
| 31 | + var cfg = new ConfigJson { Device = device, KeyStore = keystore }; |
| 32 | + File.WriteAllText(pth, JsonConvert.SerializeObject(cfg)); |
| 33 | + return bot; |
| 34 | + } |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +public class ApiConfig |
| 39 | +{ |
| 40 | + [JsonProperty("url")] public string Url { get; set; } = ""; |
| 41 | + [JsonProperty("token")] public string Token { get; set; } = ""; |
| 42 | +} |
| 43 | + |
| 44 | +public class AndrealSettings |
| 45 | +{ |
| 46 | + [JsonProperty("friend_add")] public bool FriendAdd { get; set; } |
| 47 | + [JsonProperty("group_add")] public bool GroupAdd { get; set; } |
| 48 | + |
| 49 | + [JsonProperty("group_inviter_whitelist")] |
| 50 | + public List<uint> GroupInviterWhitelist { get; set; } = new(); |
| 51 | +} |
| 52 | + |
| 53 | +public class AndrealConfig |
| 54 | +{ |
| 55 | + [JsonProperty("master")] public uint Master { get; set; } |
| 56 | + [JsonProperty("accounts")] public List<AccountInfo> Accounts { get; set; } = new(); |
| 57 | + [JsonProperty("api")] public Dictionary<string, ApiConfig> Api { get; set; } = new(); |
| 58 | + [JsonProperty("approve_settings")] public AndrealSettings Settings { get; set; } = new(); |
| 59 | + |
| 60 | + [JsonProperty("enable_handle_message")] |
| 61 | + public bool EnableHandleMessage { get; set; } = true; |
| 62 | +} |
0 commit comments