public DBGuild(ulong guildId) { this.ID = guildId; try { if (GenericBot.LoadedGuildDbs.ContainsKey(this.ID)) { this.Users = GenericBot.LoadedGuildDbs[this.ID].Users; this.Quotes = GenericBot.LoadedGuildDbs[this.ID].Quotes; } else { var col = GenericBot.GlobalDatabase.GetCollection <DBGuild>("userDatabase"); DBGuild tempdb; col.EnsureIndex(c => c.ID, true); if (col.Exists(c => c.ID.Equals(guildId))) { tempdb = col.FindOne(c => c.ID.Equals(guildId)); } else { tempdb = new DBGuild() { ID = guildId, Users = new List <DBUser>() }; } this.Users = tempdb.Users; this.Quotes = tempdb.Quotes; } } catch (Exception ex) { GenericBot.Logger.LogErrorMessage($"Load DB for {guildId} Failed: {ex.Message}\n{ex.StackTrace}"); } }
public DBGuild(ulong guildId) { this.ID = guildId; try { if (GenericBot.LoadedGuilds.ContainsKey(this.ID)) { this.Users = GenericBot.LoadedGuilds[this.ID].Users; this.Quotes = GenericBot.LoadedGuilds[this.ID].Quotes; } else { var col = GenericBot.GlobalDatabase.GetCollection <DBGuild>("userDatabase"); DBGuild tempdb; col.EnsureIndex(c => c.ID, true); if (col.Exists(c => c.ID.Equals(guildId))) { Console.WriteLine("DB loaded from LITEDB"); tempdb = col.FindOne(c => c.ID.Equals(guildId)); } else if (File.Exists($"files/guildDbs/{ID}.json")) { if (!File.ReadAllText($"files/guildDbs/{ID}.json").StartsWith("{")) { Console.WriteLine("DB loaded from ENCRYPTED JSON"); tempdb = JsonConvert.DeserializeObject <DBGuild>(AES.DecryptText(File.ReadAllText($"files/guildDbs/{ID}.json"), GenericBot.DBPassword)); } else { Console.WriteLine("DB loaded from RAW JSON"); tempdb = JsonConvert.DeserializeObject <DBGuild>(File.ReadAllText($"files/guildDbs/{ID}.json")); } } else { tempdb = new DBGuild() { ID = guildId, Users = new List <DBUser>() }; } this.Users = tempdb.Users; this.Quotes = tempdb.Quotes; } } catch (Exception ex) { GenericBot.Logger.LogErrorMessage($"Load DB for {guildId} Failed: {ex.Message}\n{ex.StackTrace}"); } }