// Populate the preferences dictionary when starting the bot public void Populate() { IMongoCollection <BsonDocument> collection = _dbService.GetCollection("ServerSettings"); var results = collection.Find("{}").ToList(); foreach (var obj in results) { ServerPreference preference = BsonSerializer.Deserialize <ServerPreference>(obj); _preferences.Add(preference.guild, preference); } }
public void CheckPreferenceStatus(SocketGuild guild) { IMongoCollection <BsonDocument> collection = _dbService.GetCollection("ServerSettings"); // Search the database for preferences var filter = new BsonDocument("guild", Convert.ToInt64(guild.Id)); var results = collection.Find(filter).ToList(); // Check if server already has a config if (results.Count == 0) { // Generate new config ServerPreference newPreference = new ServerPreference(); BsonDocument preferenceBson = new BsonDocument(); preferenceBson = newPreference.ToBsonDocument(); collection.InsertOne(preferenceBson); _preferences.Add(Convert.ToInt64(guild.Id), newPreference); } }