/// <summary> /// Loads the <see cref="CommandDocument"/> associated with the specified command, or creates one if it doesn't exist. /// </summary> /// <param name="channelId">The channel Id the command belongs to.</param> /// <param name="isWhisperCommand">Whether this is a whisper command.</param> /// <param name="command">The command to lookup.</param> /// <returns>A <see cref="CommandDocument"/>.</returns> public async Task <CommandDocument> LoadCommandAsync(string channelId, bool isWhisperCommand, string command) { IMongoCollection <CommandDocument> commands = DatabaseClient.Instance.MongoDatabase.GetCollection <CommandDocument>(CommandDocument.CollectionName); FilterDefinition <CommandDocument> filter = Builders <CommandDocument> .Filter.Where(c => c.ChannelId == channelId && c.IsWhisperCommand == isWhisperCommand && c.Command == command); if (await commands.CountDocumentsAsync(filter).ConfigureAwait(false) == 0) { await commands.InsertOneAsync(new CommandDocument { ChannelId = channelId, Command = command, IsWhisperCommand = isWhisperCommand, Cooldowns = new CommandCooldownDocument(), UserLevel = this._defaultCommandPermissions[command] }).ConfigureAwait(false); } using IAsyncCursor <CommandDocument> cursor = await commands.FindAsync(filter).ConfigureAwait(false); CommandDocument commandDocument = await cursor.SingleAsync().ConfigureAwait(false); commandDocument.Cooldowns.Id = commandDocument.Id; return(commandDocument); }